Fix Spotify API authorization #66
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #65.
The
https://accounts.spotify.com/authorizeendpoint no longer acceptstokenasresponse_typeso we must instead usecode. The script previously used thetokenresponse type which the Spotify API redirected tohttp://127.0.0.1:3000/redirect#error=unsupported_response_typeOAuth authorization methods/flows
From: https://developer.spotify.com/documentation/web-api/concepts/authorization
Since we need access to user resources and don't want the client secret to be published we have no choice but to use Authorization code with PKCE.
This PR implements this flow by generating a new PKCE
code_verifier-code_challengepair and including the challenge in the oauth request. If the user accepts the request then we get a code that we use together with thecode_verifierto request an access token.This PR does not save or log the
code_verifierwhich would be needed to be able to skip the oauth request when re-running the python script (we would also need to accept thecode_verifierand authorization code as CLI arguments if we wanted to skip the oauth request).