# What audiences are needed to link users via access tokens?

**URL:** <https://community.auth0.com/t/what-audiences-are-needed-to-link-users-via-access-tokens/106565>\
**Category:** Get Help\
**Tags:** users, management-api\
**Created:** [May 9, 2023, 9:35pm UTC](https://community.auth0.com/t/what-audiences-are-needed-to-link-users-via-access-tokens/106565 "2023-05-09T21:35:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jennings](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jennings/32/39154_2.png) [@jennings](https://community.auth0.com/u/jennings)\
**Post date:** [May 9, 2023, 9:35pm UTC](https://community.auth0.com/t/what-audiences-are-needed-to-link-users-via-access-tokens/106565/1 "2023-05-09T21:35:29Z")

</div>

The Management API has the option to [link users by providing an access token for each user](https://auth0.com/docs/api/management/v2#!/Users/post_identities). However, it’s not clear to me what audiences and scopes those tokens need.

The documentation says the primary access token needs the `update:current_user_identities` scope, which implies to me that the primary access token must have the Management API as its audience (`https://DOMAIN/api/v2/`), is that right?

Does the audience of the secondary access token matter? Do the scopes?

In our application, the guest signs in with a database connection, then links with a `passwordless` user. The passwordless user should become the **primary** user. This is the workflow I’m trying to implement, but I get back Unauthorized when I try to link accounts:

1. User signs in to our app with a database connection. The audience is our API, `https://example.com`. Our app gets the access token.

2. User is sent back to the authorize endpoint to get an access token for their passwordless user for the Management API: `/authorize?...&login_hint={email}&connection=email&audience=https://DOMAIN/api/v2/&scope=update:current_user_identities`.

3. We retrieve the access token from step 2 and make the following request:

```auto
POST /api/v2/users/PASSWORDLESS_USER_ID/identities
Authorization: Bearer {ACCESS TOKEN FROM STEP 2}
{
  "link_with": "ACCESS TOKEN FROM STEP 1"
}

```

When I make this request, Auth0 responds with 400 Bad Request with message “Invalid token (link\_with).”

I thought maybe I needed a secondary access token with the Management API audience, so I try to do that but get “ **invalid\_request** : The specified redirect\_uri ‘[http://localhost:5173/sign-in/callback](http://localhost:5173/sign-in/callback)’ does not have a registered origin”, which I don’t quite understand because that URI is in my application as an allowed redirect URI.

---

<div class="post-metadata">

**Author:** ![jennings](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jennings/32/39154_2.png) [@jennings](https://community.auth0.com/u/jennings)\
**Post date:** [May 17, 2023, 10:26pm UTC](https://community.auth0.com/t/what-audiences-are-needed-to-link-users-via-access-tokens/106565/2 "2023-05-17T22:26:56Z")

</div>

I ended up opening a support ticket about this, and it turns out the token in the `link_with` property should be the ID token, not an access token.

When passing an access token as the Authorization header and an ID token as the `link_with` property, I can successfully link users together.

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [May 17, 2023, 10:42pm UTC](https://community.auth0.com/t/what-audiences-are-needed-to-link-users-via-access-tokens/106565/3 "2023-05-17T22:42:41Z")

</div>

Hey @jennings glad you were able to get this sorted, and thanks a bunch for sharing the solution with the community! 🙏

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [May 31, 2023, 10:43pm UTC](https://community.auth0.com/t/what-audiences-are-needed-to-link-users-via-access-tokens/106565/4 "2023-05-31T22:43:04Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
