Microsoft Graph REST API v1.0-使用应用程序权限列出个人联系人

时间:2019-05-28 08:04:56

标签: rest api azure-active-directory microsoft-graph azure-webapps

我已经在Azure门户中注册了Web应用程序,授予了Contacts.Read权限,获得了管理员的同意,现在尝试使用Microsoft Graph REST API v1.0列出特定用户的个人联系人应用。

起初,我试图通过向POST发送请求来获取访问令牌 https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token,其身体参数如下:scope=https://graph.microsoft.com/contacts.readgrant_type=client_credentials,我的client_id和我的client_secret

作为回应,我收到一个错误400 Bad Request。身体: {"error":"invalid_scope","error_description":"AADSTS70011: The provided request must include a 'scope' input parameter. The provided value for the input parameter 'scope' is not valid. The scope https://graph.microsoft.com/contacts.read is not valid."}

当我在令牌请求中替换范围参数时,例如:scope=https://graph.microsoft.com/.default,实际上是在收到200 OK和我的Bearer令牌作为响应。

但是当我通过使用此令牌向GET发送https://graph.microsoft.com/v1.0/users/{user_id}/contacts请求来请求用户个人联系时,我得到401 Unauthorized的响应是以下错误:

"code": "NoPermissionsInAccessToken", "message": "The token contains no permissions, or permissions can not be understood.",

我还尝试用scope{app_id_uri}/.default替换令牌请求中的{app_id_uri}/contacts.read值,但没有好运。

那么,如何使用Microsoft Graph REST API v1.0列出用户个人联系人?我在做什么错了?

编辑:权限截图: enter image description here

2 个答案:

答案 0 :(得分:0)

保持范围:

  

scope = https://graph.microsoft.com/.default

您将需要应用程序权限(管理员):

  • users.read.all
  • contacts.read

如果您要添加/编辑联系人,我会选择可读写版本

我还通过离线访问使用委派权限

您已在旧版交易所中设置了联系人,而是添加了图表联系人权限。

答案 1 :(得分:0)

我授予我的应用程序错误的权限。是Contacts.Read部分而非User.Read.All部分的ExchangeMicrosoft Graph权限。

我在Microsoft Graph部分授予了这些权限,并且一切正常。实际上,Contacts.Read权限就足够了。

P.S。范围是https://graph.microsoft.com/.default