Microsoft图表401请求用户/ {user_id} /日历时未经授权的错误

时间:2017-11-05 12:06:44

标签: php azure calendar microsoft-graph

尝试请求日历列表,但获取401 Unauthorized错误。我可以获得用户,可以创建新用户,但无法获取或创建日历。

我使用这些库:

thephpleague/oauth2-client

msgraph-sdk-php

通过客户端凭据授予方法获取令牌,无需用户访问。

$this->oauthClient = new \League\OAuth2\Client\Provider\GenericProvider([
            'clientId'                => $config['oauth_app_id'],
            'clientSecret'            => $config['oauth_app_password'],
            'redirectUri'             => $config['oauth_redirect_uri'],
            'urlAuthorize'            => $config['oauth_authority'].$config['tenantID'].$config['oauth_authorize_endpoint'],
            'urlAccessToken'          => $config['oauth_authority'].$config['tenantID'].$config['oauth_token_endpoint'],
            'urlResourceOwnerDetails' => '',
            'scopes'                  => $config['oauth_scopes']
        ]);

$newToken = $this->oauthClient->getAccessToken('client_credentials', [
                    'scope' => 'https://graph.microsoft.com/.default'
                ]);

$graph = new \Microsoft\Graph\Graph();
        $graph->setAccessToken($newToken);

//这可行

$users = $graph->createRequest('GET', '/users/')
            ->setReturnType(\Microsoft\Graph\Model\User::class)
            ->execute();

这有效

$users = $graph->createRequest('GET', '/users/{user_id}')
            ->setReturnType(\Microsoft\Graph\Model\User::class)
            ->execute();

但这不起作用

 $calendars = $graph->createRequest('GET', '/users/{user_id}/calendars')
                ->setReturnType(\Microsoft\Graph\Model\Calendar::class)
                ->execute();

在apps.dev.microsoft.com和Azure门户网站尝试设置所有权限时,这没有帮助。在Graph Explorer相同的结果。

0 个答案:

没有答案