Skip to content

Commit

Permalink
Fix backwards compatibility for aud
Browse files Browse the repository at this point in the history
  • Loading branch information
Sephster committed Nov 24, 2020
1 parent 9a58173 commit 7efa91c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 13 additions & 8 deletions src/AuthorizationValidators/BearerTokenValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,6 @@ public function validateAuthorization(ServerRequestInterface $request)
// Attempt to parse and validate the JWT
$token = $this->jwtConfiguration->parser()->parse($jwt);

/*$this->jwtConfiguration->setValidationConstraints(
new SignedWith(
new Sha256(),
LocalFileReference::file($this->publicKey->getKeyPath())
)
);*/

$constraints = $this->jwtConfiguration->validationConstraints();

try {
Expand All @@ -123,8 +116,20 @@ public function validateAuthorization(ServerRequestInterface $request)
// Return the request with additional attributes
return $request
->withAttribute('oauth_access_token_id', $claims->get('jti'))
->withAttribute('oauth_client_id', $claims->get('aud'))
->withAttribute('oauth_client_id', $this->convertSingleRecordAudToString($claims->get('aud')))
->withAttribute('oauth_user_id', $claims->get('sub'))
->withAttribute('oauth_scopes', $claims->get('scopes'));
}

/**
* Convert single record arrays into strings to ensure backwards compatibility between v4 and v3.x of lcobucci/jwt
*
* @param $aud
*
* @return array|string
*/
private function convertSingleRecordAudToString($aud)
{
return count($aud) === 1 ? $aud[0] : $aud;
}
}
2 changes: 1 addition & 1 deletion tests/ResponseTypes/BearerResponseTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function testDetermineAccessTokenInHeaderValidToken()
$request = $authorizationValidator->validateAuthorization($request);

$this->assertEquals('abcdef', $request->getAttribute('oauth_access_token_id'));
$this->assertContains('clientName', $request->getAttribute('oauth_client_id'));
$this->assertEquals('clientName', $request->getAttribute('oauth_client_id'));
$this->assertEquals('123', $request->getAttribute('oauth_user_id'));
$this->assertEquals([], $request->getAttribute('oauth_scopes'));
}
Expand Down

0 comments on commit 7efa91c

Please sign in to comment.