# Finding a user by their identity provider 'external ID'

**URL:** https://meta.discourse.org/t/finding-a-user-by-their-identity-provider-external-id/169723
**Category:** Site Management
**Tags:** rest-api, how-to, users
**Created:** [November 10, 2020, 12:19pm UTC](https://meta.discourse.org/t/finding-a-user-by-their-identity-provider-external-id/169723 "2020-11-10T12:19:53Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Discourse](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/discourse/32/148734_2.png) [@Discourse](https://meta.discourse.org/u/Discourse)
#### Post date: [November 10, 2020, 12:19pm UTC](https://meta.discourse.org/t/finding-a-user-by-their-identity-provider-external-id/169723/1 "2020-11-10T12:19:53Z")

</div>

> 🔖 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](https://meta.discourse.org/t/discourse-api-documentation/22706).

## [DiscourseConnect](https://meta.discourse.org/t/13045?silent=true)

If you are using [DiscourseConnect](https://meta.discourse.org/t/13045?silent=true) (formerly known as [Discourse SSO](https://meta.discourse.org/t/13045?silent=true)), you can fetch a user with the following API call:

```plaintext
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 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:

```plaintext
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](https://meta.discourse.org/t/discourse-rest-api-documentation/22706)
- [Get a user by external\_id endpoint](https://docs.discourse.org/#tag/Users/operation/getUserExternalId)
- [Get a user by identity provider external ID endpoint](https://docs.discourse.org/#tag/Users/operation/getUserIdentiyProviderExternalId)

> Last edited by @pedro 2025-07-23T20:13:11Z
> 
> > **Check document**
> >
> > Perform check on document:
