rest - Microsoft Graph REST API v1.0 - List personal contacts using application permissions
问题描述
I've registered a web application in Azure Portal, granted it a Contacts.Read
permission, gave it an administrator consent and now trying to list personal contacts of a particular user with Microsoft Graph REST API v1.0 using this application.
At first i'm trying to get an access token by sending POST
request to
https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token
with following body parameters: scope=https://graph.microsoft.com/contacts.read
, grant_type=client_credentials
, my client_id
and my client_secret
.
In response i'm getting an error 400 Bad Request
. Body:
{"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."}
When i'm replacing scope parameter in token request like this: scope=https://graph.microsoft.com/.default
, i'm actually receiving 200 OK
and my Bearer token in response.
But when i'm requesting user personal contacts by sending GET
request to https://graph.microsoft.com/v1.0/users/{user_id}/contacts
with this token, i'm getting 401 Unauthorized
in response with following error:
"code": "NoPermissionsInAccessToken",
"message": "The token contains no permissions, or permissions can not be understood.",
I've also tried to replace the scope
value in my token request with {app_id_uri}/.default
and {app_id_uri}/contacts.read
with no luck.
So how do i list user personal contacts using Microsoft Graph REST API v1.0? What am i doing wrong?
解决方案
我授予我的应用程序错误的权限。它是部分而不是Contacts.Read
部分的User.Read.All
权限。Exchange
Microsoft Graph
我在部分授予了这些权限Microsoft Graph
,一切正常。事实上Contacts.Read
许可就足够了。
PS 范围是https://graph.microsoft.com/.default
推荐阅读
- java - 这个糟糕的 JLabel 仅在调整框架大小后才显示图片。为什么?
- python - Python selenium 无法检测到当前页面元素(按钮)
- html - 背景图像在我的代码中不起作用的原因可能是什么
- javascript - 检查给定 div 中所有具有类“x”的跨度是否具有属性
- python - 通过 input type="hidden" 在视图和模板之间交换数据
- javascript - 成功设置后Discord.js中的集合对象清空
- c# - 使用 YamlDotNet 将字符串嵌套到类反序列化
- java - 无法通过 Python 的 Spring Boot REST API POST 调用上传文件
- typescript - 有什么方法可以缩小T吗?
- linux - opencv 在 raspi pi 4 上包含和 lib 路径