How to check if a user is linked to an external identity provider?
-
I need to determine whether a user is linked to an external identity provider to change application behavior accordingly. I've checked the user object in the userinfo lambda and the
/api/user/{userId}endpoint, but neither contains information about linked identity providers.When attempting to use the
/api/identity-provider/linkendpoint with just a userId parameter, I receive this error:You must specify the [identityProviderId] property. During a [POST] request this property is not required when using the [pendingIdPLinkId] property to complete the link request.Is there a way to:
- Get a list of all linked identities for a specific user?
- Determine during login that the user authenticated via an external provider?
I'm using FusionAuth 1.69.2 and authenticating with an API key.
-
You can retrieve all identity provider links for a user by sending a GET request to:
/api/identity-provider/link?userId={userId}Important: The parameter name is case-sensitive and must be
userId(with capital "I"), notuserid.The error you're seeing occurs when the parameter is lowercase
useridinstead of the correct camelCaseuserId. Using the correct casing will return a list of all identity provider IDs that the user is currently linked to.Make sure your request looks like:
GET {baseUrl}/api/identity-provider/link?userId=4aa40fcd-0102-4c26-a51c-9a6c5c0c504a Authorization: <your-api-key>This endpoint works with a standard API key and will return the identity provider link information you need to determine if a user is linked to external providers.
-
D dan has marked this topic as solved