iOS Swift: Linking Accounts

View on Github

iOS Swift: Linking Accounts

Gravatar for
By Martin Walsh

This tutorial will show you how to link multiple accounts within the same user. We recommend you to Log in to follow this quickstart with examples configured for your account.

I want to explore a sample app

2 minutes

Get a sample configured with your account settings or check it out on Github.

View on Github
System requirements: CocoaPods 1.6 (Beta) | Xcode 10.1 | iOS 9+

Install the Deploy CLI tool

Before You Start

Before you continue with this tutorial, make sure that you have completed the previous tutorials. This tutorial assumes that:

  • You have integrated Auth0.swift as a dependency in your project.
  • You are familiar with presenting the login screen. To learn more, see the Login and the User Sessions tutorials.

We recommend that you read the Linking Accounts documentation to understand the process of linking accounts.

Install the the Deploy CLI tool using the Dashboard

Enter Account Credentials

Your users may want to link their other accounts to the account they are logged in to.

To achieve this, present an additional login dialog where your users can enter the credentials for any additional account. You can present this dialog in the way described in the Login tutorial.

After the user authenticates, save the idToken value for the secondary account.

Install the the Deploy CLI tool using the command-line interface

Now, you can link the accounts. To do this, you need the following values:

  • id: the logged-in user's ID (see profile.sub)
  • idToken: the ID Token for the saved account the user initially logged in to
  • otherUserToken: the ID Token for the second account received in the last login response

Install the the Deploy CLI tool manually

Retrieve the Linked Accounts

Once you have the sub value from the profile, you can retrieve user identities. Call the management API:

A linked account is handled as an Identity instance. Read more about this object in the Identity class documentation.

Scopes required

To unlink the accounts, you need to specify the following:

  • id: the logged-in user's ID (see profile.sub)
  • userId and provider: the values in the identity object you want to unlink

Unlink the accounts:

Use Auth0 for FREE