2017-12-13 3 views
0

내 웹 사이트에서 Google의 승인을 받으려고합니다. Google oauth가 "코드가 이미 사용되었습니다."오류로 작동하지 않습니다. 오류

그리고 access_tokencode를 교환하는 단계에서

내가 얻을 오류 :

redirect_uri = 'http://example.com/accounts/google/login/callback/'  
config = {u'web': {u'redirect_uris': redirect_uris, 
         u'token_uri': u'https://accounts.google.com/o/oauth2/token', 
         u'auth_uri': u'https://accounts.google.com/o/oauth2/auth', 
         u'client_id': client_id, 
         u'client_secret': client_secret, 
         } 
       } 
    flow = google_auth_oauthlib.flow.Flow.from_client_config(
     config, 
     scopes=['https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/userinfo.email'] 
    ) 
    flow.redirect_uri = redirect_uri 
    flow.fetch_token(code=code) 

I을 : 그것은 구글 libs와 코드에서 권장하는 사용과 마찬가지로 django-allauth LIB aswell를 사용하여 발생

Code was already redeemed 

로컬 컴퓨터에서 localhost url을 사용하여 테스트 구성을 사용하고 있는데 인증이 올바르게 작동합니다.

하지만 프로덕션 서버를 사용할 때 오류가 발생합니다. 구글에서 웹 응용 프로그램에서

나는 모두의 URI 리디렉션이 있습니다

http://localhost:8888/accounts/google/login/callback/ 
http://example.com/accounts/google/login/callback/ 

내가 볼 수 있듯이, code 한 번만 exahnging을, 왜이 수는 일이 어떻게 그것을 해결하기 위해?

+0

새로 고칠 필요가 만료 된 수명이 짧은 코드처럼 보인다 python-social-auth 응용 프로그램을 사용하여 해결. [가능한 도움말] (https://stackoverflow.com/questions/32705682/google-api-php-offline-access-invalid-grant-code-was-already-reemed). 새로 고침 토큰을 사용하고 있습니까? – Jarad

+0

사실, 새로 고침 토큰을 얻을 수 없습니다. 왜냐하면'fetch_token' (두 토큰이 올 곳)이 실패하기 때문입니다. 짧게 살아있는'code'에 대해서 : docs에 관한 정보를 찾지 못했습니다. – user1931780

답변

1

늦게 대답 할 수도 있지만 유용 할 수 있습니다. https://github.com/anupy/google-oauth이 라이브러리를 프로젝트에 적용해야합니다. 아니면 누군가가 유용 할 수도 있습니다.

관련 문제