2

I'm building an API with the Python Flask framework in which I now receive a "one-time authorization code" from an app which I supposedly can exchange for an access and refresh token with the Gmail API (described here).

I've been using Oauthlib for regular authorizations in the browser, which works perfectly fine. So I found this page with some example code of how to implement this. The code in the example starts off with from your_validator import your_validator and I'm immediately stuck. I found something here about implementing a custom validator, but at the top of that page it says that flask_oauthlib already implemented this.

Does anybody have an example how to exchange a one-time authorization code for an access and a refresh token with flask_oauthlib? All tips are welcome!

kramer65
  • 50,427
  • 120
  • 308
  • 488

1 Answers1

1

I don't have an example using Oauthlib but here's one using oauth2client library. https://github.com/googleplus/gplus-quickstart-python

Looking at flask_oauthlib, handle_oauth2_response seems to be the method you'll need to use to exchange code with access_token.

agektmr
  • 2,144
  • 15
  • 14
  • It took me some time, but in the end I solved it with handle_oauth2_response. I had to manually overwrite flasks request.args unmutual dict (which is a bit ugly), but it works. Thanks a million for pointing me in the right direction! – kramer65 Sep 16 '15 at 14:41