This multi-step quickstart guide will walk you through managing authentication in your iOS apps with Auth0.
Each tutorial in the series includes a link to its corresponding sample project, which demonstrates how to achieve the tutorial's goal. You can find all the samples here.
A brief description:
- Lock is a widget that is easy to present in your app. It contains default templates (that can be customized) for login with email/password, signup, social providers integration, and password recovery.
- Auth0.swift is a toolkit that lets you communicate efficiently with many of the basic Auth0 API functions.
If you are using Carthage, add the following lines to your
github "auth0/Lock.iOS-OSX" -> 1.26 github "auth0/Auth0.swift" "1.0.0-beta.5"
For more information about Carthage usage, check their official documentation.
If you are using Cocoapods, add these lines to your
use_frameworks! pod 'Lock', '~> 1.26' pod 'Auth0', '1.0.0-beta.5'
For further reference on Cocoapods, check their official documentation.
When you signed up for Auth0, you were invited to create a new client.
There are some details about this client that your application needs to know about to properly communicate with Auth0. These include your Client ID, Domain, and Client Secret. You can retrieve these values from the settings area for your client in the Auth0 dashboard.
Please note that if you download the samples available for this tutorial, these keys will be pre-populated for you. If you have created more than one client in your account, the sample will come with the values for your Default App.
Configure Callback URLs
Callback URLs are the URLs that Auth0 invokes after the authentication process. Auth0 routes your application back to this URL and appends additional parameters to it, including a token. Since callback URLs can be manipulated, you will need to add your application's URL to your client's Allowed Callback URLs for security. This will enable Auth0 to recognize these URLs as valid. If omitted, authentication will not be successful.
That being said, go to your Client's Dashboard and make sure that Allowed Callback URLs contains the following:
The dependencies listed above requires that you set your credentials in two different
.plist files in order for them to work. If you downloaded the seed project, or any sample project from here, these credentials are automatically set. Either way, you have to make sure they are there—otherwise your app might crash.
You can add the following entries in your project's
<key>Auth0ClientId</key> <string>YOUR_CLIENT_ID</string> <key>Auth0Domain</key> <string>YOUR_AUTH0_DOMAIN</string>
Alternatively you can add your credentials in
Auth0.plist. You have to create that file if it doesn't already exist:
<?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>