Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC Get givenname and surname of Azure Active Directory authenticated user

I'm able to obtain the user name (email format) of the authenticated user using:

var autenticateduser = HttpContext.User.Identity.Name;

Using QuickWatch window I am able to find the givenname and surname using the following expression. Is there a more clean way to obtain this info?

(new System.Linq.SystemCore_EnumerableDebugView<System.Security.Claims.Claim>(((System.Security.Claims.ClaimsIdentity)(HttpContext.User.Identity)).Claims)).Items[5]

like image 224
iamnicoj Avatar asked Nov 18 '15 02:11

iamnicoj


1 Answers

How about

ClaimsPrincipal cp = ClaimsPrincipal.Current;
string welcome = string.Format("Welcome, {0} {1}!", cp.FindFirst(ClaimTypes.GivenName).Value, cp.FindFirst(ClaimTypes.Surname).Value);
like image 118
vibronet Avatar answered Sep 28 '22 02:09

vibronet