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-0.6.tar.gz
(3.4 kB
view details)
Built Distribution
File details
Details for the file stups-tokens-0.6.tar.gz
.
File metadata
- Download URL: stups-tokens-0.6.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a432757d317e82c9ebb03fd6eced34a0e8ef68f13751fa4e95fcfc3121307696 |
|
MD5 | bda33bf894fdf1c74380492e13becf50 |
|
BLAKE2b-256 | 3490738788251365f66983980a6a1372e2e5903e21db4c2bf39ce626e45d3582 |
Provenance
File details
Details for the file stups_tokens-0.6-py3-none-any.whl
.
File metadata
- Download URL: stups_tokens-0.6-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b46a37c2e441cf4fd535836308eed6cce7f3cde7363590295254f80fe98eff20 |
|
MD5 | 4aecb6b6e60728c4b80cf713c24bb0cb |
|
BLAKE2b-256 | e0d6fa94557d42a405e3830d2a06899abf709c6069311cddbfdf40a771f4f5b0 |