Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ $token = array(
);

$jwt = JWT::encode($token, $key);
$decoded = JWT::decode($jwt, $key);
$decoded = JWT::decode($jwt, $key, 'HS256');

print_r($decoded);
?>
Expand Down
5 changes: 4 additions & 1 deletion lib/JWT/Authentication/JWT.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class JWT
* @uses jsonDecode
* @uses urlsafeB64Decode
*/
public static function decode($jwt, $key = null, $verify = true)
public static function decode($jwt, $key = null, $algo = null, $verify = true)
{
$tks = explode('.', $jwt);
if (count($tks) != 3) {
Expand All @@ -50,6 +50,9 @@ public static function decode($jwt, $key = null, $verify = true)
if (empty($header->alg)) {
throw new \DomainException('Empty algorithm');
}
if($algo && $header->alg !== $algo){
throw new \DomainException('Invalid algorithm');
}
if ($sig != JWT::sign("$headb64.$bodyb64", $key, $header->alg)) {
throw new \UnexpectedValueException('Signature verification failed');
}
Expand Down