yasuaki640 / cognito-srp-php
Helper written by PHP to get through SRP authentication for Amazon Cognito.
1.1.3
2024-11-16 01:17 UTC
Requires
- php: ^8.3
- aws/aws-sdk-php: ^3.323
- nesbot/carbon: ^3.8
- phpseclib/phpseclib: ^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.64
- phpstan/phpstan: ^1.12
- phpunit/phpunit: ^11.4
README
Helper written by PHP to get through SRP authentication for Amazon Cognito.
This was written in reference to the jenky/AwsCognitoIdentitySRP.php.
Install
composer require yasuaki640/cognito-srp-php
Usage
// instantiate aws client $client = new CognitoIdentityProviderClient([ ... ]); // instantiate helper $srpHelper = new CognitoSrp( 'your client id', 'your pool id', 'your client secret (required)', ); $result = $client->adminInitiateAuth([ 'AuthFlow' => 'USER_SRP_AUTH', 'ClientId' => 'your client id', 'UserPoolId' => 'your pool id', 'AuthParameters' => [ 'USERNAME' => $username, // calculate A 'SRP_A' => $srpHelper->SRP_A(), // calculate secret Hash 'SECRET_HASH' => $srpHelper->SECRET_HASH($username), ], ]); $authRes = $client->adminRespondToAuthChallenge([ 'ChallengeName' => 'PASSWORD_VERIFIER', 'UserPoolId' => 'your pool id', 'ClientId' => 'your client id', // generate authentication challenge response params 'ChallengeResponses' => $srpHelper->ChallengeResponses($result, $password), ]);