Skip to content

Commit 7a15d3c

Browse files
committed
Merge pull request firebase#48 from aztech-forks/master
Allow using \ArrayAccess as $key in \JWT::decode
2 parents f68efb8 + c595e2b commit 7a15d3c

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Authentication/JWT.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static function decode($jwt, $key = null, $allowed_algs = array())
7373
if (!is_array($allowed_algs) || !in_array($header->alg, $allowed_algs)) {
7474
throw new DomainException('Algorithm not allowed');
7575
}
76-
if (is_array($key)) {
76+
if (is_array($key) || $key instanceof \ArrayAccess) {
7777
if (isset($header->kid)) {
7878
$key = $key[$header->kid];
7979
} else {

tests/JWTTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,14 @@ public function testKIDChooser()
194194
$this->assertEquals($decoded, 'abc');
195195
}
196196

197+
public function testArrayAccessKIDChooser()
198+
{
199+
$keys = new ArrayObject(array('1' => 'my_key', '2' => 'my_key2'));
200+
$msg = JWT::encode('abc', $keys['1'], 'HS256', '1');
201+
$decoded = JWT::decode($msg, $keys, array('HS256'));
202+
$this->assertEquals($decoded, 'abc');
203+
}
204+
197205
public function testNoneAlgorithm()
198206
{
199207
$msg = JWT::encode('abc', 'my_key');

0 commit comments

Comments
 (0)