Logged In Auth Flow
Details of the authentication flow.
Use Case
The Logged In Auth Flow should be used when the user is also logged in to your app. Access token will be stored in your DB along side a field of your choice linking the user to the token. From then on you will be able to retrieve the access token from your DB based on the logged in user and not have to make them "Connect to Soundcloud" every time they access an area of your app that needs to call the Soundcloud API.
Authentication Flow
Redirect User to Authorization URL
To begin the auth flow we must request permission from the users to call the Soundcloud API on their behalf.
Your application should construct the authorization URL with the necessary parameters and then redirect the user's browser to this URL. This step must be performed on the front-end of your application, as it involves user interaction.
If you are unsure on any of the keys above please see the Prerequisites section.
Grant Access: User Authorization
A pop-up window will be opened allowing the user to log in to SoundCloud and approve your app's authorization request. If the user is already signed into SoundCloud, they will be able to authorize your request in one click.
Obtain Access Token
If the user approves your authorization request, they will be sent to the redirect_uri
you specified when registering your app. The redirectUri
should have a ?code=
param attached. You will need to process this however you see best and pass it to your back end where it will be used to obtain an access token.
Here you should also securely pass a userId
or reference to the logged in user so we can later get the stored token based on the logged in user.
Obtaining the access code should happen back end as their are keys invovled that should not be exposed to the client. Create your own endpoint to handle obtaining acess code. The endpoint should request a token and upon success store it in your DB.
Use Token
The returned object has an access_token
property. To send requests to the API, retrieve the access_token
from your DB and pass it to the Authorization
header.
Now instead of sending the user through the full authorization flow on each API interaction, use the token stored your database to authorize requests.