Determining the connection name for a signed in user

For a user signed into application A I would like to allow seamless login to application B which is configured with Auth0 as the identity provider for the SAML connection.

In order to avoid prompting the login screen, the connection parameter must be included on the SAML URL. However, I do not see anywhere in the token/user information for application A where the connection name of the signed in user is included.

Would the proper approach here be to use the management API to get the user information for the just signed in user in application A such that the connection name can be retrieved from the identities and used to create the SAML sign in URL?

Am I missing an easier solution?

Hey there @GavinH!

You can add the connection name/id as custom claims to the access and/or ID token with a Post-Login Action. You’ll definitely want to test this in your own environment, but the code might look something like the following:

exports.onExecutePostLogin = async (event, api) => {
  // Check if the connection details are available in the event object
  if (event.connection && event.connection.name && event.connection.id) {
    const connectionName = event.connection.name;
    const connectionId = event.connection.id;

    // Add custom claims to the ID Token
    api.idToken.setCustomClaim("https://example.com/connection_name", connectionName);
    api.idToken.setCustomClaim("https://example.com/connection_id", connectionId);

    // Add custom claims to the Access Token
    api.accessToken.setCustomClaim("https://example.com/connection_name", connectionName);
    api.accessToken.setCustomClaim("https://example.com/connection_id", connectionId);
  }
};

Hope this helps!

1 Like

Thanks @tyf - I was able to successfully add the connection name to the ID token and it ended up as a claim on the server side application.

1 Like

Awesome! Thanks for confirming :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.