Note
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:
https://github.com/auth0/Auth0.swift
Then, select the dependency rule and press Add Package.
Cocoapods
Add the following line to your Podfile:
pod 'Auth0', '~> 2.4'
Then, run pod install.
Carthage
Add the following line to your Cartfile:
github "auth0/Auth0.swift" ~> 2.4
Then, run carthage bootstrap --use-xcframeworks.
Configure the SDK
Head to the Auth0 Dashboard and create a new Native application.
Auth0.swift needs the Client ID 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 have a custom domain, use your custom domain 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:
The callback and logout URLs are the URLs that Auth0 invokes to redirect back to your app. Auth0 invokes the callback URL after authenticating the user, and the logout URL after removing the session cookie.
Since callback and logout URLs 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 and logout URLs are not set, users will be unable to log in and out of the app 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 app. If you have a custom domain, replace YOUR_AUTH0_DOMAIN with your custom domain instead of the value from the settings page.
Note
Make sure that the Token Endpoint Authentication Methodsetting is set to None.
Configure custom URL scheme
Back 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 and logout URLs can reach your app.
Web Auth login (iOS / macOS)
Import the Auth0 module in the file where you want to present the login page.
import Auth0
Then, present the Universal Login page in the action of your Login button.
Auth0
.webAuth()
.start { result in
switch result {
case .success(let credentials):
print("Obtained credentials: \(credentials)")
case .failure(let error):
print("Failed with: \(error)")
}
}
Using async/await
do {
let credentials = try await Auth0.webAuth().start()
print("Obtained credentials: \(credentials)")
} catch {
print("Failed with: \(error)")
}
Using Combine
Auth0
.webAuth()
.start()
.sink(receiveCompletion: { completion in
if case .failure(let error) = completion {
print("Failed with: \(error)")
}
}, receiveValue: { credentials in
print("Obtained credentials: \(credentials)")
})
.store(in: &cancellables)
Web Auth logout (iOS / macOS)
Logging the user out involves clearing the Universal Login session cookie and then deleting the user’s credentials from your app.
Call the clearSession() method in the action of your Logout button. Once the session cookie has been cleared, delete the user’s credentials.
Auth0
.webAuth()
.clearSession { result in
switch result {
case .success:
print("Session cookie cleared")
// Delete credentials
case .failure(let error):
print("Failed with: \(error)")
}
}
This Policy defines the extent of the support for Xcode, Swift, and platform (iOS, macOS, tvOS, and watchOS) versions in Auth0.swift.
Xcode
The only supported versions of Xcode are those that can be currently used to submit apps to the App Store. Once a Xcode version becomes unsupported, dropping it from Auth0.swift will not be considered a breaking change, and will be done in a minor release.
Swift
The minimum supported Swift minor version is the one released with the oldest-supported Xcode version. Once a Swift minor becomes unsupported, dropping it from Auth0.swift will not be considered a breaking change, and will be done in a minor release.
Platforms
Only the last 4 major platform versions are supported, starting from:
iOS 12
macOS 10.15
macCatalyst 13
tvOS 12
watchOS 6.2
Once a platform version becomes unsupported, dropping it from Auth0.swift will not be considered a breaking change, and will be done in a minor release. For example, iOS 13 will cease to be supported when iOS 17 gets released, and Auth0.swift will be able to drop it in a minor release.
In the case of macOS, the yearly named releases are considered a major platform version for the purposes of this Policy, regardless of the actual version numbers.
Feedback
Contributing
We appreciate feedback and contribution to this repo! Before you get started, please see the following:
Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.
Auth0 is an easy to implement, adaptable authentication and authorization platform. To learn more checkout Why Auth0?
This project is licensed under the MIT license. See the LICENSE file for more info.
📚 Documentation • 🚀 Getting Started • 📃 Support Policy • 💬 Feedback
Migrating from v1? Check the Migration Guide.
Documentation
Getting Started
Requirements
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
Head to the Auth0 Dashboard and create a new Native application.
Auth0.swift needs the Client ID 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 have a custom domain, use your custom domain instead of the value from the settings page.
Configure Client ID and Domain with a plist
Create a
plist
file namedAuth0.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 and logout URLs
The callback and logout URLs are the URLs that Auth0 invokes to redirect back to your app. Auth0 invokes the callback URL after authenticating the user, and the logout URL after removing the session cookie.
Since callback and logout URLs 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 and logout URLs are not set, users will be unable to log in and out of the app 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 app. If you have a custom domain, replace
YOUR_AUTH0_DOMAIN
with 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 wasexample.us.auth0.com
, then this value would be:Configure custom URL scheme
Back 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 and logout URLs 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 Universal Login session cookie and then deleting the user’s credentials from your app.
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)
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 ↗
/userinfo
endpoint.Support Policy
This Policy defines the extent of the support for Xcode, Swift, and platform (iOS, macOS, tvOS, and watchOS) versions in Auth0.swift.
Xcode
The only supported versions of Xcode are those that can be currently used to submit apps to the App Store. Once a Xcode version becomes unsupported, dropping it from Auth0.swift will not be considered a breaking change, and will be done in a minor release.
Swift
The minimum supported Swift minor version is the one released with the oldest-supported Xcode version. Once a Swift minor becomes unsupported, dropping it from Auth0.swift will not be considered a breaking change, and will be done in a minor release.
Platforms
Only the last 4 major platform versions are supported, starting from:
Once a platform version becomes unsupported, dropping it from Auth0.swift will not be considered a breaking change, and will be done in a minor release. For example, iOS 13 will cease to be supported when iOS 17 gets released, and Auth0.swift will be able to drop it in a minor release.
In the case of macOS, the yearly named releases are considered a major platform version for the purposes of this Policy, regardless of the actual version numbers.
Feedback
Contributing
We appreciate feedback and contribution to this repo! Before you get started, please see the following:
Raise an issue
To provide feedback or report a bug, please raise an issue on our issue tracker.
Vulnerability reporting
Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.
Auth0 is an easy to implement, adaptable authentication and authorization platform. To learn more checkout Why Auth0?
This project is licensed under the MIT license. See the LICENSE file for more info.