Skip to main content

Python utilities for Auth0

Project description

pyauth0

Test Coverage Status PyPI version

Python utilities for Auth0.

Install

pip install pyauth0

Usage

Get a machine-to-machine token

from pyauth0 import TokenProvider
from urllib.request import Request, urlopen

token_provider = TokenProvider(
    issuer="your-domain.auth0.com",
    audience="https://api.your-domain.com",
    client_id="1234",
    client_secret="secret"
)

# Machine to machine request
response = urlopen(Request(
    "https://api.your-domain.com",
    headers={"authorization": token_provider.get_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


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.3.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

pyauth0-0.1.3-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file pyauth0-0.1.3.tar.gz.

File metadata

  • Download URL: pyauth0-0.1.3.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.10.12 Linux/6.5.0-1018-azure

File hashes

Hashes for pyauth0-0.1.3.tar.gz
Algorithm Hash digest
SHA256 6f66578c1fdb2391587b43739bd05ff6c35604523eb136fbe8c57b651aa18f93
MD5 389c1b22f9a444ec39ad76403229234d
BLAKE2b-256 05d1c88d8522ac23ad175d6a96612cf5f90495f0fec37beee899c907c1de492b

See more details on using hashes here.

Provenance

File details

Details for the file pyauth0-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: pyauth0-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.10.12 Linux/6.5.0-1018-azure

File hashes

Hashes for pyauth0-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 abdc619937347650718930ca0249e507f1e65fc83121423a6a9067d044a32633
MD5 ae9073c4f3caffbf34f7740e98c4bb2f
BLAKE2b-256 663b80bc72853dd23a8e4427eee950d4b1ac04ff6dc4780d2c8edc89e86e584b

See more details on using hashes here.

Provenance

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