PHP code example of yasuaki640 / cognito-srp-php

1. Go to this page and download the library: Download yasuaki640/cognito-srp-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yasuaki640 / cognito-srp-php example snippets


    // instantiate aws client
    $client = new CognitoIdentityProviderClient([
        ...
    ]);

    // instantiate helper
    $srpHelper = new CognitoSrp(
        'your client id',
        'your pool id',
        'your client secret (e,
             // 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), 
    ]);
shell
composer