Associate an Out-of-Band Authenticator

In this tutorial, you'll learn how to configure your application so users can self-associate out-of-band (OOB) authenticators.

Before you start

Before you can use the MFA APIs, you'll need to enable the MFA grant type for your application. You can enable the MFA grant by going to Applications > Your Application > Advanced Settings > Grant Types and selecting MFA.

1. Get the MFA token

When using Universal Login, users get prompted to enroll an MFA factor the first time they authenticate. If you want to provide end users a way to enroll an additional factor, you need to obtain an Access Token for the https://YOUR_DOMAIN/mfa audience and the enroll scope. You can do it by specifying that audience as part the initial authentication request, or in a different one.

When using the Resource Owner Password Grant, when users try to authenticate without an active authenticator associated with their account, Auth0 will return an mfa_required error when calling the /oauth/token endpoint. The request might look something like this:

The response will include the mfa_required error and a mfa_token that you can use when calling the /mfa/associate endpoint to enroll your first authenticator.

2. Request association of the authenticator

Next, make a POST request to the /mfa/associate endpoint to request association of the user's authenticator. The Access Token required by this endpoint is the MFA token received in the previous step.

To associate an authenticator where the challenge type is an SMS message containing a code the user provides, make the following POST request to the /mfa/associate endpoint. This will both trigger an MFA challenge for the user and associate the new authenticator.

Be sure to replace the placeholder values in the payload body shown below as appropriate.

If successful, you'll receive a response like this:

Recovery Codes

If this is the first time the user is associating an authenticator, you'll notice the response includes recovery_codes. Recovery codes are used to access the user's account in the event that they lose access to the account or device used for their second factor authentication. These are one-time usable codes, and new ones are generated as necessary.

3. Confirm the authenticator association

Once the authenticator is associated, it must be used at least once to confirm the association.

To confirm the association of an authenticator using SMS messages for the MFA challenge, make a POST request to the oauth/token endpoint. Now, you can add the oob_code retrieved previously as a parameter in the request.

Be sure to replace the placeholder values in the payload body shown below as appropriate.

If the call was successful, you'll receive a response in the below format, containing the Access Token:

At this point, the authenticator is fully associated and ready to be used, and you have an Access Token for the user.

You can check at any point to verify whether an authenticator has been confirmed by calling the mfa/authenticators endpoint. If the authenticator is confirmed, the value returned for active is true.