且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用Azure身份验证在Azure Function中获取当前用户身份?

更新时间:2023-12-01 09:30:28

使用 Azure Function运行时v2.0.12309 ,您可以检索来自 ClaimsPrincipal 实例通过Run方法注入:

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.
 }