Skip to content

Commit

Permalink
Update usage of the JWT lib
Browse files Browse the repository at this point in the history
  • Loading branch information
christeredvartsen committed Jul 11, 2023
1 parent 81832c9 commit 7d02381
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/ArrayContainsComparator/Matcher/JWT.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Firebase;
use InvalidArgumentException;
use Imbo\BehatApiExtension\ArrayContainsComparator as Comparator;
use UnexpectedValueException;

/**
* Match a JWT token
Expand Down Expand Up @@ -76,10 +77,20 @@ public function __invoke($jwt, $name) {
}

$token = $this->jwtTokens[$name];
$result = (array) Firebase\JWT\JWT::decode($jwt, $token['secret'], $this->allowedAlgorithms);

if (!$this->comparator->compare($token['payload'], $result)) {
throw new InvalidArgumentException('JWT mismatch.');
foreach ($this->allowedAlgorithms as $algorithm) {
try {
$result = (array) Firebase\JWT\JWT::decode($jwt, new Firebase\JWT\Key($token['secret'], $algorithm));
} catch (UnexpectedValueException $e) {
// try next algorithm
continue;
}

if ($this->comparator->compare($token['payload'], $result)) {
return true;
}
}

throw new InvalidArgumentException('JWT mismatch.');
}
}

0 comments on commit 7d02381

Please sign in to comment.