Skip to main content

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)

Uploaded Source

Built Distribution

sparta_auth0-1.0.0-py3-none-any.whl (7.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page