This guide demonstrates how to add authentication and gain access to user profile information in any iOS / macOS app using the Auth0.swift SDK.
To use this quickstart, you’ll need to:
To use Auth0 services, you’ll need to have an application set up in the Auth0 Dashboard. The Auth0 application is where you will configure how you want authentication to work for the app you are developing.
Use the interactive selector to create a new Auth0 application or select an existing application that represents the iOS or macOS app you want to integrate with. Every application in Auth0 is assigned an alphanumeric, unique Client ID that your app will use to call Auth0 APIs through the SDK.
Any settings you configure using this quickstart will automatically update for your Auth0 application in the Dashboard, which is where you can manage your applications in the future.
If you would rather explore a complete configuration, you can view a sample app instead.
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. 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.
Add the corresponding URL to Callback URLs and Logout URLs, according to the platform of your app. If you are using a custom domain, use the value of your custom domain instead of your Auth0 tenant's domain.
For example, if your iOS bundle identifier was
com.company.myapp and your Auth0 tenant's domain was
company.us.auth0.com, then this value would be:
You need to register your bundle identifer as a custom URL scheme so the callback and logout URLs can reach your app.
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.
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..
Add the following line to your
pod 'Auth0', '~> 2.0'
Add the following line to your
github "auth0/Auth0.swift" ~> 2.0
carthage bootstrap --use-xcframeworks.
The Auth0.swift SDK needs to be configured with your Auth0 Domain and Client ID. You can find these values in the settings page of your Auth0 application.
plist file named
Auth0.plist in your app bundle containing the Auth0 Domain and Client ID values.
The Auth0.swift SDK should now be properly configured. Run your app to verify that it is not producing any errors related to the SDK.
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.
Press the Login button and verify that:
Now that you can log in to your app, you need a way to log out. In the action of your Logout button, call the
clearSession() method to clear the Universal Login session cookie.
Press the Logout button and verify that:
Credentials instance you obtained after logging in includes an ID token. The ID token contains the profile information associated with the logged-in user, such as their name or profile picture. You can use these details to personalize the user interface of your app.
The Auth0.swift SDK includes a utility for decoding JWTs like the ID token. Start by importing the
JWTDecode module in the file where you want to access the user profile information. Then, use the
decode(jwt:) method to decode the ID token and access the claims it contains.
Verify that you can access the
picture, or any other claim after you have logged in.
Excellent work! If you made it this far, you should now have login, logout, and user profile information running in your application.
This concludes our quickstart tutorial, but there is so much more to explore. To learn more about what you can do with Auth0, check out:
Did it work?
Any suggestion or typo?Edit on GitHub
Sign up for an or to your existing account to integrate directly with your own tenant.