Implement a Skip Option for MFA Enrollment Using Auth0 Forms

Overview

Administrators can implement a skip option for Multi-Factor Authentication (MFA) enrollment using Auth0 Forms and a Post-Login Action. The native MFA enrollment API does not support a skip option directly, but creating a custom form allows users to choose whether to enroll in MFA or skip the process during login.

Applies To

  • Auth0
  • Multi-Factor Authentication (MFA)
  • Auth0 Forms
  • Post-Login Actions

Solution

What steps are needed to configure the form to capture the user's preference?

Create a form to capture the user preference regarding MFA enrollment by navigating to the Forms section, adding a Boolean field to the Step node, connecting it to an Ending Screen node, and publishing the form.

  1. Navigate to Dashboard > Actions > Forms and create a new form.
  2. Add a Boolean field to the Step node with the ID of the preferred choice (for example, with the ID mfa_choice) and configure two options for the field, such as Yes and No.
  3. Connect the Step node to an Ending Screen node.
  4. Publish the form.
  5. Note the Form ID displayed in the Render tab for use in the Action.

Configure the Post-Login Action.

Create a new Post-Login Action by navigating to the Library, entering the provided code snippet into the Action editor, replacing the placeholder with the actual Form ID, and deploying the Action.

  1. Navigate to Dashboard > Actions > Library and create a new custom Action.
  2. Enter the following code into the Action editor, replacing <form-id> with the Form ID noted previously.
exports.onExecutePostLogin = async (event, api) => {
  if (!event.user.enrolledFactors || event.user.enrolledFactors.length === 0) {
    api.prompt.render('<form-id>');
  }
};

exports.onContinuePostLogin = async (event, api) => {
  const choice = event.prompt?.fields?.mfa_choice;
  if (choice === true) {
    api.authentication.enrollWith({ type: 'otp' }, {
      additionalFactors: [{ type: 'phone' }]
    });
  }
};

  1. Deploy the Action.

What steps add the Action to the login flow?

Add the custom Action to the post-login trigger by navigating to the Triggers section, dragging the created Action to the trigger section, applying the changes, and testing the behavior.

  1. Navigate to Actions, select Triggers, and choose the post-login trigger.
  2. Locate the created Action in the Add Action section on the right side of the screen.
  3. Drag the Action toward the trigger section and drop it on the Drop here button.
  4. Select Apply.
  5. Test the behavior with a user to verify the MFA skip use case.

NOTE: Combine skip logic with secure, properly tested MFA enforcement logic aligned with the specific needs of the application.

Recommended content

No recommended content found...