iOS - Objective C

Sample Project

Download this sample project configured with your Auth0 API Keys.

System Requirements
  • CocoaPods 0.39.0
  • XCode 7.2.1
  • Simulator - iOS 9.2 - iPhone 6
Show requirements

1. Initial Setup

Go to the Application Settings section of your app in the Auth0 dashboard and make sure that Allowed Callback URLs contains the following value:


2. Add the Auth0 Dependencies

Add the following to the Podfile and run pod install:

pod 'Lock', '~> 1.28'

NOTE: If you need help installing CocoaPods, see: What is CocoaPods.

3. Configure Auth0 Lock for iOS

  1. Add the following entries to your app's Info.plist:
Key Value
  1. Register a new URL Type in your app's Targets info section with the following scheme: a0YOUR_CLIENT_ID


  2. Create and configure an instance of A0Lock with your Auth0 credentials from Info.plist. This sample uses a custom object called MyApplication:

@class A0Lock;
@interface MyApplication : NSObject
@property (readonly, nonatomic) A0Lock *lock;
+ (MyApplication *)sharedInstance;
#import "MyApplication.h"
#import <Lock/Lock.h>

@implementation MyApplication
+ (MyApplication*)sharedInstance {
    static MyApplication *sharedApplication = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedApplication = [[self alloc] init];
    return sharedApplication;

- (id)init {
    self = [super init];
    if (self) {
        _lock = [A0Lock newLock];
    return self;

NOTE: You can create A0Lock in any other class, even in your AppDelegate, the only requirement is that you keep it in a strong reference.

4. Register Native Authentication Handlers

  1. In your AppDelegate method application:didFinishLaunchingWithOptions:, add the following lines:
A0Lock *lock = [[MyApplication sharedInstance] lock];
[lock applicationLaunchedWithOptions:launchOptions];
  1. Add the following import:
#import <Lock/Lock.h>
#import “MyApplication.h"
  1. To allow native logins using other iOS apps (e.g: Twitter, Facebook, Safari etc.), add the following method:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    A0Lock *lock = [[MyApplication sharedInstance] lock];
    return [lock handleURL:url sourceApplication:sourceApplication];

NOTE: If you need Facebook or Twitter native authentication, continue reading to learn how to configure these. Otherwise, skip to Implement the login.


Before continuing to configure either Facebook or Twitter integration, check that you have enabled and correctly configured the social connection with your credentials in the Dashboard.


Lock uses the native Facebook SDK to obtain the user's access token. Use the information from your app that is configured for Facebook connections in the Auth0 dashboard:

  1. Add the following entries to the Info.plist:
Key Value
  1. Register a custom URL Type with the format fb<FacebookAppID>.

NOTE: For more information on how to configure your app for Facebook, see: Facebook Getting Started Guide and Connect your app to Facebook.

Here is an example of how the entries should look:

FB plist

  1. Add the following key to the Info.plist inside the main <dict> key. To open this file in Source Code mode within Xcode, Control-Click (or right click) on it, and select Open As > Source Code.

NOTE: These entries enable compatibility with iOS 9. You can get more information about this on Facebook's developer portal at: Preparing your apps for iOS 9.

  1. Add Lock Facebook's Pod:

pod 'Lock-Facebook', '~> 2.0'

  1. Add to the import:

#import <Lock-Facebook/A0FacebookAuthenticator.h>

  1. Register it after initializing A0Lock:
A0FacebookAuthenticator *facebook = [A0FacebookAuthenticator newAuthenticatorWithDefaultPermissions];
[lock registerAuthenticators:@[facebook]];


  1. Add Lock Twitter's Pod

pod 'Lock-Twitter', '~> 2.0'

  1. Import the Lock-Twitter Class

#import <Lock-Twitter/A0TwitterAuthenticator.h>

  1. Configure Auth0 Twitter Authenticator
NSString *twitterApiKey = ...
A0TwitterAuthenticator *twitter = [A0TwitterAuthenticator newAuthenticationWithConsumerKey:twitterApiKey];

Register the A0TwitterAuthenticator instance with your A0Lock instance if native integration is available. Lock-Twitter does not default to an OAuth flow, so a check should be made to determine if native authentication is available. If it is, the integration can be registered.

A0Lock *lock = ... // Get your instance of A0Lock
if ([A0TwitterAuthenticator canUseNativeTwitterAuthentication]) {
    [lock registerAuthenticators:@[twitter]];

NOTE: For more information on configuring your app for Twitter, see: Connect your app to Twitter.

5. Implement the Login

Now you are ready to implement the Login using Lock. You only need to instantiate and present it from any of your UIViewControllers, like this:

A0Lock *lock = [[MyApplication sharedInstance] lock];
A0LockViewController *controller = [lock newLockViewController];
controller.onAuthenticationBlock = ^(A0UserProfile *profile, A0Token *token) {
    // Do something with token & profile. e.g.: save them.
    // And dismiss the ViewController
    [self dismissViewControllerAnimated:YES completion:nil];
[self presentViewController:controller animated:YES completion:nil];


Login UI Options

There are multiple ways of implementing the login box. What you see above is the Login Widget. You can also Build your own UI, or implement one of the passwordless Login Widgets: SMS or TouchID.

On successful authentication, onAuthenticationBlock will yield the user's profile and tokens.

NOTE: To learn how to save and manage the tokens and profile, see: Lock iOS: Saving and Refreshing JWT Tokens.

6. Showing user information

After the user has logged in, you can use the profile object which contains all the user information:

  self.usernameLabel.text =;
  self.emailLabel.text =;

Additional Information

See User Profile to find out all of the available properties of the user profile.

Also see: A0UserProfile.

You can also download a sample project that shows how to store/update your user profile with Auth0.

Use Auth0 for FREECreate free Account