Python library to manage OAuth access tokens
Project description
A Python library that keeps OAuth 2.0 service access tokens in memory for your usage.
Installation
$ sudo pip3 install --upgrade stups-tokens
Usage
import requests
import time
import tokens
# will use OAUTH2_ACCESS_TOKEN_URL environment variable by default
# will try to read application credentials from CREDENTIALS_DIR
tokens.configure(url='https://example.com/access_tokens')
tokens.manage('example', ['read', 'write'])
tokens.start()
tok = tokens.get('example')
requests.get('https://example.org/', headers={'Authorization': 'Bearer {}'.format(tok)})
time.sleep(3600) # make the token expire
tok = tokens.get('example') # will refresh the expired token
requests.get('https://example.org/', headers={'Authorization': 'Bearer {}'.format(tok)})
Local testing
The “tokens” library allows injecting fixed OAuth2 access tokens via the OAUTH2_ACCESS_TOKENS environment variable. This allows testing applications using the library locally with personal OAuth2 tokens (e.g. generated by “zign”):
$ MY_TOKEN=$(zign token -n mytok)
$ export OAUTH2_ACCESS_TOKENS=mytok=$MY_TOKEN
$ ./myapp.py # start my local Python app using the tokens library
Releasing
Uploading a new version to PyPI:
$ ./release.sh <NEW-VERSION>
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
stups-tokens-1.0.15.tar.gz
(4.1 kB
view hashes)
Built Distribution
Close
Hashes for stups_tokens-1.0.15-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c2e4a9b92a29b9c80fd3a50d5bf8228dd1f9007037a91e5cc11b6d3c25fa2be |
|
MD5 | b07202c6e471c74cda8a11dff89561e4 |
|
BLAKE2b-256 | a5a619127f427b5f2c8e46c086691cc3558ac662617f3bb7293f5530f21efcaa |