Prerequisites
Before you can use the MFA APIs, you’ll need to enable the MFA grant type for your application. Go to Auth0 Dashboard > Applications > Advanced Settings > Grant Types and select MFA.- Configure OTP as a factor in the Dashboard or using the Management API.
Enroll with OTP
Get MFA token
Depending on when you are triggering enrollment, you can obtain an for using the MFA API in different ways:- If you are enrolling during authentication, see Authenticate With Resource Owner Password Grant and MFA.
- If you want to let the user enroll a factor at any moment, see Manage MFA Factor Enrollments.
Enroll authenticator
Make aPOST
request to the MFA Associate endpoint to enroll the user’s authenticator. The bearer token required by this endpoint is the MFA token obtained in the previous step.
To enroll with OTP, set the authenticator_types
parameter to [otp]
.
User is already enrolled
error, the user already has an MFA factor enrolled. Before associating another factor with the user, you must challenge the user with the existing factor.
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.
Confirm OTP enrollment
To confirm the enrollment, the end user will need to enter the secret obtained in the previous step in an OTP generator application like Google Authenticator. They can enter the secret by scanning a QR code with thebarcode_uri
or by typing the secret code manually in that OTP application. You should provide users a way to get the secret as text in case they cannot scan the QR code (for example, if they are enrolling from a mobile device, or using a desktop OTP application).
After the user enters the secret, the OTP application will display a 6-digit code, that the user should enter in your application. The application should then make a POST
request to the , including that otp
value.
active
is true
.
Challenge with OTP
Get MFA token
Get an MFA token following the steps described in Authenticate With Resource Owner Password Grant and MFA.Retrieve enrolled authenticators
You can list all enrolled authenticators using the MFA Authenticators endpoint:Complete authentication using received code
The user will collect a one time password, which you will then collect from them. You can verify the code and get authentication tokens using the OAuth0 Token endpoint, specifying the one time password in theotp
parameter: