Get User Information on Azure ADFS Integration with Claims Identity

In my previous article, I have explained about Integrating Azure ADFS to an existing Asp.Net Webforms application.

In this article, I have explained how to get user information, like name, email, etc after implementing SSO with Azure ADFS.

Once the user successfully logged in with the Single Sign-On of his organisational account, the application redirects to the default page. In this page, on page load place the following code.

string currentUser = string.Empty;
var Identity = (ClaimsIdentity)Thread.CurrentPrincipal.Identity;
if (Identity.IsAuthenticated)
{
     foreach (System.Security.Claims.Claim claim in Identity.Claims)
     {
         if (claim.Type.Contains("name"))
         {
              currentUser = claim.Value;
         }
     }
}

In the above code, if the name parameter is mapped with email or organisational ID, it will return the value. Refer to your LDAP to get the detailed parameter definition.