We have no issue accessing the external_id from SSO record of the current logged-in user using below approach:
api.getCurrentUser().external_id
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.
# 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}
end
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: