Skip to main content

A must have if you are using Auth0 with FastAPI

Project description

Auth0 FastAPI

This library provides a simple and elegant way to validate Auth0 tokens in your API and keep your endpoints protected.

Benefits of using this library:

  • Token validation, ensure the access tokens are properly structured, and signed.
  • Support of scopes for permission based authorization.
  • Automatic swagger UI support, just enter your token and test your endpoints.
  • Super easy to use.

Installation

pip install auth0_fastapi

Example usage

from fastapi import FastAPI, Depends, Security
from auth0_fastapi import Auth0JWTBearerTokenValidator

auth = Auth0JWTBearerTokenValidator(
    domain="<your-auth0-domain>",
    audience="<your-auth0-api-audience>",
    issuer="<your-auth0-issuer>"
)

app = FastAPI()

@app.get("/public")
def get_public():
    return {"message": "Anyone can access"}

@app.get("/protected", dependencies=[Security(auth.get_authenticated_user)])
def get_protected():
    return {"message": "Any authenticated user can access"}


@app.get("/secured", dependencies=[Security(auth.get_authenticated_user, scopes=['read:secure'])])
def get_secured():
    return {"message": "Only users with permission 'read:secure' can access"}

@app.get("/get-token-payload")
def get_token_payload(token_payload=Security(auth.get_authenticated_user)):
    return {"message": token_payload}

Disclaimer

This is not an official plugin, it is however used in production by my own applications and follows best practices.

Please report any issues you encounter, happy coding!

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

auth0_fastapi-0.0.3.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

auth0_fastapi-0.0.3-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file auth0_fastapi-0.0.3.tar.gz.

File metadata

  • Download URL: auth0_fastapi-0.0.3.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.0 Linux/6.2.0-1018-azure

File hashes

Hashes for auth0_fastapi-0.0.3.tar.gz
Algorithm Hash digest
SHA256 9b3c23b75eb9e280076794f3ddc60a838c7bfd002ab14bf3ca9e2cc8527200af
MD5 9cdd6078a7eca5fedad9144f5c0d0a79
BLAKE2b-256 3860360ecf5c41dc2a0bfc480a85f983f7ea23fb1bc5adc48407ed7b312b9d32

See more details on using hashes here.

File details

Details for the file auth0_fastapi-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: auth0_fastapi-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.0 Linux/6.2.0-1018-azure

File hashes

Hashes for auth0_fastapi-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 13b512ecabde79607031a0744277d899606214b9e588163bc7debef2a79db2bb
MD5 b4a9e8fe345af3d7185c5d9b2cba8e04
BLAKE2b-256 37b8259dd7438934dc69d0362f371cc2c191fcb60161311f9a304d47d3f36d35

See more details on using hashes here.

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