我已按照本文 https://blogs.msdn.microsoft.com/stuartleeks/2018/02/19/azure-functions-and-app-service-authentication/ 中描述的方式设置了我的 Azure Functions 2
我可以使用 Google token 调用/.auth/login/google 端点并取回简单例份验证 token 。
我可以调用/.auth/me 端点并获取我的个人资料信息。
但在我的代码中,Thread.CurrentPrincipal.Identity 为 null。我似乎找不到任何解决方案。我已验证我的请求已将 x-zumo-auth header 设置为从登录端点检索的简单例份验证 token 。当然,该函数设置为匿名。
我希望我错过了一些简单的事情。感谢您的帮助。
最佳答案
自 2018 年 11 月 28 日起,此功能现已提供预览版。此功能仅适用于 Functions 2.x 运行时。目前它也仅适用于 .NET 语言。
The ClaimsPrincipal is available as part of the request context as shown in the following example:
using System.Net; using Microsoft.AspNetCore.Mvc; using System.Security.Claims; public static IActionResult Run(HttpRequest req, ILogger log) { ClaimsPrincipal identities = req.HttpContext.User; // ... return new OkResult(); }
Alternatively, the ClaimsPrincipal can simply be included as an additional parameter in the function signature:
using System.Net; using Microsoft.AspNetCore.Mvc; using System.Security.Claims; using Newtonsoft.Json.Linq; public static void Run(JObject input, ClaimsPrincipal principal, ILogger log) { // ... return; }
关于Azure Functions v2 和 Google Auth,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53364729/