- Published on
Finding out which provider a user logged in with
- Authors
- Name
- Steve McNiven
- @stevemcniven
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | |
} | |
} |