2014-09-26 2 views
1

Google OAuth2를 사용하여 사용자의 연락처 정보를 가져 오려고합니다. 나는 액세스를 얻는 데 어려움을 겪고있는 것이 아니라 어떤 이유로 든 내가 멈추지 않고 궁금해하고있다. refresh_token 대신 id_token (긴 JWT 문자열)을 얻는다. 파이썬 urllib을 사용하여 사용자의 액세스 정보를 검색합니다. 내 코드는 다음과 같습니다google oauth2 id_token 대 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', 
}) 

응답 : 그래서

Failed to retrive access_token. Status: 400 
Message: { 
    "error" : "invalid_request", 
    "error_description" : "Parameter not allowed for this message type: access_type" 
} 

: 나는 아래의 오류가 access_type : offline을 PARAMS하는 범위 https://www.google.com/m8/feeds/contacts/default/full?alt=json 내가 추가하려고 해요 연락처를 사용

{u'access_token': u'hash', 
u'token_type': u'Bearer', 
u'expires_in': 3600, 
u'id_token': u'really long hash'} 

그 후 궁금해합니다 :

  1. id_token 새로 고침 access_token을 사용할 수 있습니까?
  2. 첫 번째 문자가 True 인 경우 : 어떻게?
  3. 가끔 당신이 refresh_token를 얻을하지만 영구적으로 얻을 필요가 눈치 때문에 인증지고 사용자의 유형 간의 차이가있다가, 다음 번에 내가 id_token

답변

0
을 얻을 OAuth2를 흐름을 당신은 새로 고침 토큰이 필요하면, 당신은 더 나은 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; 

에 access_type = 오프라인 approval_prompt = 힘을 추가

것은 그런 다음 반환 코드는 항상와 다음 핸드 셰이크에 당신에게 새로 고침 코드를 제공합니다