Backends
Backends in Tasteful are pluggable components that handle specific concerns like authentication, data storage, caching, and external service integrations. They provide a standardized interface that flavors can use without being tightly coupled to specific implementations.Authentication Backends
Authentication backends handle user verification and session management. Tasteful provides a flexible authentication system based on OpenID Connect (OIDC) with support for both synchronous and asynchronous authentication patterns.OIDC Backend
OpenID Connect integration with OAuth providers and custom OIDC servers
Async Authentication
High-performance async authentication for modern applications
Custom User Models
Extensible user models with BaseUser foundation
Token Introspection
Automatic token validation with OIDC introspection endpoints
OIDC Authentication Backend
TheOIDCAuthenticationBackend provides comprehensive OpenID Connect authentication with automatic token validation and user creation:
- Automatic Discovery: Uses OIDC metadata URLs for automatic endpoint discovery
- Token Introspection: Validates tokens using the provider’s introspection endpoint
- Async Support: Built on
AsyncAuthenticationBackendfor high performance - Custom Scopes: Configurable OAuth scopes for fine-grained permissions
- User Creation: Automatic user object creation from token claims
name: Unique identifier for the OIDC clientmetadata_url: OIDC discovery endpoint URLclient_id: OAuth client identifierclient_secret: OAuth client secretscopes: Space-separated OAuth scopesintrospection_endpoint: Optional custom introspection endpoint
Base Authentication Classes
Tasteful provides base classes for building custom authentication backends:AsyncAuthenticationBackend
For high-performance async authentication:AuthenticationBackend
For synchronous authentication scenarios:User Models
BaseUser
The foundation for all user models in Tasteful:OIDCUser
Extended user model for OIDC authentication with token claims:Custom User Models
Create custom user models by extending BaseUser:Storage Backends
Storage backends implementation and documentation coming soon.
Message Backends
Message backends implementation and documentation coming soon.
Custom Backends
Custom backend documentation coming soon.
Backend Configuration
Authentication backends are configured when creating your Tasteful application. The backends are passed as FastAPI dependencies to secure your entire application:Multiple Authentication Backends
You can configure multiple authentication backends for different use cases:Environment-Based Configuration
Use environment variables for secure configuration:Authentication Middleware
Authentication backends in Tasteful work as FastAPI dependencies, automatically handling:- Token Extraction: Automatically extracts tokens from Authorization headers
- Token Validation: Validates tokens using OIDC introspection or custom logic
- User Creation: Creates user objects from validated tokens
- Request State: Adds authenticated user to
request.state.user - Error Handling: Returns appropriate HTTP status codes for authentication failures
Middleware Flow
- Request Received: Incoming request with Authorization header
- Token Extraction: Backend extracts Bearer token from header
- Token Validation: Backend validates token (OIDC introspection, etc.)
- User Creation: Backend creates user object from token claims
- State Injection: User object added to
request.state.user - Route Execution: Your flavor controller receives authenticated request
Error Responses
Authentication backends automatically handle error responses:- 401 Unauthorized: Missing or invalid token
- 500 Internal Server Error: Authentication backend errors