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

标签 azure asp.net-core azure-functions claims-based-identity

我有 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/

相关文章:

azure - 操作返回无效状态代码 'NotFound' DotNet Core

windows - PowerShell 将 AD objectGUID 复制到 ms-ds-consistencyguid

asp.net-core - ASP.NET CORE MVC 可以托管在 Xamarin App(Android) 中吗?

docker - 在Windows 7中的Docker上运行ASP.NET Core WebApp时出错(调试)

reactjs - 如何从 Visual Studio 2017 将 React 客户端部署到 Azure

node.js - 将范围添加到 OpenID Connect 身份提供程序(Azure AD 租户)后,新范围不会在 idp access_token 中返回

c# - Asp.Net Core 允许 CORS 中的 IP 范围

python - 导入 azure.search.documents 时,Azure 函数未部署(时间触发器)

visual-studio - 从 Visual Studio 部署 Azure Function Slot 部署生产

Azure Function ExecutionContext.InitationId 与 FunctionFilterContext.FunctionInstanceId