2017-01-20 3 views
0

Некоторые (но не все) учетные записи Google постоянно реагируют на 401 при попытке доступа к API-интерфейсу Google, несмотря на то, что tokeninfo говорит мне, что токен доступа, который я использую, имеет правильную область (см. Curl выход ниже). Я могу успешно получить новый токен доступа с помощью токена обновления, но календарь api продолжается до 401.Google Calendar API 401 «Недействительные учетные данные»

У кого-нибудь есть идея, почему это может произойти?

$ curl -v https://www.googleapis.com/oauth2/v3/tokeninfo?access_token=[redacted] 
* Trying 216.58.195.74... 
* Connected to www.googleapis.com (216.58.195.74) port 443 (#0) 
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 
* Server certificate: *.googleapis.com 
* Server certificate: Google Internet Authority G2 
* Server certificate: GeoTrust Global CA 
> GET /oauth2/v3/tokeninfo?access_token=[redacted] HTTP/1.1 
> Host: www.googleapis.com 
> User-Agent: curl/7.49.1 
> Accept: */* 
> 
< HTTP/1.1 200 OK 
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate 
< Pragma: no-cache 
< Expires: Mon, 01 Jan 1990 00:00:00 GMT 
< Date: Tue, 18 Oct 2016 22:00:45 GMT 
< Vary: X-Origin 
< Content-Type: application/json; charset=UTF-8 
< X-Content-Type-Options: nosniff 
< X-Frame-Options: SAMEORIGIN 
< X-XSS-Protection: 1; mode=block 
< Server: GSE 
< Alt-Svc: quic=":443"; ma=2592000; v="36,35,34,33,32" 
< Accept-Ranges: none 
< Vary: Origin,Accept-Encoding 
< Transfer-Encoding: chunked 
< 
{ 
"azp": "[redacted].apps.googleusercontent.com", 
"aud": "[redacted].apps.googleusercontent.com", 
"sub": "[redacted]", 
"scope": "https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/calendar", 
"exp": "1476831626", 
"expires_in": "3581", 
"email": "[redacted]", 
"email_verified": "true", 
"access_type": "offline" 
} 
* Connection #0 to host www.googleapis.com left intact 


$ curl -v https://www.googleapis.com/calendar/v3/users/me/calendarList?access_token=[redacted] 
* Trying 216.58.195.74... 
* Connected to www.googleapis.com (216.58.195.74) port 443 (#0) 
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 
* Server certificate: *.googleapis.com 
* Server certificate: Google Internet Authority G2 
* Server certificate: GeoTrust Global CA 
> GET /calendar/v3/users/me/calendarList?access_token=[redacted] HTTP/1.1 
> Host: www.googleapis.com 
> User-Agent: curl/7.49.1 
> Accept: */* 
> 
< HTTP/1.1 401 Unauthorized 
< Vary: X-Origin 
< WWW-Authenticate: Bearer realm="https://accounts.google.com/", error=invalid_token 
< Content-Type: application/json; charset=UTF-8 
< Date: Tue, 18 Oct 2016 22:01:14 GMT 
< Expires: Tue, 18 Oct 2016 22:01:14 GMT 
< Cache-Control: private, max-age=0 
< X-Content-Type-Options: nosniff 
< X-Frame-Options: SAMEORIGIN 
< X-XSS-Protection: 1; mode=block 
< Server: GSE 
< Alt-Svc: quic=":443"; ma=2592000; v="36,35,34,33,32" 
< Accept-Ranges: none 
< Vary: Origin,Accept-Encoding 
< Transfer-Encoding: chunked 
< 
{ 
"error": { 
    "errors": [ 
    { 
    "domain": "global", 
    "reason": "authError", 
    "message": "Invalid Credentials", 
    "locationType": "header", 
    "location": "Authorization" 
    } 
    ], 
    "code": 401, 
    "message": "Invalid Credentials" 
} 
} 
* Connection #0 to host www.googleapis.com left intact 
+0

Работают ли какие-либо другие звонки? – DaImTo

+0

Возможно ли, что ваш токен обновления истек? – luc

+0

@luc, если токен обновления был истек, я смогу использовать его для получения нового токена доступа, а токен доступа, который у меня уже есть, не будет работать для конечной точки tokeninfo. –

ответ

0

Я смог воспроизвести ситуацию, создав пользователя приложений Google, чья подразделение отключилась в Календаре Google. Google по-прежнему разрешает пользователю предоставлять доступ к календарю и укажет, была ли предоставлена ​​область, но будет 401 способом, описанным при попытке вызвать конечные точки API Google Calendar с их токеном доступа.

Google, пожалуйста, сделайте сообщение об ошибке более ясным или не разрешите предоставление первоначальной области при запросе доступа к приложению, которое отключено администратором!

Смежные вопросы