0

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?

2
  • Seems like an expired short-lived code that needs to be refreshed. Possible help. Are you using a refresh token? Commented Dec 13, 2017 at 17:16
  • Actually, I can't obtain refresh token, becouse fetch_token (where both token should come) fails. About short-live code: haven't found any info about that in docs. Commented Dec 13, 2017 at 17:22

2 Answers 2

1

May be late answer, But you may find this useful https://github.com/anupy/google-oauth Need to put this library in your project. Or somebody may find useful.

Sign up to request clarification or add additional context in comments.

Comments

0

I resolved it using python-social-auth app

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.