Flask-GSA
A Flask extension for interacting with Google OAuth2 Service Accounts.
Getting Started
Requirements
Python 2.6+
OpenSSL
Installation
Flask-GSA can be installed with pip:
$ pip install Flask-GSA
Basic Usage
A minimal sample application:
from flask import Flask
from flask_gsa import GoogleServiceAccount
app = Flask(__name__)
# Create a service account object and assign a config variable prefix
analytics_gsa = GoogleServiceAccount('ANALYTICS_GSA')
# Set up the service account settings
app.config['ANALYTICS_GSA_PK_FILE'] = 'analytics.p12'
app.config['ANALYTICS_GSA_PK_PASSWORD'] = 'notasecret'
app.config['ANALYTICS_GSA_EMAIL'] = '12345abcd@developer.gserviceaccount.com'
# Initialize the extension
analytics_gsa.init_app(app)
@app.route('/token')
def get_analytics_token():
scopes = [
'https://www.googleapis.com/auth/analytics.readonly'
]
return analytics_gsa.generate_token(scopes)
if __name__ == '__main__':
app.run(port=5000, debug=True)
Run the app:
$ python example.py * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) * Restarting with stat
Get a token:
$ http :5000/token
{
"expires": 1437698007,
"issued": 1437694408,
"token": "ya29.uQEiLFkED9YMTG7CvctLYtJqnOny_8CkA4_Hxk5yxzEhXR3eNSO-Pca20BRNxBT74XYD",
"token_type": "Bearer"
}
Configuration Options:
When creating an instance of the extension, you must choose a config
variable
prefix. This allows multiple service account objects to be used with
the same
app:
analytics_gsa = GoogleServiceAccount('ANALYTICS')
gdrive_gsa = GoogleServiceAccount('GDRIVE')
The following config variables are required:
Config Variable |
Description |
|---|---|
<prefix>_PK_FILE |
Path to the PKCS12 key that will be used to sign tokens |
<prefix>_PK_PASSWORD |
Password for the PKCS12 private key |
<prefix>_EMAIL |
Service Account’s email address |
# Revision History
## 0.1.1 (2015/07/23)
Fix tests
## 0.1.0 (2015/07/23)
Initial release
Release files for Flask-GSA 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| Flask-GSA-0.1.1.tar.gz | 4.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| Flask_GSA-0.1.1-py2-none-any.whl | Python 2 | none | any | Details |
Total release size: 9.3 kB
Release files / Flask-GSA-0.1.1.tar.gz
| Download URL | Flask-GSA-0.1.1.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
16449bcfd477e2a27b2731a176f45bb2ff616f82a9c11079dedf55f911ae2547
|
|
BLAKE2b-256 checksum How to use checksums |
3771ae3ba19a05416b89b6ffa4ef4bad04a0d3b24a882a083a37217c6dd0d94b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / Flask_GSA-0.1.1-py2-none-any.whl
| Download URL | Flask_GSA-0.1.1-py2-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 2 |
|
SHA-256 checksum How to use checksums |
8c507518f79d6f80905f129285b2938837d6ef5fa3114dae0e87f0adec619943
|
|
BLAKE2b-256 checksum How to use checksums |
07a035a020b447d7f00d475c8ca5c043591ab1fb1d3e79dbcb24f2e4952dd45d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |