Skip to main content

Overview

Swift SDK for iOS, macOS, tvOS, and watchOS that enables you to seamlessly integrate Auth0 into your apps. Add login and logout, store credentials securely, and access user information.See the GitHub repositoryMigrating from v1? Check the Migration Guide

Documentation

Getting started

Requirements

  • iOS 13.0+ / macOS 11.0+ / tvOS 13.0+ / watchOS 7.0+
  • Xcode 14.x
  • Swift 5.7+
Check the Support Policy to learn when dropping Xcode, Swift, and platform versions will not be considered a breaking change.

Installation

Swift Package Manager

Open the following menu item in Xcode: File > Add Packages… In the Search or Enter Package URL search box enter this URL:
Then, select the dependency rule and press Add Package.

Cocoapods

Add the following line to your Podfile:
Then, run pod install.

Carthage

Add the following line to your Cartfile:
Then, run carthage bootstrap --use-xcframeworks.

Configure the SDK

Go to the Auth0 Dashboard and create a new Native application. Auth0.swift needs the  and Domain of the Auth0 application to communicate with Auth0. You can find these details in the Settings page of your Auth0 application. If you are using a custom domain, use the value of your instead of the value from the Settings page.

Configure Client ID and Domain with a plist

Create a plist file named Auth0.plist in your app bundle with the following content:

Configure Client ID and Domain programmatically

For Web Auth
For the Authentication API client
For the Management API client (Users)

Configure Web Auth (iOS / macOS)

Configure callback URL and logout URL

The callback URL and logout URL are the URLs that Auth0 invokes to redirect back to your application. Auth0 invokes the callback URL after authenticating the user, and the logout URL after removing the . Since the callback URL and logout URL can be manipulated, you will need to add your URLs to the Allowed Callback URLs and Allowed Logout URLs fields in the Settings page of your Auth0 application. This will enable Auth0 to recognize these URLs as valid. If the callback URL and logout URL are not set, users will be unable to log in and out of the application and will get an error. Go to the Settings page of your Auth0 application and add the corresponding URL to Allowed Callback URLs and Allowed Logout URLs, according to the platform of your application. If you are using a custom domain, replace {yourAuth0Domain} with the value of your custom domain instead of the value from the Settings page.
iOS
macOS
For example, if your iOS bundle identifier was com.example.MyApp and your Auth0 Domain was example.us.auth0.com, then this value would be:
Make sure that the Token Endpoint Authentication Method setting is set to None.

Configure custom URL scheme

In Xcode, go to the Info tab of your app target settings. In the URL Types section, click the  button to add a new entry. There, enter auth0 into the Identifier field and $(PRODUCT_BUNDLE_IDENTIFIER) into the URL Schemes field. This registers your bundle identifier as a custom URL scheme, so the callback URL and logout URL can reach your app.

Web Auth login (iOS / macOS)

Import the Auth0 module in the file where you want to present the login page.
Then, present the Universal Login page in the action of your Login button.

Using async/await

Using Combine

Web Auth logout (iOS / macOS)

Logging the user out involves clearing the session cookie and then deleting the user’s credentials from your application. Call the clearSession() method in the action of your Logout button. Once the session cookie has been cleared, delete the user’s credentials.

Using async/await

Using Combine

SSO alert box (iOS / macOS)

undefined
Check the FAQ for more information about the alert box that pops up by default when using Web Auth.

Next steps

Learn about most features in Examples: