Using AWS Cognito with Authsignal rules
Learn how to use Authsignal rules to implement adaptive MFA with AWS Cognito
With Authsignal rules you can require MFA only when certain conditions are met - for example, if a user is authenticating on a new device. Rules can also be used to target users and you can pass your own custom data points as input.
This guide will cover how to modify your AWS Cognito integration code to use rules. It builds on previous guides which show how to integrate AWS Cognito with Authsignal when using Amplify or when using the AWS SDK.
Conditional MFA on login
A common scenario for rules is to control when a secondary MFA step is required after completing a primary authentication step such as username and password.
Define Auth Challenge lambda
In this case we assume the Define Auth Challenge lambda is implemented to require multiple authentication steps.
The “CUSTOM_CHALLENGE” step is delegated to Authsignal.
Create Auth Challenge lambda
When tracking our action in the Create Auth Challenge lambda we can check the state
field in the response to see whether our rule has determined that a challenge is required for the action.
In addition to the url
for the pre-built UI, we will also pass this state
value along with a token
back to our app as public challenge parameters.
The app code
Now we can adapt our app code to use the state
param to determine whether MFA is required.
Verify Auth Challenge Response lambda
Finally, we need to update our Verify Auth Challenge Response lambda to handle if the user is allowed to bypass MFA.
The only change here is to set event.response.answerCorrect
to true if the state
of the action is either “CHALLENGE_SUCCEEDED” (because the user successfully completed an MFA step) or “ALLOW” (because the user wasn’t required to complete MFA).
Next steps
Was this page helpful?