Azure Function 2.x-获取当前用户的声明 [英] Azure Function 2.x - Get Current User's Claims

查看:71
本文介绍了Azure Function 2.x-获取当前用户的声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an Azure Function 2.x (Asp.net Core) and am authenticating with Azure AD. I'm trying to access the logged-in user's Claims after authentication. Previously using Azure Functions 1.x we would get the Claims using ClaimsPrincipal.Current, as seen in the code below:

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中的声明的任何指南?

Any guidance on how we access Claims in Azure Functions 2.x using .Net Core?

推荐答案

此功能为

This feature is now supported in C# in Azure Functions 2.0. You can now add ClaimsPrincipal as a parameter to your HttpTrigger function's signature, or you can access it on the HttpRequest object via req.HttpContext.User.

对JavaScript的支持应该很快就会出现,最终所有语言都应该支持此功能.

Support should be coming soon to JavaScript, and eventually all languages should support this feature.

这篇关于Azure Function 2.x-获取当前用户的声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆