google oauth2 id_token vs refresh_token
问题描述:
我正在尝试使用Google OAuth2获取用户的联系信息。我不努力获得访问权限,我想知道由于某种原因,我已经停止获取refresh_token
,而是获得id_token
(长JWT字符串)。 我使用python urllib
来检索用户的访问信息。我的代码是:google oauth2 id_token vs refresh_token
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
当我试图添加到PARAMS 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
答
如果你需要一个刷新令牌,你最好ACCESS_TYPE =离线和approval_prompt =力添加到https://accounts.google.com/o/oauth2/auth?
var url = 'https://accounts.google.com/o/oauth2/auth?' +
'client_id=' + CLIENT_ID + '&' +
'response_type=code&access_type=offline&approval_prompt=force&' +
'redirect_uri=' + encodeURIComponent(REDIRECT_URL) +
'&scope=' + SCOPES;
则返回的代码将永远给你与的下一个握手刷新代码