azure - 从 Azure Active Directory 进行身份验证时获取用户信息

标签 azure authentication azure-web-app-service azure-active-directory

我有一个为测试身份验证/授权场景而开发的 Web 表单应用程序。在创建测试项目时,我选择了“无身份验证”,这创建了我的项目,没有身份验证机制代码。我将网站发布到我的 azure 租户,并从功能下的“身份验证/授权”启用了 Azure Active Directory 身份验证。我创建了一个指向我的 Web 应用程序的 Azure AD 应用程序。点击默认页面后,应用程序现在可以进行身份​​验证,一切似乎都工作正常。

但是,当我在 Visual Studio 中本地运行应用程序时,我无法获取用户信息,因为没有可用的适当 header ,例如 X-MS-CLIENT-PRINCIPAL-NAME。我的下一步是调用图形 API 来获取详细的用户信息。

注意:我可以在我的 Web 项目中包含 OWIN 代码来对用户进行身份验证,但我希望对现有的本地 Windows 身份验证应用程序进行最少的代码更改。

任何帮助/指导

最佳答案

However, when I run the app locally from within Visual Studio, I am not able to get the user information as there are no appropriate headers available, eg X-MS-CLIENT-PRINCIPAL-NAME. My next step was to call the graph API to get the detailed user information.

这是预期的。 X-MS-CLIENT-PRINCIPAL-NAME header (及相关 header )由在应用服务中运行的身份验证/授权模块添加。当您从 Visual Studio 本地运行时,您将不会有此模块,因此不会有此请求 header 。

如果您想在本地和应用服务中使用相同的代码,我建议使用 .NET API 来显示用户信息,而不是查看请求 header ,例如 ClaimsPrincipal.Current.Identity.Name 。无论您是在本地使用 Windows 身份验证还是在 Azure 应用服务中使用身份验证/授权,都应正确填充此值。

您可以在此处找到有关身份验证/授权底层机制的更多信息:https://cgillum.tech/2016/02/01/architecture-of-azure-app-service-authentication-authorization/ .

关于azure - 从 Azure Active Directory 进行身份验证时获取用户信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38627539/

相关文章:

c# - Azure 应用服务容器上的 ASP.net core docker https

java - Azure 移动服务异步任务

authentication - JWT 使用数据库处理过期

c# - 在 Azure Web 应用设置中使用数组

azure - Azure Application Insights 与 Google 搜索之间的 IP 地址不匹配

authentication - Symfony 2 注销 (UserInterface::eraseCredentials)

json - DevOps Pipeline 在将变量值作为 JSON 正文发送以使用 Terraform 部署 Azure 资源时更改时间格式

Azure多个VM连接到同一个HD?

c# - 无法使用异步 DocumentDB 操作 CreateDocumentAsync 的结果

node.js - Angular 2 正确使用身份验证服务