- Newest
- Most votes
- Most comments
I believe you are trying to authenticate the users on your backend, which would be a secure environment and you can use AdminInitiateAuth API to authenticate the user.
More details - http://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-authentication-flow.html
include(APPPATH . 'third_party/aws/aws-autoloader.php');
use Aws\CognitoIdentity\CognitoIdentityClient;
use Aws\CognitoIdentityProvider\CognitoIdentityProviderClient;
use Aws\Sts\StsClient;
For using "AdminInitiateAuth" function need to include any specific file?
Also did not understand "ADMIN_NO_SRP_AUTH" thing in the following call
AdminInitiateAuth Request {
"AuthFlow":"ADMIN_NO_SRP_AUTH",
"AuthParameters":{
"USERNAME":"<username>",
"PASSWORD":"<password>"
},
"ClientId":"<clientId>",
"UserPoolId":"<userPoolId>"
}
I am getting this exception
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":"UnrecognizedClientException","message":"The security token included in the request is invalid."} UnrecognizedClientException (client): The security token included in the request is invalid. - {"__type":"UnrecognizedClientException","message":"The security token included in the request is invalid."}
and my code is
include(APPPATH . 'third_party/aws/aws-autoloader.php');
use Aws\CognitoIdentity\CognitoIdentityClient;
use Aws\CognitoIdentityProvider\CognitoIdentityProviderClient;
use Aws\Sts\StsClient;
$CognitoClient = CognitoIdentityProviderClient::factory(
array(
'version' => '2016-04-18',
'region' => 'us-west-2',
'credentials' => array(
'key' => 'xxxxxxxxxxxxxxxxxx,
'secret' => '',
),
)
);
$CognitoResponse = $CognitoClient->adminInitiateAuth(array(
'AuthFlow' => 'USER_SRP_AUTH|REFRESH_TOKEN_AUTH|REFRESH_TOKEN|CUSTOM_AUTH|ADMIN_NO_SRP_AUTH', // REQUIRED
'AuthParameters' => array(
"USERNAME" => "ashaheen",
"PASSWORD" => "Password123!!!"
),
'ClientId' => '2cidrtl9prq6mp2l3ou9jn1ue', // REQUIRED
'UserPoolId' => ' us-west-2_hyndOXD9H', // REQUIRED
));
echo '<pre>'; print_r($CognitoResponse); exit;
Can you check that you are not interchanging access key and secret key?
Additionally please check that credentials you are using have access to cognito-idp actions.
Relevant content
- Accepted Answerasked a month ago
- Accepted Answerasked 2 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 9 months ago