Skip to content

Commit

Permalink
Move pkce check so it happens prior to validation of code challenge
Browse files Browse the repository at this point in the history
  • Loading branch information
Sephster committed Feb 15, 2023
1 parent 1480564 commit 0d523dd
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Grant/AuthCodeGrant.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,6 @@ public function respondToAccessTokenRequest(

$codeVerifier = $this->getRequestParameter('code_verifier', $request, null);

if (!empty($authCodePayload->code_challenge)) {
$this->validateCodeChallenge($authCodePayload, $codeVerifier);
}

// If a code challenge isn't present but a code verifier is, reject the request to block PKCE downgrade attack
if (empty($authCodePayload->code_challenge) && $codeVerifier !== null) {
throw OAuthServerException::invalidRequest(
Expand All @@ -141,6 +137,10 @@ public function respondToAccessTokenRequest(
);
}

if (!empty($authCodePayload->code_challenge)) {
$this->validateCodeChallenge($authCodePayload, $codeVerifier);
}

// Issue and persist new access token
$accessToken = $this->issueAccessToken($accessTokenTTL, $client, $authCodePayload->user_id, $scopes);
$this->getEmitter()->emit(new RequestAccessTokenEvent(RequestEvent::ACCESS_TOKEN_ISSUED, $request, $accessToken));
Expand Down

0 comments on commit 0d523dd

Please sign in to comment.