我正在尝试使用Microsoft Graph POST或PATCH一个教育类,但总是得到错误 .
请求
https://graph.microsoft.com/V1.0/education/classes
{
"description": "Health Level 1",
"classCode": "Health 501",
"displayName": "Health 1",
"externalId": "11019",
"externalName": "Health Level 1",
"externalSource": "sis",
"mailNickname": "fineartschool.net"
}
响应
{
"code": "AccessDenied",
"message": "Required scp claim values are not provided.",
"innerError": {
"request-id": "e1183015-d942-491a-9949-4aa73bbef893",
"date": "2018-06-21T08:44:35"
}
}
我的应用程序具有创建教育类所需的权限 . (为了测试,我的应用程序可以拥有所有应用程序和委派权限) . 发布用户,组等是没有问题的 .
更具体的所需权限:
在AD门户中分配权限后,我执行了以下操作:
-
获取应用的管理员同意
https://login.microsoftonline.com/myTenant/adminconsent?client_id=myClientID&redirect_uri=MyRedirectURI
-
获取授权码
https://login.microsoftonline.com/myTenant/oauth2/authorize?client_id=myClientID&response_type=code&redirect_uri=MyRedirectURI&response_mode=query&resource=https://graph.microsoft.com/
-
获取访问令牌
一切都成功了 . 获得访问令牌后,我有以下范围:
-
.....
-
EduRoster.Read
-
EduRoster.ReadBasic
-
EduRoster.ReadWrite
-
......
Graph文档说您需要权限Application EduRoster.ReadWrite.All
还在Graph Explorer中测试了POST和PATCH,但获得了相同的响应 .
1 回答
此API需要"Application"而不是"Delegated"范围 . 如您所述,它特别需要
EduRoster.ReadWrite.All
范围 .哪个范围应用于令牌完全取决于您用于获取令牌的OAuth Grant:
授权代码Grant =委托
隐式授权=委托
客户端凭据Grant =应用程序
您're not getting this scope in your Access Token is that you'使用授权代码授权(
response_type=code
)的原因将始终导致委派范围被分配 .要进行此调用,您需要使用Client Credentials grant获取令牌 .
您可能还会发现本文有用(完全披露,我是作者):Application vs Delegated Scopes .