From 8efb193755df1991ebbcd6f12a6ae2bc9c8d49f7 Mon Sep 17 00:00:00 2001 From: yasuaki640 Date: Sat, 16 Nov 2024 10:11:49 +0900 Subject: [PATCH] change secret to required --- README.md | 2 +- src/CognitoSrp.php | 8 ++------ tests/CognitoSrpTest.php | 11 ++--------- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 11e9af5..37230e4 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ composer require yasuaki640/cognito-srp-php $srpHelper = new CognitoSrp( 'your client id', 'your pool id', - 'your client secret (if set)', + 'your client secret (required)', ); $result = $client->adminInitiateAuth([ diff --git a/src/CognitoSrp.php b/src/CognitoSrp.php index 868f4b3..2f471a1 100644 --- a/src/CognitoSrp.php +++ b/src/CognitoSrp.php @@ -46,7 +46,7 @@ class CognitoSrp private string $clientId; - private ?string $clientSecret; + private string $clientSecret; protected string $poolId; @@ -58,7 +58,7 @@ class CognitoSrp public function __construct( string $clientId, string $poolId, - ?string $clientSecret = null + string $clientSecret ) { $this->N = new BigInteger(static::N_HEX, 16); $this->g = new BigInteger(static::G_HEX, 16); @@ -301,10 +301,6 @@ public function SECRET_HASH(string $username): string */ private function hashClientSecret(string $message): string { - if ($this->clientSecret === null) { - throw new \InvalidArgumentException('If the user pool has a client secret set, you must pass the `$clientSecret` argument to the constructor'); - } - $hash = hash_hmac( 'sha256', $message, diff --git a/tests/CognitoSrpTest.php b/tests/CognitoSrpTest.php index 7a9c390..deed28a 100644 --- a/tests/CognitoSrpTest.php +++ b/tests/CognitoSrpTest.php @@ -18,7 +18,8 @@ protected function setUp(): void { $this->srpHelper = new CognitoSrp( 'dummy-client-id', - 'dummy-pool-id' + 'dummy-pool-id', + 'dummy-client-secret' ); } @@ -31,14 +32,6 @@ public function test_calculate_SRP_A(): void $this->assertIsString($largeA); } - public function test_fail_if_SECRER_HASH_called_without_secret_hash(): void - { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('If the user pool has a client secret set, you must pass the `$clientSecret` argument to the constructor'); - - $this->srpHelper->SECRET_HASH('dummy-username'); - } - public function test_SECRET_HASH_returns_hash_string(): void { $this->srpHelper = new CognitoSrp(