Azure Function 2.x-获取当前用户的声明

des*_*lan 5 azure claims-based-identity asp.net-core azure-functions

我有一个Azure Function 2.x(Asp.net Core),并且正在使用Azure AD进行身份验证。我正在尝试在身份验证后访问登录用户的声明。以前使用Azure Functions 1.x,我们将使用ClaimsPrincipal.Current来获得Claims ,如以下代码所示:

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");
}   
Run Code Online (Sandbox Code Playgroud)

关于如何使用.Net Core访问Azure Functions 2.x中的Claims的任何指南?

Con*_*hon 7

Azure Functions 2.0 中的 C#现在支持此功能。您现在可以ClaimsPrincipal作为参数添加到您的HttpTrigger函数签名中,或者您可以HttpRequest通过req.HttpContext.User.

应该很快就会支持 JavaScript,最终所有语言都应该支持这个功能。

  • @desflan,这是我们目前正在添加的功能。不幸的是,它目前不可用,但期待在不久的将来。 (2认同)