Registry / web-framework / fastapi-auth0

fastapi-auth0

JSON →
library0.5.0pypypi✓ verified 85d ago

FastAPI-Auth0 is a library providing easy Auth0 integration for FastAPI applications. It offers dependency injection for verifying access tokens, including custom user models and role/permission checking. Current version is 0.5.0, with a moderate release cadence.

pip install fastapi-auth0
INSTALL
IMPORT
SIG · FASTAPI-AUTH0
F
fastapi-auth0
web-frameworkpythonv0.5.0
Install
4.3s avg
Import
1333ms
Disk
33MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.5.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 1.406s · 34.6MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 4.3s · import 1.260s · 34MB
33MB installed
● package 33MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Auth0
from fastapi_auth0 import Auth0
from auth0 import Auth0
Wrong package, causes ImportError.
Auth0User
from fastapi_auth0 import Auth0User

Basic setup with public and private endpoints.

from fastapi import FastAPI, Depends from fastapi_auth0 import Auth0, Auth0User import os app = FastAPI() auth0_domain = os.environ.get('AUTH0_DOMAIN', '') auth0_api_audience = os.environ.get('AUTH0_API_AUDIENCE', '') auth0_issuer = f'https://{auth0_domain}/' auth = Auth0(domain=auth0_domain, api_audience=auth0_api_audience, issuer=auth0_issuer) @app.get('/public') async def public(): return {'message': 'Hello public'} @app.get('/private') async def private(user: Auth0User = Depends(auth.get_user)): return {'message': f'Hello {user.email}'}
Debug
Known issues
breakingException renamed from Auth0UnauthenticatedError to Auth0UnauthenticatedException in v0.2.0.
fix
Catch Auth0UnauthenticatedException instead.
affects: >=0.2.0
deprecatedSupport for Python 3.7 dropped in v0.5.0, though may still work.
fix
Use Python 3.8 or higher.
affects: >=0.5.0
gotchaIf audience contains URL-illegal characters (like spaces), JWT verification fails. Fixed in v0.2.0.
fix
Upgrade to v0.2.0+ or sanitize audience string.
affects: <0.2.0
gotchaWhen using token from another tenant or with rotated keys, you get a misleading error message. Fixed in v0.3.0.
fix
Upgrade to v0.3.0+.
affects: <0.3.0
Errors
Common errors & fixes
ImportError: cannot import name 'Auth0' from 'auth0'
Importing from wrong module: from auth0 import Auth0 instead of from fastapi_auth0 import Auth0
fix
Use from fastapi_auth0 import Auth0
AttributeError: module 'fastapi_auth0' has no attribute 'Auth0UnauthenticatedError'
Exception was renamed in v0.2.0.
fix
Catch Auth0UnauthenticatedException instead.
Auth0Error: The token's issuer is not valid. Expected 'https://your-domain.auth0.com/', got 'https://your-domain.auth0.com/'
Issuer URL mismatch, often due to trailing slash differences.
fix
Ensure issuer URL in init matches exactly (typically ending with '/').
Upgrade
Version history
0.5.0latest on PyPI · released Sep 17, 2023
Audit
Dependencies
fastapirequiredCore framework
pydanticrequiredData validation
python-jose[cryptography]requiredJWT handling
httpxrequiredHTTP requests for JWKS
Agent activity
29 hits · last 30 days
node
26
Bingbot
1
OpenAI (training)
1
Resources
fastapi-auth0 — pip install fastapi-auth0 · libregistry