Is there a way we can access the external_id from SSO record of another user?

We have no issue accessing the external_id from SSO record of the current logged-in user using below approach:


However, we have some buttons/links when the current logged-in user is viewing another one’s profile summary (e.g., Person X). This external_id is the primary identifier used in our website which we will be using for some redirects and actions from our website. Using the admin user API works but obviously not for non-admin user accounts.

Is this possible and how?

I think you want a plugin that adds the external_id to the user serializer.

Something like:

  add_to_serializer(:user, :external_id) do

I think it would be something like:

# in the plugin's after_initialize block
after_initialize do

# Edit: probably also check to make sure that `SiteSetting.enable_discourse_connect` returns `true`
  add_to_serializer(:user, :external_id) {object&.single_sign_on_record&.external_id}

The external_id is a property of the single_sign_on_record not the user. I remember this because I had something to do with:


Thanks everyone for the inputs, we ended up doing this via custom user fields which gets synced from our application during login.

1 Like