无法请求令牌

问题描述 投票:-1回答:1

要使用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());

我究竟做错了什么?

php microsoft-graph guzzle
1个回答
0
投票

我想完整的错误描述说:

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端点构建编码体的其余部分

© www.soinside.com 2019 - 2024. All rights reserved.