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.14.tar.gz
(4.0 kB
view details)
Built Distribution
File details
Details for the file stups-tokens-1.0.14.tar.gz
.
File metadata
- Download URL: stups-tokens-1.0.14.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c79f03210eec2e61b1b7de803e63dcc29b0ffa7dca6febdf98eba7be1ea80ce2 |
|
MD5 | 7e629f64818bf3f4c747e1553720e51f |
|
BLAKE2b-256 | f79a954b79ba08e20cd109fbcd79e8b32577622075d3404424e45ffbb7242e05 |
Provenance
File details
Details for the file stups_tokens-1.0.14-py3-none-any.whl
.
File metadata
- Download URL: stups_tokens-1.0.14-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 544ad6c764ab2eb8d025e12a2d4fd730c6e237f68a8dbf5ffb14743dafa60736 |
|
MD5 | b7abcb3455ea936e16b19fab1b35eb53 |
|
BLAKE2b-256 | 3403689de5d0e335655e8f0fcecea7ad30065db3d722658a06be468b7338e032 |