"the provided secondary account does not exist" when attempting to link user accounts

I’m in the process of writing a post login action that links user accounts based on their ids from social providers (loosely based on this). I’m working with another system that has an existing table of verified links between social accounts. As part of this, I’m making a call to the ManagementClient to link two user accounts, but have run into an error message that doesn’t seem to be covered by any of the documentation. I’ve been able to replicate the same situation outside of the action by calling the API link API.

A sanitized example CURL request (generated from the docs) looks like so, when attempting to link an auth0 style user account to an existing Google account:

curl -L 'https://XXX.us.auth0.com/api/v2/users/google-oauth2%7CYYYYYYYY/identities' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer 🔒' \
-d '{"provider":"auth0","user_id":"41"}'

When I make that call, I get the following response:

{
  "statusCode": 400,
  "error": "Bad Request",
  "message": "the provided secondary account does not exist"
}

That particular message - “the provided secondary account does not exist” - doesn’t appear in any docs or search results that I’ve been able to find. I’ve verified that I do indeed have a user with an id of auth0|41 in my tenant.

Now for the weird part: if I remove the quotation marks around the id in the request, like so:

-d '{"provider":"auth0","user_id":41}'

… the request works, and the accounts are successfully linked. It also works if I give it a provider of google-oauth2 and a valid user id that is a string. It only seems to be the auth0 provider that requires the id to be a number.

This strikes me as particularly odd, as I would have thought that all user ids would be treated as strings (especially when coming from other providers that may have GUID/UUID style ids that include dashes or hexadecimal values).

Any idea on what I might be doing wrong here?

With some help from the Auth0 support, we were able to get this sorted out.

Long story short, we were also using a custom database script. The getUser function was grabbing users, with the user_id coming through as an integer. Because of this, when a new user was created in Auth0, the user_id in Auth0 was being set to an integer. (I’m surprised that Auth0 supports either integer or string user ids. I’m sure there’s some valid use case for it, and that also likely explains with the “Link a User Account” documentation mentions that the user_id can be a string or integer).

We modified the getUser function to always cast the user_id to a string, and recreated the particular user I was testing with. Once recreated, it had a string id, and the call to link the accounts worked just fine when specifying quotation marks around the user id.

Hopefully this helps anyone else who runs into this!

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