2016-11-25 2 views
4

this 가이드에 이어 서버 측 oauth를하고 있습니다.YouTube에서 새로 고침 토큰을받지 못합니다. OAuth

나는 성공적으로 OAuth를 완료하지만 새로 고침 및 액세스 토큰 교환 인증 코드에 refresh_token을 받고 있지 않다 단계 :

요청 :

POST /o/oauth2/token HTTP/1.1 
HOST: accounts.google.com 
content-type: application/x-www-form-urlencoded 
content-length: 260 

code=4/KEOuzih9jwfnHj7Rl1DeqHhcJF0goKPwtwR5IQ09ieg&client_id=****.apps.googleusercontent.com&client_secret=****&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2FsSignIn.html&grant_type=authorization_code 

응답 :

{ 
    "access_token" : "****", 
    "expires_in" : 3580, 
    "token_type" : "Bearer" 
} 

내가 빠진 것이 있습니까? 수행 될 필요가

답변

3

두 가지 :

  1. 새로 고침 토큰을 얻으려면, 당신은 OAuth를 시작 요청에 쿼리 매개 변수로 access_type=offline을 통과해야합니다. 이렇게하면 계정에 대해 처음으로 oauth를 수행 할 때 새로 고침 토큰을 얻게됩니다.
  2. 동일한 계정에 대해 oauth를 반복해서 수행 할 때 새로 고침 토큰을 얻으려면 prompt=consent을 쿼리 매개 변수로 oauth 시작 요청에 전달해야합니다.

참조 : https://developers.google.com/identity/protocols/OAuth2WebServer#offline

+1

감사 Abhishek! access_type을 오프라인으로 전달했지만 프롬프트 동의가 활성화되지 않았습니다. 이제 새로 고침 토큰을 반환합니다. – jremi