Overview

FastAPI-Users 12.0, released on August 1, 2023, migrates to Pydantic v2 and improves authentication schemas.

Main Features

Pydantic v2 migration

All models now use Pydantic v2 with model_config instead of the inner Config class.

python
from fastapi_users import schemas

class UserRead(schemas.BaseUser[int]):
    name: str

class UserCreate(schemas.BaseUserCreate):
    name: str

class UserUpdate(schemas.BaseUserUpdate):
    name: str | None = None

Improved JWT transport

JWT transport now supports audience and issuer configuration for better security.

python
from fastapi_users.authentication import (
    AuthenticationBackend, BearerTransport, JWTStrategy,
)

bearer = BearerTransport(tokenUrl='auth/jwt/login')

def get_jwt_strategy() -> JWTStrategy:
    return JWTStrategy(secret='SECRET', lifetime_seconds=3600)

backend = AuthenticationBackend(
    name='jwt', transport=bearer, get_strategy=get_jwt_strategy,
)

Sources