【发布时间】:2018-04-03 21:17:25
【问题描述】:
我正在使用一个试图从 Microsoft GRAPH API 获取令牌的 LARAVEL PHP 应用程序。 实际上,我可以使用 OAuth2 Authorization CODE 授权方法轻松获得令牌。
方法如下:https://github.com/microsoftgraph/microsoft-graph-docs/blob/master/concepts/php.md
但使用此方法会将浏览器重定向到 Microsoft 身份验证网页,我不希望这样。我想要一个没有任何浏览器重定向的透明方法。
以下是获取令牌的所有 Oauth2 授权方法: https://alexbilbie.com/guide-to-oauth-2-grants
所以我想通过使用“资源所有者凭据授予”来获取令牌。这是我的代码:
$provider = new \League\OAuth2\Client\Provider\GenericProvider([
'clientId' => 'b9e6844b-b20c-4eef-bbff-fa052c1c0f94',
'clientSecret' => '1A8yUUcMaD5Zdv1dgwqy3SR',
'redirectUri' => 'https://my-website-url/oauth',
'urlAuthorize' => 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize',
'urlAccessToken' => 'https://login.microsoftonline.com/common/oauth2/v2.0/token',
'urlResourceOwnerDetails' => '',
'scopes' => 'openid email profile' // Admin restricted scopes : Directory.Read Directory.ReadWrite Groups.Read.All
]);
$accessToken = $provider->getAccessToken('password',[
'username' => 'myaccount@assystem.com',
'password' => 'xxxxx'
]);
但我收到以下错误:
(1/1) IdentityProviderException 无效授予 在 GenericProvider.php(第 217 行)
有什么帮助吗?
【问题讨论】:
标签: laravel api graph oauth-2.0 access-token