Obtain the Authorization Code Access Token

Get the authorization code access token required to access the Spotify API endpoints.

As we discussed earlier, for all the endpoints where we access a user's resources, we need to use either the authorization code, the authorization code with PKCE, or the implicit grant flow to get the access token. In this lesson, we’ll learn how to get the access token using the authorization code flow.

Authorization code

The workflow needed to get the authorization code access token is as follows:

  • First, we need to redirect the user to the Spotify API server by making a call to the base URI https://accounts.spotify.com/authorize with some query parameters. The user is asked to log in to Spotify using a dialog box.
  • After the user has logged in, a dialog box will pop up asking the user to accept or deny our grant request.
  • Once the user accepts our request, we'll receive a code.
  • Then we’ll make an API call using the base URI https://accounts.spotify.com/api/token and some query parameters.
  • Finally, we’ll receive an access token that we can use to access the user-specific endpoints.
  • Get hands-on with 1200+ tech skills courses.