Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Login with adminInitiateAuth using email and password in AWS Cognito

Currently I am developing a custom login flow for some of my projects, using AWS Cognito.

Recently I achieved the login using username and password, as follows:

const data: CognitoIdentityServiceProvider.Types.AdminInitiateAuthRequest = {
    UserPoolId,
    AuthFlow: "ADMIN_USER_PASSWORD_AUTH",
    ClientId: CognitoConfig.ClientId,
    AuthParameters: {
        USERNAME: username,
        PASSWORD: password,
        // SECRET_HASH: hash,
    }
};

Is it possible to login using email+password using CognitoIdentityServiceProvider.adminInitiateAuth?

Ive tried to replace USERNAME with EMAIL (and the respective field value), but I got an InvalidParameterException, expecting USERNAME to be forwarded.

like image 663
Ruan Kotovich Avatar asked Sep 08 '25 04:09

Ruan Kotovich


1 Answers

Try to pass the email in USERNAME attribute, Also set the AuthFlow to "ADMIN_NO_SRP_AUTH"

const data: CognitoIdentityServiceProvider.Types.AdminInitiateAuthRequest = {
    UserPoolId,
    AuthFlow: "ADMIN_NO_SRP_AUTH",
    ClientId: CognitoConfig.ClientId,
    AuthParameters: {
        USERNAME: '[email protected]',
        PASSWORD: password,
        // SECRET_HASH: hash,
    }
};

https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_AdminInitiateAuth.html

like image 176
Dragan Velkovski Avatar answered Sep 09 '25 17:09

Dragan Velkovski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!