Passwordless Authentication with Auth0.Swift

Using Passwordless Authentication on iOS with SMS in Swift


This functionality has been deprecated in native. After June 2017, tenants cannot use the native passwordlesspasswordless flow. The functionality will continue to work for tenants that currently have it enabled. If at some point the passwordless mode feature is changed or removed from service, customers who currently use it will be notified beforehand and given ample time to migrate.

With an SMS connection, the user is asked to enter a phone number, to which Auth0 sends a one-time code using Twilio. The user then enters the code into your application.

If the phone number attached to the code matches an existing user, Auth0 authenticates the user:

Existing User Flow

If the user is new, their user profile is created for the sms connection before they are authenticated by Auth0.

New User Flow

On mobile platforms, your app will receive an ID Token, the user profile, and optionally, a Passwordless authenticationRefresh Token.

How Passwordless works


Step 1: Request the code

Open an account with Twilio

You will need a Twilio Account SID and a Twilio Auth Token. These are the Twilio API credentials that Auth0 will use to send an SMS to the user.

Step 2: Input the code

Configure the connection

  1. Navigate to the Connections > Passwordless page in the Auth0 Dashboard, and enable the SMS toggle.

Enable SMS Passwordless

  1. Enter your Twilio Account SID and Twilio Auth Token.

To learn how to find your Twilio SID and Auth Token, see Twilio docs: How to create an Application SID and Auth Tokens and how to change them.

Configure SMS Passwordless

  1. Select your SMS Source and depending on your selection, enter either your Twilio Messaging Service SID or a From phone number. Users will see what you enter as the sender of the SMS.

To learn about using Twilio Copilot, see Twilio docs: Sending Messages with Copilot.

  1. In Message, enter the body text of the SMS.

The @@password@@ placeholder will automatically be replaced with the one-time password that is sent to the user.

  1. Adjust settings for your OTP Expiry and OTP Length, and click SAVE.

If you choose to extend the amount of time it takes for your one-time password to expire, you should also extend the length of the one-time password code. Otherwise, an attacker has a larger window of time to attempt to guess a short code.

Passwordless parameters

Multi-language support

The Message area supports multiple languages.

To choose the language, call the /passwordless/start authentication endpoint and set the value of the 'x-request-language' header. When this header is not set, the language is extracted from the 'accept-language' header, which is automatically set by the browser.

Message syntax

The Message area accepts Liquid syntax. You can use this syntax, combined with exposed parameter values, to programmatically construct elements of the message. For example, you can reference the request_language parameter to change the language of the message:

The following parameters are available when defining the message template:

Exposed Parameter Description
password or code The password to use
phone_number The user's phone number The name of the application with which the user is signing up
request_language The requested language for message content

Enable your apps

Click the Apps tab, and enable the apps for which you would like to use Passwordless SMS.


Using Auth0 Lock

Lock is a widget that allows you to easily integrate Auth0's Passwordless Authentication into your iOS applications.

After installing and configuring Lock.iOS-OSX, you will be able to use Lock as follows.

When this code runs, it will ask the user for their phone number:

Then Auth0 will use Twilio to send to the user an SMS containing the one-time code:

Lastly, the user enters the one-time password into Lock. Then, if the password is correct, the user is authenticated.

This code will call onAuthenticationBlock, where the ID Token, Refresh Token, and user profile are typically stored. Then the user will be allowed to continue to the authenticated part of the application.

Using your own UI

If you choose to build your own UI, your code will need to ask the user for their phone number first. Then call the following method:

After the passwordless login process begins, ask the user for the one-time code. Then authenticate using that code:

Lastly, once the user is authenticated, your app will be able to access the user profile and tokens returned by Auth0.