我创建了一个新的函数应用,为它启用了应用服务身份验证/授权(使用身份验证/授权来保护您的应用程序并使用每个用户的数据")并禁用非身份验证请求.
I have created a new Function App, enabled App Service Authentication / Authorization for it ("Use Authentication / Authorization to protect your application and work with per-user data") and disabled non-authenticated requests.
到目前为止,一切似乎都运行正常.如果我尝试请求我的 HttpTriggered 函数,它需要我先登录;登录后,所有请求都会按原样处理.所以保护您的应用程序"部分没有问题.
Everything seems to be working correctly so far. If I try to request my HttpTriggered function, it requires me to log in first; once I'm logged in, all requests are processed as they should be. So there is no problem with "protect your application" part.
但是,我完全被处理每个用户的数据"部分所困扰.我的 Azure 函数被调用为
However, I'm totally stuck with the "work with per-user data" part. My Azure Function is invoked as
public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)]HttpRequestMessage req, TraceWriter log)
HttpRequestMessage 中没有与身份验证相关的内容.(AuthorizationLevel.Anonymous 似乎控制着完全不同的事情——即,函数是否可以由任何人调用,或者只能由具有固定 API 密钥的人调用).
And there is nothing related to authentication in HttpRequestMessage. (AuthorizationLevel.Anonymous seems to control the entirely different thing - namely, if the function could be called by anyone or only by those who have a fixed API key).
如何获取调用该函数的经过身份验证的用户的身份?
How do I get the identity of authenticated user who called the function?
使用 Azure Function runtime v2.0.12309,你可以检索 来自 Run 方法中注入的 "noreferrer">ClaimsPrincipal 实例:
Using the Azure Function runtime v2.0.12309, you can retrieve the authenticated user information from the ClaimsPrincipal instance injected in the Run method:
public static async Task<HttpResponseMessage> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)]
HttpRequest httpRequest,
ILogger logger,
ClaimsPrincipal claimsPrincipal)
{
// Explores the authenticated user's claims in claimsPrincipal.
}
这篇关于如何使用 Azure 身份验证在 Azure Function 中获取当前用户身份?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
ASP.NET Core 使用 Azure Active Directory 进行身份验证并ASP.NET Core authenticating with Azure Active Directory and persisting custom Claims across requests(ASP.NET Core 使用 Azure Active Directory 进行身
ASP.NET Core 2.0 Web API Azure Ad v2 令牌授权不起作用ASP.NET Core 2.0 Web API Azure Ad v2 Token Authorization not working(ASP.NET Core 2.0 Web API Azure Ad v2 令牌授权不起作用)
ASP Core Azure Active Directory 登录使用角色ASP Core Azure Active Directory Login use roles(ASP Core Azure Active Directory 登录使用角色)
如何获取守护进程或服务器到 C# ASP.NET Web API 的How do I get Azure AD OAuth2 Access Token and Refresh token for Daemon or Server to C# ASP.NET Web API(如何获取守护进程或服务器到 C# ASP.N
.Net Core 2.0 - 获取 AAD 访问令牌以与 Microsoft Graph.Net Core 2.0 - Get AAD access token to use with Microsoft Graph(.Net Core 2.0 - 获取 AAD 访问令牌以与 Microsoft Graph 一起使用)
异步调用时 Azure KeyVault Active Directory AcquireTokenAAzure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(异步调用时 Azure KeyVault Active Directory AcquireTokenAsync 超