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.13.tar.gz
(3.9 kB
view details)
Built Distribution
File details
Details for the file stups-tokens-1.0.13.tar.gz
.
File metadata
- Download URL: stups-tokens-1.0.13.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75b2b77ada2ccea309cb8cdac7baba397f9675d5642d602929a8ee110a6d2245 |
|
MD5 | 4a1b011b4b29df519d7ccd76bd08f291 |
|
BLAKE2b-256 | 2e4bcdb21d581a159d8cd6345e7383f2d3f89520a028e20f4506e594f73ea5c9 |
Provenance
File details
Details for the file stups_tokens-1.0.13-py3-none-any.whl
.
File metadata
- Download URL: stups_tokens-1.0.13-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 534f2d88ce058cc6de13560150e7c41e0540b585eb0957765cc85e69e797fc83 |
|
MD5 | 5b7e5d8e25f0f3cae02b569119ef8434 |
|
BLAKE2b-256 | 9d2b827394e802ce05af1167ca6e56e9feda757b108e7408790d7df29a559f87 |