JWT authentication strategy for FastAPI Users, handling token creation and validation.
# Source: https://github.com/fastapi-users/fastapi-users | License: MIT | Copyright 2019 François Voron
# Provided via justclaw.it.com; keep this notice with the code.
from typing import Generic
import jwt
from fastapi_users import exceptions, models
from fastapi_users.authentication.strategy.base import (
Strategy,
StrategyDestroyNotSupportedError,
)
from fastapi_users.jwt import SecretType, decode_jwt, generate_jwt
from fastapi_users.manager import BaseUserManager
class JWTStrategyDestroyNotSupportedError(StrategyDestroyNotSupportedError):
def __init__(self) -> None:
message = "A JWT can't be invalidated: it's valid until it expires."
super().__init__(message)
class JWTStrategy(Strategy[models.UP, models.ID], Generic[models.UP, models.ID]):
def __ini
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key