使用AAD身份验证提供程序获取当前登录的用户 [英] Get current logged user with AAD authentication provider
问题描述
我有一个简单的网站,托管在Azure App Services上,在这里我按照建议的
I have a simple website, hosted on Azure App Services, where I enabled AAD authentication following the express setting as recommended here and it is correctly working.
现在,我想在导航栏上显示当前登录用户的用户名/电子邮件.我该怎么办?
Now I would like to show on navigation bar the username / email of current logged in user. How should I do?
应用程序是使用C#Asp.Net Core 1.0.4开发的
App is developed in C# Asp.Net Core 1.0.4
非常感谢您
推荐答案
参考:
以任何语言或框架编写的代码都可以从这些标头中获取所需的信息.对于ASP.NET 4.6应用程序,ClaimsPrincipal将自动设置为适当的值. Code that is written in any language or framework can get the information that it needs from these headers. For ASP.NET 4.6 apps, the ClaimsPrincipal is automatically set with the appropriate values. 您的应用程序还可以通过调用/.auth/me获得有关已验证用户的其他详细信息. Your application can also obtain additional details on the authenticated user by calling /.auth/me. 但是目前看来,ASP.NET Core不支持将身份信息从IIS模块(例如Easy Auth)流向应用程序代码.参见此处讨论. But currently seems ASP.NET Core does not support flowing identity info from an IIS module (like Easy Auth) to the app code . See discussion here . 我目前没有对此进行测试.但是,您始终可以从标题上方获取用户名和令牌信息.如果您希望获得更多用户的声明,则可以向内置端点 I haven't test that in current days . But you can always get user's name , token information from above headers . If you want to get more user's claims , you can make a server-side request to the in-build endpoint 您可以编写自定义中间件来填充.net Core中的User属性: You can write custom middlerware to populate the User property in .net Core : https://stackoverflow.com/a/42270669/5751404 这篇关于使用AAD身份验证提供程序获取当前登录的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
/.auth/me
发出服务器端请求,以检索声明./.auth/me
to retrieve the claims .