【发布时间】:2014-11-21 09:23:09
【问题描述】:
我正在尝试使用 Google OAuth2 获取用户的联系信息。我并没有为获得访问权而苦苦挣扎,我想知道由于某种原因我已经停止获得refresh_token,而是获得了id_token(长 JWT 字符串)。
我使用 python urllib 来检索用户的访问信息。我的代码是:
scope = 'https://accounts.google.com/o/oauth2/token'
params = urllib.urlencode({
'code': request.GET['code'],
'redirect_uri': settings.SOCIAL_AUTH_GOOGLE_REDIRECT_URI,
'client_id': settings.SOCIAL_AUTH_GOOGLE_OAUTH2_KEY,
'client_secret': settings.SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET,
'grant_type': 'authorization_code',
})
回复:
{u'access_token': u'hash',
u'token_type': u'Bearer',
u'expires_in': 3600,
u'id_token': u'really long hash'}
我使用联系人范围https://www.google.com/m8/feeds/contacts/default/full?alt=json
当我尝试添加到参数access_type : offline 时,我收到以下错误:
Failed to retrive access_token. Status: 400
Message: {
"error" : "invalid_request",
"error_description" : "Parameter not allowed for this message type: access_type"
}
所以在那之后我想知道:
- 我可以使用
id_token刷新我的access_token吗? - 如果第一个是
True:如何? - 获得身份验证的用户类型之间是否有任何差异,因为我注意到有时您会收到
refresh_token,但我需要永久获得它,下次我制作 OAuth2 流程时,我获取id_token
【问题讨论】:
标签: python oauth-2.0 google-contacts-api jwt