用于管理OAuth访问令牌的Python库
项目描述
一个Python库,用于在内存中存储OAuth 2.0服务访问令牌供您使用。
安装
$ sudo pip3 install --upgrade stups-tokens
用法
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)})
此库还允许直接从文件读取令牌。令牌需要存储在文件名 ${CREDENTIALS_DIR}/${TOKEN_NAME}-secret 中
import tokens
# the environment variable CREDENTIALS_DIR must be set correctly
tokens.configure(from_file_only=True)
tokens.manage('full-access')
tok = tokens.get('full-access')
requests.get('https://example.org/', headers={'Authorization': 'Bearer {}'.format(tok)})
本地测试
“tokens”库允许通过 OAUTH2_ACCESS_TOKENS 环境变量注入固定的OAuth2访问令牌。这允许使用个人OAuth2令牌(例如由“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
发布
将新版本上传到PyPI
$ ./release.sh <NEW-VERSION>
项目详情
关闭
stups-tokens-1.1.19.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 7830ad83ccbfd52a9734608ffcefcca917137ce9480cc91a4fbd321a4aca3160 |
|
MD5 | d8223ec9d8776d54ed4016fcf448d350 |
|
BLAKE2b-256 | 80bbd9b6991f59b7542ed6de9837e9160af066f6f47fb9515a412f0311315d2f |
关闭
stups_tokens-1.1.19-py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 317f4386763bac9dd5c0a4c8b0f9f0238dc3fa81de3c6fd1971b6b01662b5750 |
|
MD5 | 2fd3a4bfa36d6251ec0bf5ad368242b0 |
|
BLAKE2b-256 | 70dd4fd77cb049b7f1e7da1abc857a8638e07dc67224acf9ebde1f02e33167ae |