要使用Microsoft Graph,我正在尝试代表用户进行身份验证。我正在关注this教程,我现在仍然坚持第3步。
请求令牌时,我收到400 Bad Request
响应:
{
"error": "invalid_scope",
"error_description": "AADSTS70011: The provided request must include a 'scope' input parameter."
}
即使我包含范围参数,这是我的要求:
$guzzle = new \GuzzleHttp\Client(['headers' => [
'Host' => 'https://login.microsoftonline.com',
'Content-Type' => 'application/x-www-form-urlencoded'
]
]);
$url = 'https://login.microsoftonline.com/common/oauth2/v2.0/token';
$token = json_decode($guzzle->post($url, [
'form_params' => [
'client_id' => '################################',
'scope' => 'user.read%20mail.read',
'code' => $_GET['code'],
'grant_type' => 'authorization_code',
'redirect_uri' => 'https://eb3ef49e.ngrok.io/callback.php',
'client_secret' => '################'
],
])->getBody()->getContents());
我究竟做错了什么?
我想完整的错误描述说:
AADSTS70011
:提供的请求必须包含'scope
'输入参数。输入参数“scope”的提供值无效。范围user.read%20mail.read
无效。范围格式无效。范围必须是有效的URI形式<https://example/scope>
或有效的Guid<guid/scope>
。
如果是这样,那么Azure AD端点无法识别此处提供的scope
。 /token
端点期望将scope
参数指定为以空格分隔的范围列表。意思是没有必要在这里显式地转义空格符号:
'scope' => 'user.read%20mail.read'
而是像这样指定:
'scope' => 'user.read mail.read'
和Guzzle client将完成为/token
端点构建编码体的其余部分