我有 Azure Function 2.x (Asp.net Core),并且正在使用 Azure AD 进行身份验证。我正在尝试在身份验证后访问登录用户的声明。以前使用 Azure Functions 1.x 时,我们将使用 ClaimsPrincipal.Current 获取声明,如下面的代码所示:
using System.Net;
using System.Collections.Generic;
using System.Security.Claims;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
public static HttpResponseMessage Run(HttpRequestMessage req, out object document, TraceWriter log)
{
string name = ClaimsPrincipal.Current.FindFirst("name").Value;
log.Info($"name is {name}");
return req.CreateResponse(HttpStatusCode.OK, "Done");
}
有关如何使用 .Net Core 访问 Azure Functions 2.x 中的声明的任何指导吗?
最佳答案
此功能是 now supported在 Azure Functions 2.0 中用 C# 编写。您现在可以将 ClaimsPrincipal
作为参数添加到 HttpTrigger
函数的签名中,也可以通过 req. HttpContext.User
。
对 JavaScript 的支持应该很快就会到来,最终所有语言都应该支持此功能。
关于Azure Function 2.x - 获取当前用户的声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51730988/