graph.microsoft.com/v1.0/me/calendars上的400 InvalidAuthenticationToken

时间:2018-10-24 23:23:53

标签: azure-ad-graph-api

enter image description here 问题:当相同的令牌可用于其他休息电话而不是日历时,为什么会得到40倍的收益。我处理电子邮件,用户等。

我获得了访问令牌和验证。 获取令牌:

authentication_endpoint = 'https://login.microsoftonline.com/'
        resource = "https://graph.microsoft.com"
        context = adal.AuthenticationContext(authentication_endpoint + tenantId)
        token_response = context.acquire_token_with_client_credentials(resource, clientId, clientKey)
        access_token_gmc = token_response.get('accessToken')
        print("FD:::access_token-graphmicrosoft:", access_token_gmc)

有效方法:

endpoint = "https://graph.microsoft.com/v1.0/reports/getOffice365ActiveUserDetail%28period%3D%27D7%27%29"
        print("FD:O365:CalendarList-ActvUsers:" + endpoint)
        headers = {"Authorization": 'Bearer ' + access_token_gmc}
        response = requests.get(endpoint, headers=headers)

使用相同的令牌-我尝试了此操作,但它不起作用:

endpoint = "https://graph.microsoft.com/v1.0/me/calendars"
        print("FD:O365:CalendarList:" + endpoint)
        headers = {"Authorization": 'Bearer ' + access_token_gmc}
        response = requests.get(endpoint, headers=headers)

错误:

FD:O365:CalendarList:https://graph.microsoft.com/v1.0/me/calendars
('FD::0365:CalendarsList:', 400, u'https://graph.microsoft.com/v1.0/me/calendars')
('FD::0365:CalendarsList-Response', <Response [401]>)
('FD:0365:CalendarsList-Text:', u'{\r\n  "error": {\r\n    "code": "InvalidAuthenticationToken",\r\n    "message": "Access token is empty.",\r\n    "innerError": {\r\n      "request-id": "3237....e",\r\n      "date": "2018-10-24T23:06:20"\r\n    }\r\n  }\r\n}')

查看图片:

1 个答案:

答案 0 :(得分:0)

在您请求令牌时,您仅使用use Google\Cloud\Logging\LoggingClient as GCPLoggerClient; use Monolog\Handler\PsrHandler; use Monolog\Logger as MonoLogger; use Psr\Log\LogLevel; class GCPLogger { private $stderrLog; private $stdoutLog; private $projectId; public function __construct(string $projectId) { $this->projectId = $projectId; $gcpLogger = new GCPLoggerClient([ 'projectId' => $this->projectId ]); $this->stderrLog = new MonoLogger('stderr'); $this->stdoutLog = new MonoLogger('stdout'); $stderr = $gcpLogger->psrLogger('stderr'); $stdout = $gcpLogger->psrLogger('stdout'); $this->stderrLog->pushHandler(new PsrHandler($stderr)); $this->stdoutLog->pushHandler(new PsrHandler($stdout)); } public function debug($log) { $this->stdoutLog->debug($log); } public function info($log) { $this->stdoutLog->info($log); } public function warning($log) { $this->stderrLog->warning($log); } public function error($log) { $this->stderrLog->error($log); } public function critical($log) { $this->stderrLog->critical($log); } } clientid,这样,令牌中没有与clientkey相关的信息。您应该在令牌的请求正文中添加用户信息(用户名和密码),然后可以使用此令牌来执行以下请求。

以及所需的权限: enter image description here

我使用以下方式来获取用户access_token: enter image description here

请求的响应为:

enter image description here

错误404是因为me没有任何日历。