From 7e920d51c9101b952acf0858d4885a3676059d19 Mon Sep 17 00:00:00 2001 From: Vishwaraj Anand Date: Fri, 29 Dec 2023 22:53:17 +0530 Subject: [PATCH 1/3] chore: fix style check --- src/AccessToken.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AccessToken.php b/src/AccessToken.php index 0afc4ca1e..276719c3d 100644 --- a/src/AccessToken.php +++ b/src/AccessToken.php @@ -411,7 +411,7 @@ private function loadPhpsecPublicKey(string $modulus, string $exponent): string $exponent ]), 256), ]); - return $key->getPublicKey(); + return $key->__toString(); } $key = PublicKeyLoader::load([ 'n' => new BigInteger3($this->callJwtStatic('urlsafeB64Decode', [ From 03c15b81577878d30b7d4be44fc2b97b6499e9dd Mon Sep 17 00:00:00 2001 From: Vishwaraj Anand Date: Fri, 29 Dec 2023 23:11:48 +0530 Subject: [PATCH 2/3] chore: revert phpseclib change for phpseclib3 --- src/AccessToken.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/AccessToken.php b/src/AccessToken.php index 276719c3d..4a3e35eb9 100644 --- a/src/AccessToken.php +++ b/src/AccessToken.php @@ -399,7 +399,10 @@ private function checkAndInitializePhpsec() } } - private function loadPhpsecPublicKey(string $modulus, string $exponent): string + /** + * @return string|array + */ + private function loadPhpsecPublicKey(string $modulus, string $exponent) { if (class_exists(RSA::class) && class_exists(BigInteger2::class)) { $key = new RSA(); @@ -411,7 +414,7 @@ private function loadPhpsecPublicKey(string $modulus, string $exponent): string $exponent ]), 256), ]); - return $key->__toString(); + return $key->getPublicKey(); } $key = PublicKeyLoader::load([ 'n' => new BigInteger3($this->callJwtStatic('urlsafeB64Decode', [ From e3daf5a24feea2cca7e3495996760ab559e59ab6 Mon Sep 17 00:00:00 2001 From: Vishwaraj Anand Date: Fri, 29 Dec 2023 23:27:40 +0530 Subject: [PATCH 3/3] Update AccessToken.php --- src/AccessToken.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/AccessToken.php b/src/AccessToken.php index 4a3e35eb9..d283a77d6 100644 --- a/src/AccessToken.php +++ b/src/AccessToken.php @@ -38,6 +38,7 @@ use SimpleJWT\JWT as SimpleJWT; use SimpleJWT\Keys\KeyFactory; use SimpleJWT\Keys\KeySet; +use TypeError; use UnexpectedValueException; /** @@ -400,7 +401,8 @@ private function checkAndInitializePhpsec() } /** - * @return string|array + * @return string + * @throws TypeError If the key cannot be initialized to a string. */ private function loadPhpsecPublicKey(string $modulus, string $exponent) { @@ -414,7 +416,11 @@ private function loadPhpsecPublicKey(string $modulus, string $exponent) $exponent ]), 256), ]); - return $key->getPublicKey(); + $formattedPublicKey = $key->getPublicKey(); + if (is_string($formattedPublicKey)) { + return $formattedPublicKey; + } + throw new TypeError('Failed to initialize the key'); } $key = PublicKeyLoader::load([ 'n' => new BigInteger3($this->callJwtStatic('urlsafeB64Decode', [ @@ -424,7 +430,12 @@ private function loadPhpsecPublicKey(string $modulus, string $exponent) $exponent ]), 256), ]); - return $key->toString('PKCS8'); + // Ensure the key is correctly initialized + $formattedPublicKey = $key->toString('PKCS8'); + if (is_string($formattedPublicKey)) { + return $formattedPublicKey; + } + throw new TypeError('Failed to initialize the key'); } /**