Search code examples
phpamazon-cognitoaws-php-sdk

User pool client {id}does not exist


Here is my code:

 use Aws\CognitoIdentityProvider\CognitoIdentityProviderClient;

$args = [ 
    'credentials' => [
        'key'    => 'valid',
        'secret' => 'valid',
    ],
    'region' => 'us-west-2',
    'version' => 'latest',

    'app_client_id' => 'valid',
    'app_client_secret' => 'valid',
    'user_pool_id' => 'valid',
];

$email = '[email protected]';

$client = new CognitoIdentityProviderClient($args);
$hash_key = cognitoSecretHash($email);

$login =  $client->adminInitiateAuth([
            'AuthFlow' => 'ADMIN_NO_SRP_AUTH',
            'AuthParameters' => [
                'Username' => $email,
                'Password' => '12345678',
                'SecretHash' => $hash_key,
            ],
            'ClientId' => 'valid',
            'UserPoolId' => 'valid',
        ]);

return $login;


 function cognitoSecretHash($username)
{
    $message = $username . 'app_client_id';

    $hash = hash_hmac(
        'sha256',
        $message,
        'app_client_secret',
        true
    );

    return base64_encode($hash);
}

Its give me this error:

Fatal error: Uncaught exception 'Aws\CognitoIdentityProvider\Exception\CognitoIdentityProviderException' with message 'Error executing "AdminInitiateAuth" on "https://cognito-idp.us-west-2.amazonaws.com"; AWS HTTP error: Client error: POST https://cognito-idp.us-west-2.amazonaws.com resulted in a 400 Bad Request response: {"__type":"ResourceNotFoundException","message":"User pool client {id} does not exist."} ResourceNotFoundException (client): User pool client {id} does not exist. - {"__type":"ResourceNotFoundException","message":"User pool client {id} does not exist."}' GuzzleHttp\Exception\ClientException: Client error: POST https://cognito-idp.us-west-2.amazonaws.com resulted in a 400 Bad Request response: {"__type":"ResourceNotFoundException","message":"User pool client {id} does not exist."} in D:\xampp\htdocs\test\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php:113 Stack trace: #0 D:\xampp\htdocs\test\vend in D:\xampp\htdocs\test\vendor\aws\aws-sdk-php\src\WrappedHttpHandler.php on line 195


Solution

  •  $login =  $client->adminInitiateAuth([
                'AuthFlow' => 'ADMIN_NO_SRP_AUTH',
                'AuthParameters' => [
                    'USERNAME' => $email,
                    'PASSWORD' => $password,
                    'SECRET_HASH' => $hash_key,
                ],
                'ClientId' => $clientId,
                'UserPoolId' => $poolId,
            ]);