Skip to main content

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

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

Uploaded Source

Built Distribution

stups_tokens-0.5-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: stups-tokens-0.5.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for stups-tokens-0.5.tar.gz
Algorithm Hash digest
SHA256 d6766e34eea4edd6f9c325507589e893bb4073e212507b1a4f912d75aebd8b76
MD5 f57d3d8775f50722ef73b26c9d47fd0d
BLAKE2b-256 2d70fcabff69b98c5fbfe35f0f8528bf73bf0e954e350976d02530d27a5f9460

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for stups_tokens-0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 1db68b85ca4ff214caf9eec5eb8f11f228c98a86a2dced3358d2bc712d95277f
MD5 48eb540284d390ab1181317ff02f1cb5
BLAKE2b-256 cd76f4db9a9e300827e6ca5ecf3c54318ab4df8560b334c9e78a2015ca4bc864

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