Skip to content

Commit

Permalink
change secret to required
Browse files Browse the repository at this point in the history
  • Loading branch information
yasuaki640 committed Nov 16, 2024
1 parent a6e038d commit 8efb193
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
8 changes: 2 additions & 6 deletions src/CognitoSrp.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class CognitoSrp

private string $clientId;

private ?string $clientSecret;
private string $clientSecret;

protected string $poolId;

Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 2 additions & 9 deletions tests/CognitoSrpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ protected function setUp(): void
{
$this->srpHelper = new CognitoSrp(
'dummy-client-id',
'dummy-pool-id'
'dummy-pool-id',
'dummy-client-secret'
);
}

Expand All @@ -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(
Expand Down

0 comments on commit 8efb193

Please sign in to comment.