# Determining the connection name for a signed in user

**URL:** <https://community.auth0.com/t/determining-the-connection-name-for-a-signed-in-user/116150>\
**Category:** Get Help\
**Tags:** users, management-api\
**Created:** [September 13, 2023, 9:54pm UTC](https://community.auth0.com/t/determining-the-connection-name-for-a-signed-in-user/116150 "2023-09-13T21:54:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![GavinH](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gavinh/32/48211_2.png) [@GavinH](https://community.auth0.com/u/GavinH)\
**Post date:** [September 13, 2023, 9:54pm UTC](https://community.auth0.com/t/determining-the-connection-name-for-a-signed-in-user/116150/1 "2023-09-13T21:54:13Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [September 13, 2023, 11:52pm UTC](https://community.auth0.com/t/determining-the-connection-name-for-a-signed-in-user/116150/3 "2023-09-13T23:52:02Z")

</div>

Hey there @GavinH!

> [@GavinH](#):
>
> 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.

You can add the connection name/id as custom claims to the access and/or ID token with a [Post-Login Action](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow). You’ll definitely want to test this in your own environment, but the code might look something like the following:

```auto
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!

---

<div class="post-metadata">

**Author:** ![GavinH](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gavinh/32/48211_2.png) [@GavinH](https://community.auth0.com/u/GavinH)\
**Post date:** [September 14, 2023, 7:43pm UTC](https://community.auth0.com/t/determining-the-connection-name-for-a-signed-in-user/116150/4 "2023-09-14T19:43:31Z")

</div>

Thanks @ty.frith - 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.

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [September 14, 2023, 9:23pm UTC](https://community.auth0.com/t/determining-the-connection-name-for-a-signed-in-user/116150/5 "2023-09-14T21:23:23Z")

</div>

Awesome! Thanks for confirming 🙂

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [September 28, 2023, 9:23pm UTC](https://community.auth0.com/t/determining-the-connection-name-for-a-signed-in-user/116150/6 "2023-09-28T21:23:36Z")

</div>

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