Docs

iOS Objective-C: Linking Accounts

View on Github

iOS Objective-C: Linking Accounts

Gravatar for martin.walsh@auth0.com
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.2.1 | Version 8.3.2 (8E2002) | iPhone 7 - iOS 10.3 (14E269)

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.

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 as described in the Login tutorial.

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

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

Import the Swift wrapper and Auth0 library:

To link accounts:

Retrieve the Linked Accounts

Once you have the id value from the profile.sub, 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.

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