我是 Azure AD 的新手,正在尝试在 Azure Functions 上启用 Azure AD 身份验证。下面是架构。
有 2 个组件:
- 前端 Web 应用程序(Nodejs + Express 应用程序)
- 后端 API(使用 .NET 核心的 Azure Functions)
- 前端应用程序已启用 AD 身份验证。当用户使用 AD 凭据登录时,应用会从 Azure 获取访问 token 、刷新 token 和 ID token 。
- Azure Functions 上也启用了 AD 身份验证。
- 当我们尝试访问 Azure Functions 时,来自 Web 应用的 id_token 将作为 Auth header 中的 Bearer token 传递。
引用:https://learn.microsoft.com/en-us/azure/app-service/tutorial-auth-aad?pivots=platform-linux
问题:
- 启用使用 Express 模式对 Azure Functions 进行身份验证/授权(通过 Azure 门户)时,我无法访问或发布 Azure Functions。如果 EasyAuth 关闭,我可以毫无问题地访问这些功能。
请告诉我这里缺少什么。提前致谢!
以下是来自 LogStream 的异常信息:
Unhandled exception in request pipeline: System.Net.WebException: The remote server returned an error: (400) Bad Request.
2020-11-11T01:28:38.421239842Z: [INFO] at System.Net.HttpWebRequest.GetResponse()
2020-11-11T01:28:38.429941331Z: [INFO] at Microsoft.Azure.AppService.Middleware.OpenIdConnectConfiguration.Download(String url) in /EasyAuth/Microsoft.Azure.AppService.Middleware.Modules/OpenIdConnectConfiguration.cs:line 62
2020-11-11T01:28:38.437673222Z: [INFO] at Microsoft.Azure.AppService.Middleware.OpenIdConnectConfiguration.ConfigManager.RefreshConfiguration() in /EasyAuth/Microsoft.Azure.AppService.Middleware.Modules/OpenIdConnectConfiguration.cs:line 163
2020-11-11T01:28:38.437688622Z: [INFO] at Microsoft.Azure.AppService.Middleware.OpenIdConnectConfiguration.ConfigManager.GetCurrentConfiguration() in /EasyAuth/Microsoft.Azure.AppService.Middleware.Modules/OpenIdConnectConfiguration.cs:line 150
2020-11-11T01:28:38.437693322Z: [INFO] at Microsoft.Azure.AppService.Middleware.AzureActiveDirectoryProvider.GetDefault() in /EasyAuth/Microsoft.Azure.AppService.Middleware.Modules/IdentityProviders/AzureActiveDirectoryProvider.cs:line 808
2020-11-11T01:28:38.437697222Z: [INFO] at Microsoft.Azure.AppService.Middleware.EasyAuthModule.AuthenticateAsync(HttpContextBase context)
2020-11-11T01:28:38.437712122Z: [INFO] at Microsoft.Azure.AppService.Middleware.EasyAuthModule.OnAuthenticateRequestAsync(HttpContextBase context) in /EasyAuth/Microsoft.Azure.AppService.Middleware.Modules/EasyAuthModule.cs:line 243
2020-11-11T01:28:38.437716222Z: [INFO] at Microsoft.Azure.AppService.MiddlewareShim.Startup.OnRequest(HttpContext context) in /EasyAuth/Middleware.Host/Startup.cs:line 124
最佳答案
如果您使用 EasyAuth 来保护您的 Azure 函数,则应使用 access_token
来调用它,而不是 id_token
。如果您还有任何疑问,请告诉我。
关于c# - Azure Functions 中的 Azure AD 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64779575/