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-1.0.0.tar.gz
(7.3 kB
view hashes)
Built Distribution
Close
Hashes for sparta_auth0-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9f702a47d9adb55e16a02f6aff86bbfaa7db78354a727918fbd8e1436d441fe |
|
MD5 | 3bea743c86b59643faa414983672524f |
|
BLAKE2b-256 | 7ff70c880911824fb43177a94651ae164c71b14fb51aad618e8bb07962d1a289 |