Using Passwordless Authentication on iOS with emails - Objective C


This functionality has been deprecated in native. After June 2017, tenants cannot use the native passwordless 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 the email connection, the user is requested to enter their email address. Auth0 then sends an email to that address containing a one-time code.

Once the user enters this code into your application, a new user will be created in the email connection. The user is then authenticated by Auth0.

If the email address matches an existing user, Auth0 just authenticates the user:

On mobile platforms, your application will receive an ID Token, the user profile and, optionally, a Refresh Token.


Configure an email provider

By default, Auth0 sends the email from its own SMTP provider. Auth0's built-in email infrastructure should be used for testing level emails only. You can configure your own email provider to better monitor and troubleshoot the email service as well as be able to fully customize the emails.

You will need to use your own email provider to be able to modify the From, Subject and Body of Passwordless emails.

Configure the connection

In the Dashboard, on the Email page, under Connections > Passwordless, you can configure the contents and behavior of the email.

Multi-Language Support

The Message area supports usage of multiple languages.

By making a call to the /passwordless/start authentication endpoint, you can set the value of an 'x-request-language' header to the language of your choice. If the value of this header is not set, the language will be extracted from the value in the 'accept-language' header that is automatically set by the browser.

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:

{% if request_language contains 'dutch' %}
   Hier is uw verificatie code: {{ code }}
{% endif %}

{% if request_language contains 'fr-FR' %}
   Ceci est votre code: {{ code }}
{% endif %}

The following parameters are available when defining the template:

Exposed Parameter Description
code the password to use
link the magic link the name of the application name where the user is signing up
request_language the requested language for the message content
operation equals change_email when the template is triggered by an update to a user's email via the API, otherwise null


Using Auth0 Lock

The 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.

A0Lock *lock = ... //Fetch Lock instance from where you stored it
A0EmailLockViewController *controller = [lock newEmailViewController];
controller.onAuthenticationBlock = ^(A0UserProfile *profile, A0Token *token) {
    // Your user is now authenticated with Auth0
    // You'd probably want to store somewhere safe the tokens stored in "token" parameter
    [self dismissViewControllerAnimated:YES completion:nil];
[lock presentEmailController:controller fromController:self];

When this code runs, it will ask the user for their email address:

Then Auth0 will send to the user an email 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 email address first. Then call the following method:

A0Lock *lock = ... //Fetch Lock instance from where you stored it
A0APIClient *client = [lock apiClient];
[client startPasswordlessWithEmail:email success:^{
    // Email with code sent
} failure:^(NSError *error) {
    // Handle error

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

void(^failure)(NSError *) = ^(NSError *error) {
    // Handle error

void(^success)(A0UserProfile *, A0Token *) = ^(A0UserProfile *profile, A0Token *token) {
    // Your user is now authenticated with Auth0
    // You'd probably want to store somewhere safe the tokens stored in "token" parameter

A0Lock *lock = ... //Fetch Lock instance from where you stored it
A0APIClient *client = [lock apiClient];
[client loginWithEmail:email

Instead of sending the user a one time code, you can configure Auth0 to send a magic link:

Auth0 will send an email containing a clickable button or link:

After clicking the button, the user will be automatically signed-in to your application:

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