Skip to main content

Add MFA with SMS OTP

SMS OTP (One-Time Password) is a security mechanism where a password is sent to the user's registered mobile number, which they must enter during the login process. This password is typically valid for a short period.

During SMS OTP authentication, the user must access their mobile device to retrieve the OTP. This method ensures that only the person who has access to the registered mobile number can log in, providing an additional layer of security.

Follow the instructions given below to configure Multi-Factor Authentication (MFA) using SMS OTP in WSO2 Identity Platform.

Prerequisites​

Info

You can use SMS OTP for multi-factor authentication only if a previous authentication step is configured with username and password or another factor that can validate user credentials.

Set up SMS OTP​

WSO2 Identity Platform has some default settings for SMS OTP, which are sufficient for most cases. If required, you can change the default settings, as explained below.

To update the default SMS OTP settings:

  1. On the WSO2 Identity Platform Console, go to Connections and select SMS OTP.

  2. Update the following parameters in the Settings tab:

    Setup SMS OTP in WSO2 Identity Platform
    FieldDescription
    SMS OTP expiry timeSpecifies the expiry time of the OTP. The generated OTP will not be valid after this expiry time.
    Use only numeric characters for OTPSpecifies whether to use only numeric characters in the OTP. If this is selected, the generated OTP contains only digits (0-9). If this option is not selected, the OTP will contain alphanumeric characters.
    SMS OTP lengthSpecifies the number of characters allowed in the OTP.
    Allowed OTP resend attempt countSpecifies the number of allowed OTP resend attempts.
    Resend OTP block timeSpecifies the time duration to block OTP resend requests after reaching the maximum allowed resend attempts.
    Notify users on OTP delivery failureIf enabled, users are notified when the SMS OTP fails to send due to a connectivity or provider error. If disabled, the failure occurs silently and users are still prompted to enter the OTP without any error indication. Note that actual delivery failures (e.g., the SMS not reaching the recipient's device) may not be captured, depending on the provider used. This is disabled by default.
    Allow mobile number enrollment during loginIf enabled, users who don't have a mobile number can add and verify one during login. Learn more in Allow mobile number enrollment during login. This is disabled by default.
  3. Once you update the SMS OTP settings, click Update.

Enable SMS OTP for an app​

To enable SMS OTP for MFA, you need to add SMS OTP in the authentication flow of the application.

Follow the steps given below.

  1. On the WSO2 Identity Platform Console, go to Applications.

  2. Select the application to which you wish to add SMS OTP.

  3. Go to the Login Flow tab of the application and add the SMS OTP authenticator from your preferred editor:

    To add SMS OTP as a second-factor authenticator using the Visual Editor:

    1. Switch to the Visual Editor tab and go to Predefined Flows > Basic Flows > Add Multi-factor login.

    2. Select Username + Password -> SMS OTP.

    3. Click Confirm to add SMS OTP as a second factor to the sign-in flow.

      Configuring SMS OTP authenticator in WSO2 Identity Platform using the visual editor
    4. Select Enable backup codes if you wish to allow users to use backup codes to log in to the application. Learn more about configuring backup codes for users.

  4. Click Update to save your changes.

How it works​

When SMS OTP is enabled in the login flow of your application, the application user will be prompted with the SMS OTP authentication step once the first authentication step is completed. Given below are the high-level steps that follow:

  1. WSO2 Identity Platform sends the OTP to the user's mobile number.

  2. WSO2 Identity Platform prompts the user to enter the OTP code.

    Authenticate with SMS OTP in WSO2 Identity Platform
  3. If required, the user can request WSO2 Identity Platform to resend the OTP. The new OTP invalidates the previously sent OTP.

  4. The user enters the OTP and clicks Continue.

  5. If the authentication is successful, the user can access the application.

Allow mobile number enrollment during login​

Users who don't have a mobile number in their profile can add and verify one during login. WSO2 Identity Platform prompts for a mobile number only when SMS OTP comes after a step that verifies the user's credentials, such as Username & Password, and saves the number only after the user enters the OTP sent to it.

Configure at organization level​

Mobile number enrollment is disabled by default. To enable it for all applications in your organization:

  1. On the WSO2 Identity Platform Console, go to Connections.

  2. Click on SMS OTP and go to the Settings tab.

  3. Select the Allow mobile number enrollment during login checkbox.

  4. Click Update to save your changes.

Configure at application level​

To turn off mobile number enrollment for a specific application when it's enabled for the organization:

  1. On the WSO2 Identity Platform Console, enable SMS OTP for a selected application.

  2. Turn on Conditional Authentication by switching the toggle.

  3. Add the following authentication script.

    note

    The authenticatorParams method has been added to executeStep(2), assuming that SMS OTP is configured in step 2 of the authentication process. If you have configured SMS OTP in a different step, add the authenticatorParams method to the relevant step.

    var onLoginRequest = function (context) {
    executeStep(1);
    executeStep(2, {
    authenticatorParams: {
    local: {
    'sms-otp-authenticator': {
    'enrollUserInAuthenticationFlow': 'false'
    }
    }
    }
    }, {});
    };
  4. Click Update to save your changes.

Was this page helpful?