How to exchange one-time authorization code for access token with flask_oauthlib?
Question: I'm building an API with the [Python Flask framework](http://flask.pocoo.org/)
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](https://developers.google.com/gmail/api/auth/web-server)).

I've been using
[Oauthlib](http://oauthlib.readthedocs.org/en/latest/index.html) for regular
authorizations in the browser, which works perfectly fine. So I found [this
page](http://oauthlib.readthedocs.org/en/latest/oauth2/grants/authcode.html)
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](http://oauthlib.readthedocs.org/en/latest/oauth2/server.html#implement-
a-validator) about implementing a custom validator, but at the top of that
page it says that [flask_oauthlib](https://github.com/lepture/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!


Answer: 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`](https://github.com/lepture/flask-
oauthlib/blob/master/flask_oauthlib/client.py#L619) seems to be the method
you'll need to use to exchange `code` with `access_token`.

