Sparta Auth0 library
Project description
sparta-auth0
Sparta auth0 library.
Usage
from sparta.auth0 import AuthError, TokenVerifier
tv = TokenVerifier(
auth0_domain="your-domain.auth0.com",
api_audience="https://your-domain.com/api",
jwks_cache_ttl=60, # optional
)
try:
token_payload = tv.verify_auth_header(
"bearer eyJhbGciOiJIUzI1NiIsInR5cCI6Ikp...."
)
except AuthError as error:
status_code = error.status_code # suggested status code (401 or 403)
code = error.code # auth0 error code (example "invalid_header")
description = error.description # auth0 error description (example "Unable to parse authentication token")
raise
your_claim = token_payload.get_required_claim("https://your-domain.com/your_claim")
from sparta.auth0 import TokenProvider
from urllib.request import Request, urlopen
tp = TokenProvider(
issuer="your-domain.auth0.com",
audience="https://your-domain.com/api",
client_id="1234",
client_secret="secret"
)
# Machine to machine request
response = urlopen(Request(
"https://other-machine.your-domain.com/api",
headers={"authorization": tp.get_token().get_authorization()},
))
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
sparta-auth0-0.4.2.tar.gz
(7.2 kB
view hashes)
Built Distribution
Close
Hashes for sparta_auth0-0.4.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2a9777c26292cbced1e7be1f867dfb62a65f9c1335f3d47809bbac9529dc273 |
|
MD5 | 529ab231d01ed250993df9869b9a00d5 |
|
BLAKE2b-256 | 2033cbe5a5b65cabd027d38de08bb9596b46248807cdce402e8fd98f0071b01d |