Skip to main content

Python library to manage OAuth access tokens

Project description

Build Status Code Coverage PyPI Downloads Latest PyPI version License

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


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.16.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

stups_tokens-1.0.16-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file stups-tokens-1.0.16.tar.gz.

File metadata

File hashes

Hashes for stups-tokens-1.0.16.tar.gz
Algorithm Hash digest
SHA256 a4ce82c359e4c86fb34de8642d7352bb830c2445d67204e1bacb6593810928d1
MD5 57afbc1e2d467e7c881c3cb12ccd9afd
BLAKE2b-256 9ff386c3f931b7e708004c811b9a30071c0e5f1f6e5dd0b6fb15fa5ac2a52c38

See more details on using hashes here.

Provenance

File details

Details for the file stups_tokens-1.0.16-py3-none-any.whl.

File metadata

File hashes

Hashes for stups_tokens-1.0.16-py3-none-any.whl
Algorithm Hash digest
SHA256 3a3b25ad5688ccbd541a165a6c6e26fa560c95a393d6016f908240a7cb82d099
MD5 5b03113718a87f07aa3779f6e1708089
BLAKE2b-256 5729d3c5e55b296a6c4d0f8c2c0b5fa5fb1bf51951689df028df0e17d4b031e9

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page