iOS Objective-C: Login

View on Github

iOS Objective-C: Login

Gravatar for
By Martin Walsh

This tutorial demonstrates how to add user login to an Objective-C 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.2.1 | Version 8.3.2 (8E2002) | iPhone 7 - iOS 10.3 (14E269)

The preferred way to integrate Auth0 in iOS apps is using Swift. Read about it in the iOS Swift Quickstart.

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

Configure Auth0

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:

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:

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.

Universal Login

Read the Browser-Based vs. Native Login Flows on Mobile Devices article to learn how to choose between the two types of login flows.

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.


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.

Set Up the Objective-C & Swift Hybrid

Configure project settings

  1. Download the HybridAuth.swift file and add it to your project. The following message appears: "Would you like to configure an Objective-C bridging header?". Click Yes.
  2. Click on your Xcode Project file.
  3. Click on Build Settings.
  4. Search for Defines Module.
  5. Change the value to Yes.
  6. Search for Product Module Name.
  7. Make a note of the name. This tutorial uses the name Auth0Sample.


To import the Swift code and Auth0 library, add the following headers:

Add the Callback

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

Import the Swift wrapper and Auth0 library:

Then, add the following UIApplicationDelegate method:

Implement Login

Import the Swift wrapper and Auth0 library:

Then, present the hosted login screen:

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