Skip to content

Commit

Permalink
v3.1.2 -- Use latest auth0-php library but also ensure correct algo i…
Browse files Browse the repository at this point in the history
…s used when decoding.
  • Loading branch information
gdbrown committed Jan 24, 2024
1 parent c1d270e commit 810a8be
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG-3.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
This changelog references the relevant changes done in 3.x versions.


## v3.1.2
* Use latest auth0-php library but also ensure correct algo is used when decoding.


## v3.1.1
* Use latest auth0-php library.

Expand Down
17 changes: 17 additions & 0 deletions src/Security/Auth0JwtDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Auth0\SDK\Auth0;
use Auth0\SDK\Configuration\SdkConfiguration;
use Auth0\SDK\Exception\InvalidTokenException;
use Auth0\SDK\Token;
use Gdbots\Schemas\Pbjx\Enum\Code;
use Psr\Cache\CacheItemPoolInterface;

Expand Down Expand Up @@ -36,6 +37,22 @@ public function __construct(CacheItemPoolInterface $cache, string $audience, str

public function decode(string $jwt): array
{
$header = json_decode(base64_decode(explode('.', $jwt, 2)[0]), true) ?: [];
$alg = $header['alg'] ?? 'unknown';

switch ($alg) {
case Token::ALGO_RS256:
$this->auth0->configuration()->setTokenAlgorithm(Token::ALGO_RS256);
break;

case Token::ALGO_HS256:
$this->auth0->configuration()->setTokenAlgorithm(Token::ALGO_HS256);
break;

default:
throw new InvalidTokenException('Invalid token algorithm.');
}

$exception = null;
foreach ($this->keys as $key) {
$this->auth0->configuration()->setClientSecret($key);
Expand Down

0 comments on commit 810a8be

Please sign in to comment.