requests-jwtauth
Authenticator plugins for Requests that support JWT bearer tokens.
Description
This package contains two classes, HTTPBearerAuth and JWTSecretAuth,
that implement the AuthBase interface from the Requests package. The
HTTPBearerAuth class takes a single bearer token value at initialization,
and adds that to an Authorization: Bearer header. The
JWTSecretAuth class takes a shared secret, and uses that to generate and
sign short-lived JWT tokens to be added to an Authorization: Bearer
request header. By default, these tokens are valid for 1 hour (3600
seconds), and may contain arbitrary JWT claims in their payload.
Dependencies
Installation
pip install requests-jwtauth
Usage
HTTPBearerAuth
import requests
from requests_jwtauth import HTTPBearerAuth
# send a request with a pre-obtained bearer token
my_token = '...'
r = requests.get('http://example.com', auth=HTTPBearerAuth(my_token))
JWTSecretAuth
import requests
from requests_jwtauth import JWTSecretAuth
# use a shared secret to generate (and automatically regenerate)
# short-lived JWT bearer tokens
secret_auth = JWTSecretAuth(
# shared secret with the service that requires authentication
secret='...',
# JWT claims to place in the token payload
# this class takes care of providing the 'exp' (expiration time) key
claims={
'sub': '...'
},
# Time-To-Live, in seconds; default is 3600 (i.e., 1 hour)
ttl=3600,
# instead of waiting for it to actually expire,
# renew the token whenever the remaining time-to-live is
# less than this number of seconds; default is 60
expiration_buffer=60,
# signing algorithm to use; defaults to H256
signing_algorithm='H256'
)
r = requests.get('http://example.com', auth=secret_auth)
Development Setup
git clone git@github.com:umd-lib/requests-jwtauth.git
cd requests-jwtauth
pyenv install $(cat .python-version) --skip-existing
python -m venv .venv --prompt "requests-jwtauth-py$(cat .python-version)"
source .venv/bin/activate
pip install -e .[test]
Testing
Using pytest:
pytest
With test coverage information:
pytest --cov-report=term-missing --cov src
Metadata
Release files for requests-jwtauth 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| requests-jwtauth-1.0.1.tar.gz | 8.1 kB | Without provenance | Details for requests-jwtauth-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| requests_jwtauth-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for requests_jwtauth-1.0.1-py3-none-any.whl |
Total release size: 15.7 kB
Release files / requests-jwtauth-1.0.1.tar.gz
| Download URL | requests-jwtauth-1.0.1.tar.gz |
|---|---|
| Size | 8.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4a33957dfb1f2dbe1609932b8bb78324b20a82304fb6229f992de3638b4f01c2
|
|
BLAKE2b-256 checksum How to use checksums |
b3739d7a1295975765a0890149f7b61e024c764ec7bb1df5c56c18b206532033
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.12.0
|
Release files / requests_jwtauth-1.0.1-py3-none-any.whl
| Download URL | requests_jwtauth-1.0.1-py3-none-any.whl |
|---|---|
| Size | 7.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2358b346b92f3692d90bec1bfc700df568ef8fbcc7e75ebf1fc772b35bb7ee94
|
|
BLAKE2b-256 checksum How to use checksums |
b9a7344c4620cb4f41e555a4d7d2405098a9b5eb7eb277a63e61a97b358772e8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.12.0
|
Security for requests-jwtauth 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.