【发布时间】:2012-10-06 16:06:13
【问题描述】:
我使用适用于 Python 的 Google API 客户端库(oauth2client 应用引擎)。当access_token过期时,我必须自己刷新还是由API完成? 现在 access_token 过期了,没有刷新!
我使用 oauth 感知装饰器。访问类型 = 离线,并且刷新令牌在凭据内。
这是我收到的 TokenInfo:
{
"issued_to": "1002825648120.apps.googleusercontent.com",
"audience": "1002825648120.apps.googleusercontent.com",
"user_id": "110738386197429542823",
"scope": "https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email",
"expires_in": 3540,
"email": "xxxxxxxxx@gmail.com",
"verified_email": true,
"access_type": "offline"
}
如果我必须刷新 access_token,oauth 客户端 API 中有没有简单的方法可以做到这一点?
UPDATE-1:
我研究了oauth2/client.py的代码。我现在认为不使用 decorator.http() 会导致不刷新访问令牌。看到这个(我的另一个)问题: Failed to authorize tokeninfo oauth2 request using decorator.http()
UPDATE-2:已解决:
上面提到的问题(在 UPDATE-1 中)已经解决,也解决了这个问题。 API 将在调用授权的 http.request 时尝试刷新 access_token(如果已过期)。
【问题讨论】:
-
是的。 API 假设在到期后刷新您的令牌。这是使用刷新令牌(如果可用)或通过要求用户再次输入凭据(如果会话/cookie 中不可用)来完成的
-
感谢您的确认。现在工作正常。
标签: python google-app-engine oauth oauth-2.0