'PHP AWS Cognito 'Error executing "SignUp" : ResourceNotFoundException : User pool client XXXX does not exist
When i implement AWS Cognito in my project Occur following error.
Uncaught exception 'Aws\CognitoIdentityProvider\Exception\CognitoIdentityProviderException' with message 'Error executing "SignUp" on "https://cognito-idp.us-east-1.amazonaws.com"; AWS HTTP error: Client error: `POST https://cognito-idp.us-east-1.amazonaws.com` resulted in a `400 Bad Request` response: {"__type":"ResourceNotFoundException","message":"User pool client XXXX does not exist."} ResourceNotFoundException (client): User pool client XXXX does not exist. - {"__type":"ResourceNotFoundException","message":"User pool client XXXX does not exist."}' GuzzleHttp\Exception\ClientException: Client error: `POST https://cognito-idp.us-east-1.amazonaws.com` resulted in a `400 Bad Request` response: {"__type":"ResourceNotFoundException","message":"User pool client XXXX does not exist."} in /vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php on line 191
I was used this URL: https://github.com/pmill/aws-cognito
This is my PHP code:
if(isset($_POST['action'])) {
$username = $_POST['username'] ?? '';
$password = $_POST['password'] ?? '';
if($_POST['action'] === 'register') {
$email = $_POST['email'] ?? '';
$error = $client->registerUser($username, $password, [
'email' => $email,
]);
if(empty($error)) {
header('Location: confirm.php?username=' . $username);
exit();
}
}}
This is config.php file.
$config = [
'credentials' => [
'key' => 'XXXXXXXXXXXXXXXX',
'secret' => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
],
'region' => 'XXXXXXXXXXXXXXXX',
'version' => 'latest',
'app_client_id' => 'XXXXXXXXXXXXXXXX',
'app_client_secret' => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
'user_pool_id' => 'XXXXXXXXXXXXXXXX'];
require './vendor/autoload.php';
$aws = new \Aws\Sdk($config);
$cognitoClient = $aws->createCognitoIdentityProvider();
$client = new \pmill\AwsCognito\CognitoClient($cognitoClient);
$client->setAppClientId($config['app_client_id']);
$client->setAppClientSecret($config['app_client_secret']);
$client->setRegion($config['region']);
$client->setUserPoolId($config['user_pool_id']);
return $client;
Solution 1:[1]
// use Aws\Exception\AwsException;
// use Aws\CognitoIdentityProvider\CognitoIdentityProviderClient;
$awsCognitoClient = new CognitoIdentityProviderClient([
'version' => 'latest',
'region' => 'us-east-1',//Change with your region
'credentials' => [
'key' => YOUR_AWS_ACCESS_KEY,
'secret' => YOUR_AWS_SECRET,
],
]);
try {
$result = $awsCognitoClient->adminInitiateAuth([
'AuthFlow' => 'ADMIN_NO_SRP_AUTH',
'ClientId' => YOUR_APP_CLIENT_ID,
'UserPoolId' => YOUR_USER_POOL_ID,
'AuthParameters' => [
'USERNAME' => $userName,
'PASSWORD' => $password,
],
]);
$arr = $result->toArray();
} catch (AwsException $e) {
$errorArr = $e->toArray();
$statusCode = $e->getStatusCode();
$errorMessageCompleteLog = $e->getMessage();
}
That must give you the user information if success, if you get some error in the client, try making another client and during the creating process, there is a checkbox on the Cognito where it says Generate client secret
, uncheck the checkbox and use the new credentials.
Solution 2:[2]
The error is thrown if the client id you are passing actually does not exist. Maybe the user pool is created in a different region or configuration parameters are wrong
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Hygison Brandao |
Solution 2 | Alessandro Bellanda |