Microsoft Graph API 给出不支持的权限错误
Mirosoft Graph API gives unsupported privileges error
我在 apps.dev.microsoft.com 中创建了应用程序。我正在使用 https://login.microsoftonline.com/common/oauth2/v2.0/authorize for authorization code and https://login.microsoftonline.com/common/oauth2/v2.0/token 访问和刷新令牌。我成功获得了访问令牌,但是当我尝试读取已登录用户的个人资料数据时,出现错误:
Array (
[error] => Array
(
[code] => Authorization_RequestDenied
[message] => Insufficient privileges to complete the operation.
[innerError] => Array
(
[request-id] => 02269b14-2cf9-458e-b9d6-2aec1a23cee3
[date] => 2017-02-23T16:30:44
)
)
)
当我使用创建应用程序的原始 ID 时,此错误不会出现。但是,当我在租期之外使用任何其他 ID 时,就会出现此错误。有人可以为此提出任何解决方法吗?
基于 preview post,您使用如下请求获取令牌:
GET:https://login.microsoftonline.com/common/oauth2/v2.0/authorize?response_type=code&client_id={clientId}&scope=openid%20profile&redirect_uri={redirectURL}
在此请求中,您使用的 scope(openid,profile
) 不会 return access_token 使用 Microsoft Graph REST。 profile scope only return id_token 中的用户信息,而不是授予您访问该用户的权限通过 Microsoft Graph REST 获得的信息。
如果你想使用 Microsoft Graph REST,我们需要添加像 https://graph.microsoft.com/user.Read
这样的范围(更多关于读取用户信息的范围请参考 here)。这是一个示例请求,供您参考,以便通过 https://graph.microsoft.com/v1.0/me
:
访问用户的个人资料
GET:https://login.microsoftonline.com/common/oauth2/v2.0/authorize?response_type=code&client_id={clientId}&scope=https://graph.microsoft.com/user.Read%20openid%20profile&redirect_uri={redirectURL}
请注意 access_token 与 id_token 不同。我们应该使用 access_token 执行对资源(Microsoft Graph)的请求。 id_token仅用于为客户端验证用户身份。更多关于client和resource的概念可以参考here。
如果有帮助,请告诉我。
我在 apps.dev.microsoft.com 中创建了应用程序。我正在使用 https://login.microsoftonline.com/common/oauth2/v2.0/authorize for authorization code and https://login.microsoftonline.com/common/oauth2/v2.0/token 访问和刷新令牌。我成功获得了访问令牌,但是当我尝试读取已登录用户的个人资料数据时,出现错误:
Array (
[error] => Array
(
[code] => Authorization_RequestDenied
[message] => Insufficient privileges to complete the operation.
[innerError] => Array
(
[request-id] => 02269b14-2cf9-458e-b9d6-2aec1a23cee3
[date] => 2017-02-23T16:30:44
)
)
)
当我使用创建应用程序的原始 ID 时,此错误不会出现。但是,当我在租期之外使用任何其他 ID 时,就会出现此错误。有人可以为此提出任何解决方法吗?
基于 preview post,您使用如下请求获取令牌:
GET:https://login.microsoftonline.com/common/oauth2/v2.0/authorize?response_type=code&client_id={clientId}&scope=openid%20profile&redirect_uri={redirectURL}
在此请求中,您使用的 scope(openid,profile
) 不会 return access_token 使用 Microsoft Graph REST。 profile scope only return id_token 中的用户信息,而不是授予您访问该用户的权限通过 Microsoft Graph REST 获得的信息。
如果你想使用 Microsoft Graph REST,我们需要添加像 https://graph.microsoft.com/user.Read
这样的范围(更多关于读取用户信息的范围请参考 here)。这是一个示例请求,供您参考,以便通过 https://graph.microsoft.com/v1.0/me
:
GET:https://login.microsoftonline.com/common/oauth2/v2.0/authorize?response_type=code&client_id={clientId}&scope=https://graph.microsoft.com/user.Read%20openid%20profile&redirect_uri={redirectURL}
请注意 access_token 与 id_token 不同。我们应该使用 access_token 执行对资源(Microsoft Graph)的请求。 id_token仅用于为客户端验证用户身份。更多关于client和resource的概念可以参考here。
如果有帮助,请告诉我。