6
6
use DomainException ;
7
7
use Exception ;
8
8
use InvalidArgumentException ;
9
+ use OpenSSLAsymmetricKey ;
9
10
use UnexpectedValueException ;
10
11
use DateTime ;
11
12
@@ -59,7 +60,7 @@ class JWT
59
60
* Decodes a JWT string into a PHP object.
60
61
*
61
62
* @param string $jwt The JWT
62
- * @param Key|array<Key> $keyOrKeyArray The Key or array of Key objects.
63
+ * @param Key|array<Key>|mixed $keyOrKeyArray The Key or array of Key objects.
63
64
* If the algorithm used is asymmetric, this is the public key
64
65
* Each Key object contains an algorithm and matching key.
65
66
* Supported algorithms are 'ES384','ES256', 'HS256', 'HS384',
@@ -385,14 +386,20 @@ public static function urlsafeB64Encode($input)
385
386
/**
386
387
* Determine if an algorithm has been provided for each Key
387
388
*
388
- * @param string |array $keyOrKeyArray
389
+ * @param Key |array<Key>|mixed $keyOrKeyArray
389
390
* @param string|null $kid
390
391
*
391
- * @return an array containing the keyMaterial and algorithm
392
+ * @throws UnexpectedValueException
393
+ *
394
+ * @return array containing the keyMaterial and algorithm
392
395
*/
393
396
private static function getKeyMaterialAndAlgorithm ($ keyOrKeyArray , $ kid = null )
394
397
{
395
- if (is_string ($ keyOrKeyArray )) {
398
+ if (
399
+ is_string ($ keyOrKeyArray )
400
+ || is_resource ($ keyOrKeyArray )
401
+ || $ keyOrKeyArray instanceof OpenSSLAsymmetricKey
402
+ ) {
396
403
return array ($ keyOrKeyArray , null );
397
404
}
398
405
@@ -418,7 +425,7 @@ private static function getKeyMaterialAndAlgorithm($keyOrKeyArray, $kid = null)
418
425
}
419
426
420
427
throw new UnexpectedValueException (
421
- '$keyOrKeyArray must be a string key, an array of string keys, '
428
+ '$keyOrKeyArray must be a string|resource key, an array of string|resource keys, '
422
429
. 'an instance of Firebase\JWT\Key key or an array of Firebase\JWT\Key keys '
423
430
);
424
431
}
0 commit comments