Skip to content

Commit 7e40a8e

Browse files
committed
Fix indefinite hang on invalid PKCE client_id
1 parent 5a8b55f commit 7e40a8e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

spotipy/oauth2.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,27 @@ def get_access_token(self, code=None, check_cache=True):
875875
if self.code_verifier is None or self.code_challenge is None:
876876
self.get_pkce_handshake_parameters()
877877

878+
preflight_payload = {
879+
"client_id": self.client_id,
880+
"grant_type": "authorization_code",
881+
"code": "invalid_code",
882+
"redirect_uri": self.redirect_uri,
883+
"code_verifier": self.code_verifier,
884+
}
885+
886+
preflight_resp = self._session.post(
887+
self.OAUTH_TOKEN_URL,
888+
data=preflight_payload,
889+
headers={"Content-Type": "application/x-www-form-urlencoded"},
890+
timeout=self.requests_timeout,
891+
proxies=self.proxies
892+
)
893+
894+
if preflight_resp.status_code == 400:
895+
body = preflight_resp.json()
896+
if body.get("error") == "invalid_client":
897+
raise SpotifyOauthError("Invalid client_id")
898+
878899
payload = {
879900
"client_id": self.client_id,
880901
"grant_type": "authorization_code",

0 commit comments

Comments
 (0)