iOS Objective-C: Getting Started

Gravatar for martin.walsh@auth0.com
By Martin Walsh
Auth0

This quickstart guide walks you through managing authentication with Auth0 in your iOS Objective-C apps.

To make the most of all the features in the Auth0.swift toolkit, read the iOS Swift Quickstart first.

Sample Projects

Each tutorial in this guide includes a link to a sample project showing the features described in the article. You can find all the samples in the iOS Objective-C samples folder.

All sample projects use a hybrid project, combining Objective-C and Swift. For more information, read the Mix and Match guide from Apple.

Dependencies

Each tutorial uses the Auth0.swift toolkit. It is a toolkit that lets you efficiently communicate with many of the basic Auth0 API functions.

Create an application

Create a new application in your Auth0 dashboard. For Type, select Native.

Add Auth0 Credentials

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

You need the following information:

  • Client ID
  • Domain

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.

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

<!-- Auth0.plist -->

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>ClientId</key>
  <string>YOUR_CLIENT_ID</string>
  <key>Domain</key>
  <string>YOUR_AUTH0_DOMAIN</string>
</dict>
</plist>

Configure Callback URLs

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

You need to whitelist the callback URL for your app in the Allowed Callback URLs field in your Application Settings. If you do not set any callback URL, your users will see a mismatch error when they log in.

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

<!-- Info.plist -->

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>None</string>
        <key>CFBundleURLName</key>
        <string>auth0</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
        </array>
    </dict>
</array>

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:

{PRODUCT_BUNDLE_IDENTIFIER}://YOUR_AUTH0_DOMAIN/ios/{PRODUCT_BUNDLE_IDENTIFIER}/callback
Use Auth0 for FREECreate free Account