【问题标题】:Microsoft graph API: unauthorized error when used with sharepoint and token attachedMicrosoft 图形 API:与附加的共享点和令牌一起使用时出现未经授权的错误
【发布时间】:2019-01-07 07:13:14
【问题描述】:

我正在开发一个 Sharepoint 应用程序。对于我的应用程序,我必须使用 Microsoft 图形端点从 Azure AD 获取我的详细信息。我使用/token 端点和client_credentials 授权类型生成了访问令牌。当我将响应中收到的令牌与图形 /users 端点一起使用时,我收到一个未经授权的错误,如下图所示:

在 Azure 门户上,所有权限都授予 microsoft graph API。是否缺少任何配置?我该如何解决这个未经授权的错误?

【问题讨论】:

标签: azure azure-active-directory sharepoint-2013 microsoft-graph-api


【解决方案1】:

没有测试过v2.0的endpoint,如果可以使用v1.0的endpoint可以参考一下步骤。

1.导航到门户中的Azure Active Directory -> App registrations -> New application registration,更多详细信息请参见link

2.进入AD App -> Keys -> 为AD App生成key,复制key值。

3.然后转到Required permissions -> Add -> 在APPLICATION PERMISSIONS 中选择Microsoft GraphRead all users' full profiles -> Save注意 然后不要'不要忘记点击Grant permissions 按钮。

4.我在邮递员中测试,具体我们需要什么来获取access_tokenclient_id是AD App的Application IDclient_secret是你复制的key vaulegrant_typeclient_credentialsresourcehttps://graph.microsoft.com/

示例:

POST https://login.microsoftonline.com/<Tenant ID>/oauth2/token?api-version=1.0

5.使用access_token调用MS Graph API,在我的示例中,我调用List users api,它工作正常。

【讨论】:

  • 我试过上面的过程,但是错误还是一样
  • @DishaAgrawal 在jwt.io 中解码你的令牌,然后给我结果截图。
  • @DishaAgrawal 顺便问一下,你确定你成功Grant permissions了吗?它需要全局管理员帐户的同意。
  • 我的请求正文和相应的 URL 有错误。您的回答很接近但不准确
【解决方案2】:

我认为您在令牌中缺少使用“用户”端点的正确范围。 可能的范围是:

  • User.ReadBasic.All
  • User.Read
  • User.ReadWrite
  • User.Read.All
  • User.ReadWrite.All

更多详情请看here

【讨论】:

  • 你在问题​​中看到On azure portal, all permissions are granted to microsoft graph API了吗?
  • 是的。但我认为令牌不授予使用端点的权利。只要令牌不需要那些,如果我没记错的话,就不可能访问它。如果是我,我很乐意记下我的回复 =)
  • @Joy 所有权限都授予microsoft graph api
猜你喜欢
  • 1970-01-01
  • 2019-07-07
  • 1970-01-01
  • 2016-07-02
  • 2019-10-28
  • 2020-12-17
  • 2021-08-26
  • 1970-01-01
  • 2014-10-09
相关资源
最近更新 更多