Azure Functions / Microsoft Graph绑定未获取令牌(clientCredentials)

时间:2017-11-20 10:24:00

标签: azure azure-active-directory microsoft-graph azure-functions

我正在尝试在Azure Functions上使用新的Microsoft Graph绑定功能,因此我已关注this article(使用clientCredentials):

Azure AD App已经注册良好,但是,在调用Function时,我收到以下错误:

{
    "error": "unauthorized_client",
    "error_description": "AADSTS70001: Application with identifier 'ba8b3444-403f-4472-aba3-0407c563dd28' was not found in the directory microsoft.com\r\nTrace ID: 76a06d59-43a5-4862-9a1e-7864121c2200\r\nCorrelation ID: f511ce93-d6e3-40f2-8427-a3af0b89750d\r\nTimestamp: 2017-11-20 10:11:41Z",
    "error_codes": [70001],
    "timestamp": "2017-11-20 10:11:41Z",
    "trace_id": "76a06d59-43a5-4862-9a1e-7864121c2200",
    "correlation_id": "f511ce93-d6e3-40f2-8427-a3af0b89750d"
}

正如我所说,App ID是正确的,并且已在我的Azure AD目录中注册(具有正确的权限)。为什么在尝试获取令牌时使用microsoft.com目录?!!

这是我的函数c#代码(只返回令牌):

public static async Task<string> Run(HttpRequestMessage req, string graphToken, TraceWriter log)
{
    log.Info("C# HTTP trigger function processed a request.");
    return graphToken;
    //HttpClient client = new HttpClient();
    //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", graphToken);
    //return await client.GetAsync("https://graph.microsoft.com/v1.0/groups");
}

这是我的_function.json`

{
  "bindings": [
    {
      "name": "req",
      "type": "httpTrigger",
      "direction": "in",
      "authLevel": "anonymous",
      "methods": [
        "get"
      ]
    },
    {
      "name": "graphToken",
      "type": "token",
      "direction": "in",
      "resource": "https://graph.microsoft.com",
      "identity": "ClientCredentials"
    },
    {
      "name": "$return",
      "type": "http",
      "direction": "out"
    }
  ],
  "disabled": false
}

1 个答案:

答案 0 :(得分:1)

这是一个已知问题,我们认为这是由使用公共端点而非专用租户的绑定引起的。我不确定为什么公共端点的默认行为是使用Microsoft租户,但我可以通过针对公共端点手动执行流程来重现任何租户中的问题。

我刚刚意识到我们的GitHub仓库没有跟踪该问题,所以我创建了一个新项目:https://github.com/Azure/azure-functions-microsoftgraph-extension/issues/25

修复没有ETA,但团队将继续努力。