Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: throw audience mismatch when audience doesn't exist #370

Merged
merged 5 commits into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/AccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ private function verifyEs256($token, array $certs, $audience = null, $issuer = n
$jwt = $this->callSimpleJwtDecode([$token, $jwkset, 'ES256']);
$payload = $jwt->getClaims();

if (isset($payload['aud'])) {
if ($audience && $payload['aud'] != $audience) {
if ($audience) {
if (!isset($payload['aud']) || $payload['aud'] != $audience) {
throw new UnexpectedValueException('Audience does not match');
}
}
Expand Down Expand Up @@ -266,8 +266,8 @@ private function verifyRs256($token, array $certs, $audience = null, $issuer = n
['RS256']
]);

if (property_exists($payload, 'aud')) {
if ($audience && $payload->aud != $audience) {
if ($audience) {
if (!property_exists($payload, 'aud') || $payload->aud != $audience) {
throw new UnexpectedValueException('Audience does not match');
}
}
Expand Down
6 changes: 6 additions & 0 deletions tests/AccessTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Psr\Http\Message\RequestInterface;
use RuntimeException;
use SimpleJWT\JWT as SimpleJWT;
use UnexpectedValueException;

/**
* @group access-token
Expand Down Expand Up @@ -220,6 +221,11 @@ public function verifyCalls()
null,
AccessToken::IAP_CERT_URL,
'baz'
], [
$this->payload,
null,
'foo',
new UnexpectedValueException('Audience does not match'),
]
];
}
Expand Down