Skip to content
Merged
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 src/JWT.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ private static function getKey(
return $keyOrKeyArray;
}

if (empty($kid)) {
if (empty($kid) && $kid !== '0') {
throw new UnexpectedValueException('"kid" empty, unable to lookup correct key');
}

Expand Down
10 changes: 6 additions & 4 deletions tests/JWTTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,11 @@ public function testEmptyKeyFails()
public function testKIDChooser()
{
$keys = [
'1' => new Key('my_key', 'HS256'),
'0' => new Key('my_key0', 'HS256'),
'1' => new Key('my_key1', 'HS256'),
'2' => new Key('my_key2', 'HS256')
];
$msg = JWT::encode(['message' => 'abc'], $keys['1']->getKeyMaterial(), 'HS256', '1');
$msg = JWT::encode(['message' => 'abc'], $keys['0']->getKeyMaterial(), 'HS256', '0');
$decoded = JWT::decode($msg, $keys);
$expected = new stdClass();
$expected->message = 'abc';
Expand All @@ -217,10 +218,11 @@ public function testKIDChooser()
public function testArrayAccessKIDChooser()
{
$keys = new ArrayObject([
'1' => new Key('my_key', 'HS256'),
'0' => new Key('my_key0', 'HS256'),
'1' => new Key('my_key1', 'HS256'),
'2' => new Key('my_key2', 'HS256'),
]);
$msg = JWT::encode(['message' => 'abc'], $keys['1']->getKeyMaterial(), 'HS256', '1');
$msg = JWT::encode(['message' => 'abc'], $keys['0']->getKeyMaterial(), 'HS256', '0');
$decoded = JWT::decode($msg, $keys);
$expected = new stdClass();
$expected->message = 'abc';
Expand Down