Azure Functions v2 和 Google Auth

标签 azure azure-functions

我已按照本文 https://blogs.msdn.microsoft.com/stuartleeks/2018/02/19/azure-functions-and-app-service-authentication/ 中描述的方式设置了我的 Azure Functions 2

我可以使用 Google token 调用/.auth/login/google 端点并取回简单例份验证 token 。

我可以调用/.auth/me 端点并获取我的个人资料信息。

但在我的代码中,Thread.CurrentPrincipal.Identity 为 null。我似乎找不到任何解决方案。我已验证我的请求已将 x-zumo-auth header 设置为从登录端点检索的简单例份验证 token 。当然,该函数设置为匿名。

我希望我错过了一些简单的事情。感谢您的帮助。

最佳答案

自 2018 年 11 月 28 日起,此功能现已提供预览版。此功能仅适用于 Functions 2.x 运行时。目前它也仅适用于 .NET 语言。

The ClaimsPrincipal is available as part of the request context as shown in the following example:

using System.Net; 
using Microsoft.AspNetCore.Mvc; 
using System.Security.Claims;

public static IActionResult Run(HttpRequest req, ILogger log)
{
    ClaimsPrincipal identities = req.HttpContext.User;
    // ...
    return new OkResult();
}

Alternatively, the ClaimsPrincipal can simply be included as an additional parameter in the function signature:

using System.Net;
using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;
using Newtonsoft.Json.Linq;

public static void Run(JObject input, ClaimsPrincipal principal, ILogger log)
{
    // ...
    return;
}

引用:https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-http-webhook#working-with-client-identities

关于Azure Functions v2 和 Google Auth,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53364729/

相关文章:

azure - 我可以将单个 Azure AD B2C 租户用于 Django 应用程序的 DEV、STAGE 和 PROD 环境吗?

c# - 'Microsoft.Azure.Devices.Client'中的ReceiveAsync方法是否消耗互联网?

asp.net - 本地作品。 Azure 给出错误 : Invalid object name 'dbo.AspNetUsers' . 为什么?

javascript - Azure 函数与 NodeJS : retrieve id generated by documentDB after a POST request

azure - 如何从 Azure API 管理服务将消息记录到 Azure 事件中心

Azure Functions V2 每次发布前都必须停止函数,因为 dll 正忙

azure - 如何安排 Azure 应用服务仅在工作时间运行(计费)

entity-framework - 带有 Entity Framework 的 Azure 函数

c# - 从逻辑应用调用 Azurefunction 会抛出 "Runtime keys are stored on blob storage. This API doesn' t 支持此配置。”

c# - 炼金术网络套接字 : Can't host server on Azure