Skip to content

Commit

Permalink
Fix: handle different JWT::decode signatures (#54)
Browse files Browse the repository at this point in the history
* fix: handle differente JWT::decode signatures
* chore: coding style
* chore: code style again :)
  • Loading branch information
stefanorosanelli authored May 17, 2024
1 parent 561ae0f commit 74818d3
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Token/AppleAccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,17 @@ public function __construct(array $keys, array $options = [])
try {
$decoded = JWT::decode($options['id_token'], $key);
} catch (\UnexpectedValueException $e) {
$decoded = JWT::decode($options['id_token'], $key, ['RS256']);
$decodeMethodReflection = new \ReflectionMethod(JWT::class, 'decode');
$decodeMethodParameters = $decodeMethodReflection->getParameters();
// Backwards compatibility for firebase/php-jwt >=5.2.0 <=5.5.1 supported by PHP 5.6
if (array_key_exists(2, $decodeMethodParameters) &&
'allowed_algs' === $decodeMethodParameters[2]->getName()
) {
$decoded = JWT::decode($options['id_token'], $key, ['RS256']);
} else {
$headers = (object) ['alg' => 'RS256'];
$decoded = JWT::decode($options['id_token'], $key, $headers);
}
}
break;
} catch (\Exception $exception) {
Expand Down

0 comments on commit 74818d3

Please sign in to comment.