Finding a user by their identity provider 'external ID'

:bookmark: This guide explains how to find a Discourse user based on their external_id from an identity provider using API calls.

:person_raising_hand: Required user level: Administrator

When using an external authentication system, Discourse keeps track of two user ids: the Discourse user_id, and an external_id from the identity provider. If you need to lookup a Discourse user based on the external_id, this howto article is for you! Below, you’ll learn how to perform this operation.

API Setup

First, ensure you have properly configured an admin API key. For more information on setting up and using the Discourse API, refer to the Discourse API documentation.

DiscourseConnect

If you are using DiscourseConnect (formerly known as Discourse SSO), you can fetch a user with the following API call:

curl https://myforum.example.com/u/by-external/{external-id}.json \
     -H "Api-Key: 714552c6148e1617aeab526d0606184b94a80ec048fc09894ff1a72b740c5f19" \
     -H "Api-Username: discourse1"

Replace {external-id} with the actual external ID of the user you are looking for. If a user is found, its information will be returned. If not, a 404 will be returned

Other Authentication Provider

:information_source: This API is new in Discourse 2.6.0.beta5, make sure you’re up-to-date

This works for all core methods, as well as plugins which use the “ManagedAuthenticator” framework (including discourse-openid-connect and discourse-oauth2-basic)

First, find the ‘provider name’ of your authenticator. This is normally contained in the callback URL (e.g. if the callback url is /auth/oauth2_basic/callback, then the provider name is oauth2_basic).

Then you can fetch a user like this:

curl https://myforum.example.com/u/by-external/{provider}/{external-id}.json \
     -H "Api-Key: 714552c6148e1617aeab526d0606184b94a80ec048fc09894ff1a72b740c5f19" \
     -H "Api-Username: discourse1"

Replace {provider} with the actual provider name and {external-id} with the external ID of the user you are looking for. If a user is found, its information will be returned. If not, a 404 will be returned.

Additional Resources

Last edited by @pedrom 2024-07-05T03:23:24Z

Check documentPerform check on document:
15 Likes