Published on

Finding out which provider a user logged in with

Authors

We added a new custom authentication provider (saml2) and needed to customize our logout url based on what someone logged in with.

Credit to Velizar Bishurov for the answer

public static class Util
{
public static string GetIdentityProvider()
{
var identity = ClaimsManager.GetCurrentIdentity();
var idToken = identity.Claims.FirstOrDefault(c => c.Type == "id_token");
if (idToken != null)
{
var handler = new JwtSecurityTokenHandler();
var jwtToken = handler.ReadToken(idToken.Value) as JwtSecurityToken;
if (jwtToken != null)
{
var idpClaim = jwtToken.Claims.FirstOrDefault(c => c.Type == "idp");
if (idpClaim != null)
{
return idpClaim.Value;
}
}
}
return "Unknown";
}
}
view raw GetIdp.cs hosted with ❤ by GitHub

Boost your online presence.

Let us create the perfect digital experience for your company.

Contact us now