Add code parameter to get_access_token of SpotifyPKCE (#556)

* Add code parameter to oauth2.SpotifyPKCE.get_access_token

* Fix the PKCE integration test cache
This commit is contained in:
IdmFoundInHim 2020-08-24 14:57:05 -04:00 committed by GitHub
parent 004df7b2df
commit 3d48d77615
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 6 deletions

View File

@ -803,12 +803,17 @@ class SpotifyPKCE(SpotifyAuthBase):
self.code_verifier = self._get_code_verifier()
self.code_challenge = self._get_code_challenge()
def get_access_token(self, check_cache=True):
""" Gets the access token for the app given the code
def get_access_token(self, code=None, check_cache=True):
""" Gets the access token for the app
If the code is not given and no cached token is used, an
authentication window will be shown to the user to get a new
code.
Parameters:
- check_cache - check for locally stored token before request
a new token if True
- code - the response code from authentication
- check_cache - if true, checks for locally stored token
before requesting a new token if True
"""
if check_cache:
@ -826,7 +831,7 @@ class SpotifyPKCE(SpotifyAuthBase):
payload = {
"client_id": self.client_id,
"grant_type": "authorization_code",
"code": self.get_authorization_code(),
"code": code or self.get_authorization_code(),
"redirect_uri": self.redirect_uri,
"code_verifier": self.code_verifier
}

View File

@ -435,7 +435,7 @@ class SpotifyPKCETests(unittest.TestCase):
'user-follow-read '
'user-follow-modify '
)
auth_manager = SpotifyPKCE(scope=scope, cache_path=".cache-implicittest")
auth_manager = SpotifyPKCE(scope=scope, cache_path=".cache-pkcetest")
cls.spotify = Spotify(auth_manager=auth_manager)
def test_user_follows_and_unfollows_artist(self):