Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Cognito User Pool without a password

I want to use a phone number as the username for my app and i want to be able to make it simple to sign up by just having to verify the phone number each time they want to login - no messy password remembering business.

How to do this with AWS Cognito User Pool as its asking me to mandatorily configure a password for each user.

I thought of using a dummy password for each user and configure mandatory user verification. Everytime the user sign out i can "Unverify" the user so that next time they would automatically be asked to verify the phone number. Also i would wire up my app to only "login" if the user is verified.

Please let me know if the is the best approach :( I'm new to AWS and i could't find any posts for this scenario.

Thanks !!

like image 206
spar Avatar asked Aug 14 '17 02:08

spar


People also ask

Is it possible to get AWS Cognito user password?

It is not possible to get a user password from AWS Cognito. Cognito just lets the user reset his password but it has got no API call to perform password retrieval and it's not meant to do that for security reasons.

Does Cognito hash passwords?

Cognito Identity uses the token from the identity provider to obtain a unique identifier for the user and then hashes it using a one-way hash so that the same user can be recognized again in the future without storing the actual user identifier.

Is Cognito user pool ID sensitive?

No, they are not.

What is the difference between Cognito user pool and identity pool?

Short description. User pools are for authentication (identity verification). With a user pool, your app users can sign in through the user pool or federate through a third-party identity provider (IdP). Identity pools are for authorization (access control).


1 Answers

Since AWS Cognito is not currently supporting passwordless authentication you need to implement a workaround with random password stored externally. You can implement the authentication flow as follows.

  • After user Signup (Also ask for mobile number and make it mandatory), store the Mobile number, Username and Password also in Dynamodb encrypted with AWS KMS (For additional security).
  • You can use MFA with mobile number for authentication challenge so that after the user enters mobile number and press login(In frontend), in the backend you can automatically do username password matching(Passthrough) and trigger the MFA to send a code for user's mobile and verify that using the AWS Cognito SDK (Without implementing custom mobile message and challenge).
  • If you plan to implement the flow manually(Without MFA) to send the SMS & validation, you can use AWS SNS for the purpose.

Check the following code sample to understand the insight of MFA and refer this link for more details.

    var userData = {          Username : 'username',         Pool : userPool     };      cognitoUser = new AWSCognito.CognitoIdentityServiceProvider.CognitoUser(userData);      var authenticationData = {         Username : 'username',         Password : 'password',     };      var authenticationDetails = new AWSCognito.CognitoIdentityServiceProvider.AuthenticationDetails(authenticationData);      cognitoUser.authenticateUser(authenticationDetails, {         onSuccess: function (result) {             alert('authentication successful!')         },          onFailure: function(err) {             alert(err);         },          mfaRequired: function(codeDeliveryDetails) {             var verificationCode = prompt('Please input verification code' ,'');             cognitoUser.sendMFACode(verificationCode, this);         }      }); 

Note: Here the MFA with mobile number is not used for the purpose of MFA but as a workaround to meet your requirement.

like image 141
Ashan Avatar answered Sep 23 '22 17:09

Ashan