Build your own UI


This document covers an outdated version of Lock for iOS. We recommend you to upgrade to v2

Sample Project

Download a sample project specific to this tutorial configured with your Auth0 API Keys.

Otherwise, if you already have an existing application, please follow the steps below.

  1. Add the following dependencies to your project using Cocoapods:
pod "Lock/Core", "~> 1.16"
pod "Lock-Facebook", "~> 2.0" #If you need FB native integration
pod "Lock-Twitter", "~> 1.1" #If you need Twitter native integration
  1. Open your app's Info.plist file and add two new entries Auth0ClientId and Auth0Domain with the following values YOUR_CLIENT_ID and YOUR_DOMAIN

  2. Create a new instantiate of A0Lock and store it where is easily accessible:

self.lock = [A0Lock newLock];
self.lock = A0Lock()
  1. When you need to login your user with email/password credentials, just paste the following code
NSString *email = ... // User's email
NSString *password = ... // User's password
A0Lock *lock = ... // Get your Lock instance
A0APIClient *client = [lock apiClient];
A0APIClientAuthenticationSuccess success = ^(A0UserProfile *profile, A0Token *token) {
  NSLog(@"We did it!. Logged in with Auth0.");
A0APIClientError failure = ^(NSError *error){
  NSLog(@"Oops something went wrong: %@", error);
A0AuthParameters *params = [A0AuthParameters newDefaultParams];
params[A0ParameterConnection] = @"Username-Password-Authentication"; // Or your configured DB connection
[client loginWithUsername:email
let email = ... // User's email
let password = ... // User's password
let lock = ... // Get your Lock instance
let client = lock.apiClient()
let parameters = A0AuthParameters(dictionary: [A0ParameterConnection : "Username-Password-Authentication"])
client.login(withUsername: email, password: password, parameters: parameters, success: { profile, token in
    print("We did it!. Logged in with Auth0.")
}, failure: { error in
    print("Oops something went wrong: \(error)")

More details about the parameters you can use check this wiki page.

After that, you may want to save the user's token to be able to use them later, you can find how to do it here.

Social Authentication

  1. In your AppDelegate method named application:didFinishLaunchingWithOptions add the following line:
A0Lock *lock = ... //Get your Lock instance
[lock applicationLaunchedWithOptions:launchOptions];
let lock = ... // Get your Lock instance
lock.applicationLaunched(options: launchOptions)
  1. Also add the following lines to your AppDelegate too
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
  A0Lock *lock = ... //Get your Lock instance
  return [lock handleURL:url sourceApplication:sourceApplication];
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
  let lock = ... // Get your Lock instance
  return lock.handle(url, sourceApplication: sourceApplication)
  1. Configure Facebook Native Integration
A0Lock *lock = ... //Get your Lock instance
A0FacebookAuthenticator *facebook = [A0FacebookAuthenticator newAuthenticatorWithDefaultPermissions];
[lock registerAuthenticators:@[facebook]];
let lock = ... //Get your Lock instance
let facebook = A0FacebookAuthenticator.newAuthenticatorWithDefaultPermissions()

You need to configure your iOS App for Facebook, please check this guide for more information.

  1. Configure Twitter Native Integration
NSString *twitterApiKey = ... //Remember to obfuscate your api key
NSString *twitterApiSecret = ... //Remember to obfuscate your api secret
A0TwitterAuthenticator *twitter = [A0TwitterAuthenticator newAuthenticationWithKey:twitterApiKey andSecret:twitterApiSecret];
A0Lock *lock = ... //Get your Lock instance
[lock registerAuthenticators:@[twitter]];
let twitterApiKey = ... //Remember to obfuscate your api key
let twitterApiSecret = ... //Remember to obfuscate your api key
let twitter = A0TwitterAuthenticator.newAuthenticationWithKey(twitterApiKey, andSecret:twitterApiSecret)
let lock = ... //Get your Lock instance
  1. Authenticate with a social connection
void(^success)(A0UserProfile *, A0Token *) = ^(A0UserProfile *profile, A0Token *token) {
  NSLog(@"We did it!. Logged in with Auth0.");
void(^error)(NSError *) = ^(NSError *error) {
  NSLog(@"Oops something went wrong: %@", error);
A0Lock *lock = ... //Get your Lock instance
[[lock identityProviderAuthenticator] authenticateWithConnectionName:@"facebook" parameters:nil success:success failure:failure];
let success = { (profile: A0UserProfile, token: A0Token) in
  println("We did it!. Logged in with Auth0.")
let failure = { (error: NSError) in
  println("Oops something went wrong: \(error)")
let lock = ... //Get your Lock instance
lock.identityProviderAuthenticator().authenticateWithConnectionName("facebook", parameters: nil, success: success, failure: failure)