【问题标题】:401 Unauthorized when making a POST request to Microsoft Graph Search API using managed identity with Sites.Read.All permission使用具有 Sites.Read.All 权限的托管标识向 Microsoft Graph Search API 发出 POST 请求时出现 401 Unauthorized
【发布时间】:2023-01-24 23:22:25
【问题描述】:

我正在尝试使用从具有 Microsoft Graph API 上的“Sites.Read.All”权限的托管身份获得的令牌向 Microsoft Graph Search API 端点https://graph.microsoft.com/v1.0/search/query 发出 POST 请求。

但是,我收到了 401 Unauthorized 响应。是什么导致了这个问题?

【问题讨论】:

  • 你如何使用令牌?您是否将其作为标头的一部分传递?该标题的关键是什么?
  • 另外,您是否尝试将该令牌粘贴到jwt.ms

标签: sharepoint microsoft-graph-api http-status-code-401 azure-managed-identity


【解决方案1】:

问题出在 Oxymoron 的建议中,不记名令牌中缺少“角色”。解决方案是在请求令牌时将 resource="https://graph.microsoft.com/" 更改为 "https://graph.microsoft.com"(不带斜杠)。

同样显然只有委派权限适用于 v1.0 Graph Search。请求现在看起来像这样:

POST https://graph.microsoft.com/beta/search/query
Content-Type: application/json

{
  "requests": [
    {
      "entityTypes": [
          "listItem"
      ],
       "query": {
        "queryString": "contoso"
      },
      "region": "NAM"
    }
  ]
}

【讨论】:

    猜你喜欢
    • 2014-12-02
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    • 2021-09-07
    • 2022-01-10
    • 2018-07-04
    • 2019-03-04
    相关资源
    最近更新 更多