iOS Swift: Login

View on Github

iOS Swift: Login

Gravatar for
By Martin Walsh

This tutorial demonstrates how to add user login to a Swift application using Auth0. We recommend you to Log in to follow this quickstart with examples configured for your account.

I want to explore a sample app

2 minutes

Get a sample configured with your account settings or check it out on Github.

View on Github
System requirements: CocoaPods 1.6 (Beta) | Xcode 10.1 | iOS 9+

New to Auth? Learn How Auth0 works, how it integrates with Native Applications and which protocol it uses.


Configure Auth0

Multi-Factor Authentication

Get Your Application Keys

When you signed up for Auth0, a new application was created for you, or you could have created a new one.

You will need some details about that application to communicate with Auth0. You can get these details from the Application Settings section in the Auth0 dashboard.

You need the following information:

  • Domain
  • Client ID

If you download the sample from the top of this page these details are filled out for you.

If you have more than one application in your account, the sample comes with the values for your Default App.

App Dashboard

Add your credentials in the Auth0.plist file. If the file does not exist in your project yet, create it:

Password Reset

Configure Callback URLs

A callback URL is a URL in your application where Auth0 redirects the user after they have authenticated.

The callback URL for your app must be whitelisted in the Allowed Callback URLs field in your Application Settings. If this field is not set, users will be unable to log in to the application and will get an error.

In your application's Info.plist file, register your iOS Bundle identifier as a custom scheme:

If your Info.plist file is not in the format shown above, you can right-click Info.plist in Xcode and select Open As > Source Code.

Go to your Dashboard Settings and make sure that the Allowed Callback URLs field contains the following callback URL:

e.g. If your bundle identifier was and your domain was then this value would be

Start the Authentication

Universal Login is the easiest way to set up authentication in your application. We recommend using it for the best experience, best security and the fullest array of features.

You can also embed the login dialog directly in your application using the Lock widget. If you use this method, some features, such as single sign-on, will not be accessible. To learn how to embed the Lock widget in your application, follow the Embedded Login sample. Make sure you read the Browser-Based vs. Native Login Flows on Mobile Devices article to learn how to choose between the two types of login flows.

login page

Email Verification

Install Dependencies


If you are using Carthage, add the following to your Cartfile:

Then, run carthage bootstrap.

For more information on how to use Carthage, read their official documentation.

Custom DB Connections


If you are using Cocoapods, add the following to your Podfile:

Then, run pod install.

For more information on how to use Cocoapods, read the Cocoapods documentation.


Add the Callback

For Auth0 to handle the authentication callback, update your AppDelegate file.

First, import the Auth0 module:

Then, add the following UIApplicationDelegate method:


Implement Login

First, import the Auth0 module in the file where you want to present the login page:

Then, present the login screen:

This adds the profile scope to enable retrieving the User Profile.

After the user authenticates, their information is returned in a credentials object.

To learn more about the credentials object, read the Credentials article.

Use Auth0 for FREE