I am trying to make authorization from Google on my website.
And at the step of exchanging code
to access_token
I obtain error:
Code was already redeemed
It happens with using django-allauth
lib aswell as with using recommended by Google libs and 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)
When I am using test config with localhost url on my local machine, authorization works fine.
But when I use production server i got error.
In google web application I have both redirect URIs:
http://localhost:8888/accounts/google/login/callback/
http://example.com/accounts/google/login/callback/
As I can see, code
exahnging only once, so why it could happens and how to fix it?