내 웹 사이트에서 Google의 승인을 받으려고합니다. Google oauth가 "코드가 이미 사용되었습니다."오류로 작동하지 않습니다. 오류
그리고 access_token
에 code
를 교환하는 단계에서
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을, 왜이 수는 일이 어떻게 그것을 해결하기 위해?
새로 고칠 필요가 만료 된 수명이 짧은 코드처럼 보인다 python-social-auth 응용 프로그램을 사용하여 해결. [가능한 도움말] (https://stackoverflow.com/questions/32705682/google-api-php-offline-access-invalid-grant-code-was-already-reemed). 새로 고침 토큰을 사용하고 있습니까? – Jarad
사실, 새로 고침 토큰을 얻을 수 없습니다. 왜냐하면'fetch_token' (두 토큰이 올 곳)이 실패하기 때문입니다. 짧게 살아있는'code'에 대해서 : docs에 관한 정보를 찾지 못했습니다. – user1931780