Docs

Auth0.swift Saving and Renewing Tokens

When an authentication is performed with the offline_access scope included, it will return a Refresh Token that can be used to request a new user token, without asking for credentials again.

Credentials Manager

Auth0.swift provides a utility class to streamline the process of storing and renewing credentials. You can access the accessToken or idToken properties from the Credentials instance. This is the preferred method to manage user credentials.

First, import the Auth0 module:

Next, present the Login:

Credentials Check

It can be useful to perform a quick sanity check that you have valid credentials stored in the manager. If not the user can then be directed to authenticate.

Retrieving User Credentials

You can retrieve the user's credentials as follows:

Renewing a user's credentials works exactly the same way, if the token has expired. The Credentials Manager will automatically renew the credentials, then store the renewed credentials to the Keychain and finally return them in the closure.

Alternative Method - SimpleKeychain

If you are familiar with Lock v1, you may already be using the SimpleKeychain SDK to handle iOS Keychain read/write access. This section is for developers who would prefer to keep using the SimpleKeychain and not upgrade to the preferred Credentials Manager.

First thing you need to do is store the tokens you need. In this case, you will store the access_token and refresh_token in the Keychain after a successful authentication.

Once you have those stored, you can at any point request a fresh Credentials instance.

Renewing User Credentials