diff options
author | Rob DiMarco <rob@firebase.com> | 2015-05-19 14:30:28 -0700 |
---|---|---|
committer | Rob DiMarco <rob@firebase.com> | 2015-05-19 14:30:28 -0700 |
commit | 7a15d3cbabb5903192f81487634239ecfc1af309 (patch) | |
tree | cd895d5b86080015c9dbee00ae20dc86098e04da | |
parent | f68efb87855220b9c13bdcd56a90840be0b8ba9e (diff) | |
parent | c595e2bd231c7aedb7c27d15713a213feafda073 (diff) | |
download | php-jwt-7a15d3cbabb5903192f81487634239ecfc1af309.zip php-jwt-7a15d3cbabb5903192f81487634239ecfc1af309.tar.gz php-jwt-7a15d3cbabb5903192f81487634239ecfc1af309.tar.bz2 |
Merge pull request #48 from aztech-forks/master
Allow using \ArrayAccess as $key in \JWT::decode
-rw-r--r-- | Authentication/JWT.php | 2 | ||||
-rw-r--r-- | tests/JWTTest.php | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/Authentication/JWT.php b/Authentication/JWT.php index e65dc50..7d6665b 100644 --- a/Authentication/JWT.php +++ b/Authentication/JWT.php @@ -73,7 +73,7 @@ class JWT if (!is_array($allowed_algs) || !in_array($header->alg, $allowed_algs)) { throw new DomainException('Algorithm not allowed'); } - if (is_array($key)) { + if (is_array($key) || $key instanceof \ArrayAccess) { if (isset($header->kid)) { $key = $key[$header->kid]; } else { diff --git a/tests/JWTTest.php b/tests/JWTTest.php index da9975c..b1fc1eb 100644 --- a/tests/JWTTest.php +++ b/tests/JWTTest.php @@ -194,6 +194,14 @@ class JWTTest extends PHPUnit_Framework_TestCase $this->assertEquals($decoded, 'abc'); } + public function testArrayAccessKIDChooser() + { + $keys = new ArrayObject(array('1' => 'my_key', '2' => 'my_key2')); + $msg = JWT::encode('abc', $keys['1'], 'HS256', '1'); + $decoded = JWT::decode($msg, $keys, array('HS256')); + $this->assertEquals($decoded, 'abc'); + } + public function testNoneAlgorithm() { $msg = JWT::encode('abc', 'my_key'); |