Python utilities for Auth0
Project description
pyauth0
Python utilities for Auth0.
Install
pip install pyauth0
Or, if you plan to use async features:
pip install pyauth0[async]
Usage
Get a machine-to-machine token
import pyauth0
from urllib.request import Request, urlopen
token_provider = pyauth0.TokenProvider(
issuer="your-domain.auth0.com",
audience="https://api.your-domain.com",
client_id="1234",
client_secret="secret"
)
# Machine to machine request
token: pyauth0.GetTokenResponse = token_provider.get_token()
response = urlopen(Request(
"https://api.your-domain.com",
headers={"authorization": token.get_authorization()},
))
Get a machine-to-machine token asynchronously
import httpx
import pyauth0
token_provider = pyauth0.TokenProvider(
issuer="your-domain.auth0.com",
audience="https://api.your-domain.com",
client_id="1234",
client_secret="secret"
)
# Machine to machine request
token: pyauth0.GetTokenResponse = await token_provider.aget_token()
async with httpx.AsyncClient() as client:
response = await client.get(
"https://api.your-domain.com",
headers={"authorization": token.get_authorization()},
)
Verify a token
from pyauth0 import TokenVerifier, Auth0Error
token_verifier = TokenVerifier(
issuer="your-domain.auth0.com",
audience="https://api.your-domain.com",
jwks_cache_ttl=60, # optional
)
try:
decoded_token = token_verifier.verify(
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...."
)
except Auth0Error as error:
status_code = error.status_code # suggested status code (401 or 403)
code = error.code # pyauth0 error code (example "token_expired")
description = error.description # pyauth0 error description (example "Token is expired.")
raise error
claim_value = decoded_token.payload.get("http://your-domain.com/claim_name", "default value")
Contribute
If you want to contribute, open a GitHub Issue and motivate your request.
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
pyauth0-0.1.4a0.tar.gz
(5.1 kB
view hashes)
Built Distribution
Close
Hashes for pyauth0-0.1.4a0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05e366f345b8328754c5a9cbd29a54f7e61e7995f41be55be5979d38fc00a89c |
|
MD5 | 233591904ef14cb51db364d296576668 |
|
BLAKE2b-256 | d1194e89ccc3a3f7641e9ba9493a7061cd3c6e4bf8ef4b8aab3c2839688a664c |