【发布时间】:2019-06-30 21:46:50
【问题描述】:
我正在使用oauth2-microsoft 为我的应用开发“使用 Microsoft 登录”工具。我已成功验证并接收令牌,但随后我收到示例代码中的错误。
我正在使用下面的示例代码,并在“urlResourceOwnerDetails”字段中尝试了各种 URL 组合,包括将其留空。
$provider = new \Stevenmaguire\OAuth2\Client\Provider\Microsoft([
'clientId' => '<redacted>',
'clientSecret' => '<redacted>',
'redirectUri' => 'http://localhost/test.php',
'urlAuthorize' => 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize',
'urlAccessToken' => 'https://login.microsoftonline.com/common/oauth2/v2.0/token',
'urlResourceOwnerDetails' => 'https://graph.microsoft.com/v1.0/me/drive'
]);
$options = [
'scope' => ['wl.basic', 'wl.signin']
];
之后是身份验证和令牌生成。
然后这一行抛出错误:
$user = $provider->getResourceOwner($token);
一个令牌肯定正在生成,我可以echo $token 看到它。
上面的代码应该创建一个$user 对象,其中包含有关登录用户的详细信息。但是,它反而会产生以下错误:
如果 'urlResourceOwnerDetails' 设置为 https://graph.microsoft.com/v1.0/me/drive 我得到:
League\OAuth2\Client\Provider\Exception\IdentityProviderException: Access token is empty
如果 'urlResourceOwnerDetails' 设置为 https://outlook.office.com/api/v2.0/me 我得到:
UnexpectedValueException: Invalid response received from Authorization Server. Expected JSON.
如果'urlResourceOwnerDetails' 为空,我会得到:
GuzzleHttp\Exception\RequestException: cURL error 3: malformed (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
有什么想法吗?
【问题讨论】:
-
您能分享一下您的计划吗?到目前为止,我了解您想要获取令牌并使用该令牌尝试访问 Graph API 对吗?但是您使用的是哪种grant_type?
-
嗨,对不起 - 我只是想用它来登录,所以我想根据我的数据库检查他们的电子邮件地址并检索他们的名字等基本信息。
标签: php oauth-2.0 microsoft-graph-api microsoft-graph-sdks