Skip to content

Commit 924ed04

Browse files
Merge branch 'master' into psr-event-dispatcher
2 parents 2a5f995 + 6fb1cb9 commit 924ed04

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

src/AuthorizationValidators/BearerTokenValidator.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@
1212
use DateTimeZone;
1313
use Lcobucci\Clock\SystemClock;
1414
use Lcobucci\JWT\Configuration;
15-
use Lcobucci\JWT\Encoding\CannotDecodeContent;
1615
use Lcobucci\JWT\Signer\Key\InMemory;
1716
use Lcobucci\JWT\Signer\Key\LocalFileReference;
1817
use Lcobucci\JWT\Signer\Rsa\Sha256;
19-
use Lcobucci\JWT\Token\InvalidTokenStructure;
20-
use Lcobucci\JWT\Token\UnsupportedHeaderFound;
2118
use Lcobucci\JWT\Validation\Constraint\SignedWith;
2219
use Lcobucci\JWT\Validation\Constraint\ValidAt;
2320
use Lcobucci\JWT\Validation\RequiredConstraintsViolated;
@@ -95,18 +92,18 @@ public function validateAuthorization(ServerRequestInterface $request)
9592
$jwt = \trim((string) \preg_replace('/^(?:\s+)?Bearer\s/', '', $header[0]));
9693

9794
try {
98-
// Attempt to parse and validate the JWT
95+
// Attempt to parse the JWT
9996
$token = $this->jwtConfiguration->parser()->parse($jwt);
97+
} catch (\Lcobucci\JWT\Exception $exception) {
98+
throw OAuthServerException::accessDenied($exception->getMessage(), null, $exception);
99+
}
100100

101+
try {
102+
// Attempt to validate the JWT
101103
$constraints = $this->jwtConfiguration->validationConstraints();
102-
103-
try {
104-
$this->jwtConfiguration->validator()->assert($token, ...$constraints);
105-
} catch (RequiredConstraintsViolated $exception) {
106-
throw OAuthServerException::accessDenied('Access token could not be verified');
107-
}
108-
} catch (CannotDecodeContent | InvalidTokenStructure | UnsupportedHeaderFound $exception) {
109-
throw OAuthServerException::accessDenied($exception->getMessage(), null, $exception);
104+
$this->jwtConfiguration->validator()->assert($token, ...$constraints);
105+
} catch (RequiredConstraintsViolated $exception) {
106+
throw OAuthServerException::accessDenied('Access token could not be verified');
110107
}
111108

112109
$claims = $token->claims();

tests/ResponseTypes/BearerResponseTypeTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public function testDetermineAccessTokenInHeaderInvalidJWT()
166166
$accessToken = new AccessTokenEntity();
167167
$accessToken->setIdentifier('abcdef');
168168
$accessToken->setUserIdentifier(123);
169-
$accessToken->setExpiryDateTime((new DateTimeImmutable())->add(new DateInterval('PT1H')));
169+
$accessToken->setExpiryDateTime((new DateTimeImmutable())->sub(new DateInterval('PT1H')));
170170
$accessToken->setClient($client);
171171
$accessToken->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
172172

@@ -184,7 +184,7 @@ public function testDetermineAccessTokenInHeaderInvalidJWT()
184184
$authorizationValidator = new BearerTokenValidator($accessTokenRepositoryMock);
185185
$authorizationValidator->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key'));
186186

187-
$request = (new ServerRequest())->withHeader('authorization', \sprintf('Bearer %s', $json->access_token . 'foo'));
187+
$request = (new ServerRequest())->withHeader('authorization', \sprintf('Bearer %s', $json->access_token));
188188

189189
try {
190190
$authorizationValidator->validateAuthorization($request);

0 commit comments

Comments
 (0)