Skip to main content

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

The OIDCAuthenticationBackend provides comprehensive OpenID Connect authentication with automatic token validation and user creation:
Key Features:
  • Automatic Discovery: Uses OIDC metadata URLs for automatic endpoint discovery
  • Token Introspection: Validates tokens using the provider’s introspection endpoint
  • Async Support: Built on AsyncAuthenticationBackend for high performance
  • Custom Scopes: Configurable OAuth scopes for fine-grained permissions
  • User Creation: Automatic user object creation from token claims
Configuration Parameters:
  • name: Unique identifier for the OIDC client
  • metadata_url: OIDC discovery endpoint URL
  • client_id: OAuth client identifier
  • client_secret: OAuth client secret
  • scopes: Space-separated OAuth scopes
  • introspection_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

  1. Request Received: Incoming request with Authorization header
  2. Token Extraction: Backend extracts Bearer token from header
  3. Token Validation: Backend validates token (OIDC introspection, etc.)
  4. User Creation: Backend creates user object from token claims
  5. State Injection: User object added to request.state.user
  6. 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