Google oauth2 credential using Flask
This code is used to test google's authentication/authorisation mechanism (Oauth2).
The code only retrieves userinfo profile, which can be used for authenticate the user to another service.
The code was modified from Google's own documents
Create client_secret.json from API manager and credential from Your own Google console
Note that the scopes are listed in Google developers protocols
The returned values can be configured in Google developers API explorer
Full documentation is available in Google developers API library
The code is best tested by creating a virtual environment with python3 and pip3 (tested with 3.4).
$ cd google-oauth2/api
$ python3 -m virtualenv venv
$ venv/bin/pip3 install --upgrade flask
$ venv/bin/pip3 install --upgrade google-api-python-client
The file client-secret.json needs to be copied in the api/secrets/ directory.
$ venv/bin/python3 get_oauth2_credential.py
On a browser go to the address localhost:5000
The userinfo are returned to the browser.
Google distributed its code with a Apache2.0 licence, which I've kept.