Cognito, PHP SDK Authentication User

0

I am using Cognito for handling user signup and login.
I want to authenticate user by using PHP Sdk but did not find any function for that please guide me how can i authenticate the user by using PHP Sdk .

Please guide me

asked 7 years ago1291 views
4 Answers
0

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

AWS
answered 7 years ago
profile picture
EXPERT
reviewed a month ago
0

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>"
}

answered 7 years ago
0

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;

answered 7 years ago
0

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.

AWS
answered 7 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions