Auth0 Home Blog Docs

Which access token to use when linking user accounts?

Hey, fairly new to Auth0 and am using it for a client project. We’re trying to implement account linking, and I’m working on a client-side implementation using Auth0.js. I’m getting my management access token like so:

      this.auth.checkSession(
        {
          audience: `https://YOUR_DOMAIN/api/v2/`,
          scope: "read:current_user"
        },
        (err: any, result: any) => {
          const management = new auth0.Management({
            domain: process.env.VUE_APP_AUTH0_DOMAIN,
            accessToken: result.accessToken
          })
          ...
        }
      )

I gather this is the point where I need to call linkUser, but from which account should I obtain the management access token? I.e. do I:

  1. Log into the primary account.
  2. Get the management access token.
  3. Cache the current ID and access tokens in local storage.
  4. Reauthorize with the new connection.
  5. In my callback handler, check for the existence of a previous ID/access token. If they exist, request the management token and link the previous account ID with the current ID token.

Or:

  1. Log into the primary account.
  2. Cache the current ID and access tokens in local storage.
  3. Reauthorize with the new connection.
  4. Get the management access token.
  5. In my callback handler, check for the existence of a previous ID/access token. If they exist, request the management token and link the previous account ID.

I.e. Assuming I have the process correct, do I get the access token I use for the link in step 2 or 4?

Thanks.