[英]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. 使用QuickWatch窗口我可以使用以下表达式查找给定名称和姓氏。 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]
How about 怎么样
ClaimsPrincipal cp = ClaimsPrincipal.Current;
string welcome = string.Format("Welcome, {0} {1}!", cp.FindFirst(ClaimTypes.GivenName).Value, cp.FindFirst(ClaimTypes.Surname).Value);
This way you can get non standard claims also, you just need to know the name of the key, obtainable for example from the openidconnect YOURDOMAIN/.well-known/openid-configuration JSON response. 通过这种方式,您还可以获得非标准声明,您只需要知道密钥的名称,例如可以从openidconnect YOURDOMAIN / .well-known / openid-configuration JSON响应中获取。
Hello @User.Claims.Single(a => a.Type == " http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname ").Value! Hello @ User.Claims.Single(a => a.Type ==“ http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname ”)。值!
system.security.claims.claimsprincipal.claims API reference system.security.claims.claimsprincipal.claims API参考
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.