This guide explains how to find a Discourse user based on their
external_id
from an identity provider using API calls.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
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
- Discourse REST API Documentation
- Get a user by external_id endpoint
- Get a user by identity provider external ID endpoint
Last edited by @pedrom 2024-07-05T03:23:24Z
Check document
Perform check on document: