Authentication Flow & Integration Guide
Follow this comprehensive guide to implement BOSA Authentication in your application. Each section explains both the technical concept and provides practical integration steps.
Understanding the Configuration
BOSA Authentication requires configuration for database connectivity, security parameters, and token settings. The system uses a singleton AuthenticationDbSettings class to maintain consistent configuration across your application. For more details about table structure initialized, please check database schema →
Install Dependencies
# Using pip
pip install bosa-core-binary[authentication]
# Using poetry
poetry add bosa-core-binary[authentication]Configure Environment Variables
Add the following key to your .env file:
# Required environment variables
DATABASE_AUTHENTICATION_URL="postgresql://user:password@localhost:5432/auth_db"
AUTH_SECRET_KEY="your-secure-secret-key"
# Optional environment variables
AUTH_ALGORITHM="HS256"
AUTH_ACCESS_TOKEN_EXPIRE_MINUTES="43200" # 30 daysInitialize Authentication
Before using any authentication features, call this once during application startup:
This initialization creates all necessary database tables and prepares the system for client and user management.
Understanding Client Management
The client represents an organization or tenant in the multi-tenancy model. Each client has its own API key used to create and manage users within its scope. Client API keys follow the format:
To interact with client-related features, you can import the necessary services from:
Create a Client
Verify Client API Key
There are two ways to verify a client API key. First is using client_aware_service
This is useful when you want to perform further operations scoped to the verified client, such as accessing client-specific data. Or, you can perform direct approach when you only need to validate the API key.
Understanding User Management
Users exist within the scope of a client. Each user has a unique identifier and a secret (password). The system securely hashes all secrets using Argon2 before store it. To interact with user-related features, you can import the necessary services from:
Create a User
Get User Information
You can retrieve user information using either:
User ID, or
User identifier (e.g. email)
Both methods require the client API key to enforce multi-tenancy and ensure scoped access.
User management operations always require a valid client API key to enforce the multi-tenancy security model.
Understanding Authentication
Authentication validates user credentials and issues JWT tokens. These tokens are used for subsequent API requests. The system records all active tokens and supports token verification and revocation.
To interact with token-related features, you can import the necessary services from:
Authenticate a User
Verify a Token
Revoke a Token
When implementing authentication flows, always verify tokens on each protected endpoint and implement proper error handling for authentication failures.
Understanding Third-Party Integrations
The BOSA Authentication system allows users to create secure integrations with third-party services. These integrations store authentication credentials for services like GitHub, Google Drive, and others.
To interact with third-party related features, you can import the necessary services from:
Create an Integration
Check for Existing Integrations
Get Integration Data
Remove an Integration
When implementing third-party integrations, follow OAuth 2.0 best practices for secure authorization flows and token storage.
You can adapt BOSA Core Authentication to other frameworks by following the same flow of initializing configuration, setting up repositories and services, and implementing the appropriate authentication checks. For more details reference of each class and functions, please check API Reference →
Last updated