Microsoft Graph不断引发InvalidArgumentException

时间:2017-12-10 18:08:09

标签: php microsoft-graph

我正在使用Microsoft Graph进行身份验证。为了测试,我将PHP REST示例上传到了一个网站空间 - 在本地,它可以工作,但在服务器上,它不断提高

Fatal error: Uncaught exception 'InvalidArgumentException' with message     'Required option not passed: "access_token"'
in vendor/league/oauth2-client/src/Token/AccessToken.php:63
Stack trace:
#0 vendor/league/oauth2-client/src/Provider/AbstractProvider.php(755): League\OAuth2\Client\Token\AccessToken->__construct(Array)
#1 vendor/league/oauth2-client/src/Provider/AbstractProvider.php(562): League\OAuth2\Client\Provider\AbstractProvider->createAccessToken(Array, Object(League\OAuth2\Client\Grant\AuthorizationCode))
#2 oauth.php(60): League\OAuth2\Client\Provider\AbstractProvider->getAccessToken('authorization_c...', Array)
#3 {main} thrown in vendor/league/oauth2-client/src/Token/AccessToken.php on line 63

有人知道我为什么一直收到此错误消息,或者至少指出我正确的方向来修复它?

代码示例:

$provider = new \League\OAuth2\Client\Provider\GenericProvider([
    clientId                => 'client-id', // replaced for security reasons
    clientSecret            => 'client-secret',
    redirectUri             => 'redirect_uri',
    urlAuthorize            => 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize',
    urlAccessToken          => 'https://login.microsoftonline.com/common/oauth2/v2.0/token'
    urlResourceOwnerDetails => '',
    scopes                  => 'openid profile'
]);

$accessToken = $provider->getAccessToken('authorization_code', [
        code             => $_GET['code']
    ]); // raises the exception

1 个答案:

答案 0 :(得分:0)

我发现如果我插入

,这个错误就会得到解决
$prepared['access_token'] = $prepared['id_token'];

进入AbstractProvider :: getAccessToken,就在调用createAccessToken之前。我不完全确定这是否是OAuth2库中的错误,但它现在适用于我。