pythonoauthflaskgoogle-oauthflask-oauthlib

How to exchange one-time authorization code for access token with flask_oauthlib?


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!


Solution

  • 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.