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.6.tar.gz
(3.6 kB
view details)
Built Distribution
File details
Details for the file stups-tokens-1.0.6.tar.gz
.
File metadata
- Download URL: stups-tokens-1.0.6.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | be8f65518e42fef73ab71ca8e587dff09cbca64491be108cd61092261d5d8589 |
|
MD5 | 629740bcb09b6322d6ca89fcb582520e |
|
BLAKE2b-256 | fa9515abc45d016d02584d25099f236e0134a5fbc9b6cbc5e4fe28e2c026f333 |
Provenance
File details
Details for the file stups_tokens-1.0.6-py3-none-any.whl
.
File metadata
- Download URL: stups_tokens-1.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 | 6677af766540ffe43fd82804154ad7211ff90567064e5e691b93dc61087a2a73 |
|
MD5 | cfa0e8a9925f821dc24546e0a0942e26 |
|
BLAKE2b-256 | f8468e15ebd0f196fee7a9882f893da8bff7d23e09123e66397bdaa64b1c76e8 |