Find a user by their identity provider 'external ID'

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!

First, take a look at the Discourse API Documentation, and configure an admin API key.

DiscourseConnect (formerly ‘Discourse SSO’)

If you are using “DiscourseConnect”, fetch a user like this:

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

(API documentation)

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"

(API documentation)

If a user is found, its information will be returned. If not, a 404 will be returned.

15 Likes