PropelAuth FastAPI

raw JSON →
4.4.0 verified Mon Apr 27 auth: no python

A FastAPI library for managing authentication, backed by PropelAuth. Current version is 4.4.0, requires Python >=3.9. Regularly updated with new APIs and improvements.

pip install propelauth-fastapi
error ModuleNotFoundError: No module named 'propelauth_fastapi'
cause The package is not installed or imported incorrectly.
fix
Run 'pip install propelauth-fastapi' and ensure import is 'from propelauth_fastapi import PropelAuth'.
error TypeError: __init__() missing 2 required positional arguments: 'auth_url' and 'api_key'
cause PropelAuth() was called without required arguments.
fix
Initialize with PropelAuth(auth_url='https://your-tenant.auth.us.authok.io', api_key='your-api-key').
error propelauth.errors.InvalidAPIKeyError: Invalid API key
cause The API key is incorrect or the auth_url does not match the tenant.
fix
Verify your API key and auth_url from the PropelAuth dashboard.
breaking In v4.0.0, the library was rewritten to depend on propelauth-py. The initialization API changed: now pass auth_url and api_key directly instead of using PropelAuthConfig.
fix Replace PropelAuthConfig(...) with PropelAuth(auth_url=..., api_key=...).
deprecated The get_user dependency is deprecated as of v4.4.0. Use require_user or the new user retrieval methods.
fix Replace Depends(get_user) with Depends(auth.require_user).
gotcha The auth_url must include the full URL with tenant subdomain, e.g., 'https://your-tenant.auth.us.authok.io'. Missing 'https://' or the tenant part will cause cryptic authentication errors.
fix Ensure auth_url is a valid URL string starting with https://.

Initialize PropelAuth with your tenant credentials and protect routes using require_user dependency.

from fastapi import FastAPI, Depends
from propelauth_fastapi import PropelAuth, get_user

app = FastAPI()

auth = PropelAuth(
    auth_url="https://your-tenant.auth.us.authok.io",
    api_key="your-api-key"
)

@app.get("/protected")
async def protected_route(user = Depends(auth.require_user)):
    return {"message": f"Hello {user.email}"}

@app.get("/current-user")
async def current_user(user = Depends(get_user)):
    return user