I have a mobile application and wanted to use AWS Cognito pool for user management (sign up & sign in). I wanted to provide below 3 options for users to log in to my app
- username, password
- phone number with OTP login - on the sign in screen, the user enters his phone number, and Cognito should send OTP code, and on verification, it should allow to login
- Google connect login
during sign up, the user will set up username, password and adds verified phone number and optionally they can add their google connect to their profile.
How to setup Cognito pool for this scenario that user can choose any of the above 3 options to log in to the app?
I found a way to setup Cognito to allow multiple login options. setup Cognito like below 1. select use phone number as username 2. make it mandatory and verifiable. 3. this will make phone_number as alias for login.
use CUSTOM_CHALLENGE option to configure login with phone number with OTP.
basically, we need to configure 3 triggers in Cognito to send OTP to user registered number. 1. sign-in define auth challenge trigger -- define CUSTOM_CHALLENGE 2. sign-in create auth challenge trigger -- create logic to generate OTP and send SMS using SNS service 3. sign-in verify auth challenge trigger -- validate received OTP, generated OTP will be available in context so no need to save in any database.
Trigger#1 - define auth challenge
Trigger#2 - create auth challenge make sure this lambda have SNS role
Trigger#3 - verify auth challenge response