I need to be able to retrieve the current logged-on Azure AD user's email (technically a UPN) from Windows 10 via C#. I can get the following information:
WindowsIdentity currentIdentity = WindowsIdentity.GetCurrent();
string userSid =
currentIdentity.Claims.FirstOrDefault(
u => u.Type == System.Security.Claims.ClaimTypes.PrimarySid).Value;
string username = currentIdentity.Name; // This returns "AzureAD\\TestUser"
But what I really need is the email/UPN as below (test.user@testtenant.onmicrosoft.com):
I've looked through all properties of the currentIdentity
object and can't see it anywhere, is this possible?