【问题标题】:Microsoft Graph in a LARAVEL PHP app - oauth2 grant method 'password'LARAVEL PHP 应用程序中的 Microsoft Graph - oauth2 授权方法“密码”
【发布时间】: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


    【解决方案1】:

    收到错误异常后,我知道为什么会收到此错误:

        try {
        // Try to get an access token using the resource owner password credentials grant.
        $accessToken = $provider->getAccessToken('password', [
            'username' => 'myapp@assystem.com',
            'password' => 'mypassword'
        ]);
    } catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) {
    
        // Failed to get the access token
        throw $e;
    }
    

    'error_description' => 'AADSTS70000:此 API 版本不支持授权...(Microsoft Graph API)

    【讨论】:

    • 我保留了相同的 Graph API 版本,但我将授权方法更改为“client_credential”。这很好用:-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-06
    • 1970-01-01
    • 1970-01-01
    • 2016-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多