Provider Architecture
Location:homeassistant/auth/providers/__init__.py
Base AuthProvider Class
Location:homeassistant/auth/providers/__init__.py:50
All authentication providers extend the AuthProvider base class:
Required Methods
Providers must implement these abstract methods:async_login_flow()
LoginFlow instance that handles the authentication steps.
async_get_or_create_credentials()
Credentials object, creating one if it doesn’t exist.
async_user_meta_for_credentials()
Optional Methods
async_initialize()
async_validate_refresh_token()
InvalidAuthError on failure.
async_will_remove_credentials()
Provider Registry
Providers register using a decorator:Built-in Providers
Home Assistant Auth Provider
Location:homeassistant/auth/providers/homeassistant.py:293
The default local username/password authentication.
Type: homeassistant
Configuration:
- Local username/password storage
- bcrypt password hashing (12 rounds)
- Normalized usernames (lowercase, trimmed)
- Legacy mode for backwards compatibility
- Username change support
- Password change support
.storage/auth_provider.homeassistant:
homeassistant/auth/providers/homeassistant.py:96
- Usernames are normalized to lowercase
- Leading/trailing whitespace stripped
- Legacy mode preserves old behavior for compatibility
- Creates repair issue if non-normalized usernames detected
Trusted Networks Provider
Location:homeassistant/auth/providers/trusted_networks.py:73
Passwordless authentication from trusted IP networks.
Type: trusted_networks
Configuration:
trusted_networks(required): List of IP networks in CIDR notationtrusted_users(optional): Map of networks to allowed user IDs or groupsallow_bypass_login(optional, default: false): Skip user selection if only one user available
- Automatic authentication from trusted networks
- Per-network user restrictions
- Group-based access control
- Trusted proxy detection (blocks auth from proxies)
- Cloud connection detection (blocks cloud access)
- No MFA support
- Validates IP address on every token use
- Blocks access from trusted proxies to prevent abuse
- Blocks cloud connections even if from trusted IP
- Only allows existing, active, non-system users
Command Line Provider
Location:homeassistant/auth/providers/command_line.py
Authentication via external command execution.
Type: command_line
Configuration:
- Delegates authentication to external programs
- Supports custom metadata
- Command receives username and password via stdin
- Exit code 0 = success, non-zero = failure
Login Flow
Location:homeassistant/auth/providers/__init__.py:195
Providers create LoginFlow instances to handle the authentication process:
Flow Steps
async_step_init()
Location:homeassistant/auth/providers/__init__.py:213
The initial authentication step:
- Return
self.async_show_form()to display a form - Return
await self.async_finish(flow_result)on success
async_step_select_mfa_module()
Location:homeassistant/auth/providers/__init__.py:223
Optional MFA module selection:
async_step_mfa()
Location:homeassistant/auth/providers/__init__.py:248
MFA verification:
Example: Home Assistant Login Flow
Location:homeassistant/auth/providers/homeassistant.py:409
Creating Custom Providers
Step 1: Create Provider Module
Createhomeassistant/auth/providers/my_provider.py:
Step 2: Add Configuration Schema
DefineCONFIG_SCHEMA for validation:
Step 3: Register Provider
The@AUTH_PROVIDERS.register() decorator automatically registers your provider.
Step 4: Configure in Home Assistant
Provider Loading
Location:homeassistant/auth/providers/__init__.py:144
Best Practices
- Validate config with a
CONFIG_SCHEMA - Handle errors gracefully in login flows
- Use timing-safe comparison for sensitive checks
- Implement async_validate_refresh_token() if tokens can become invalid
- Clean up resources in
async_will_remove_credentials() - Don’t store passwords in credential data
- Use appropriate token types for different use cases
- Respect MFA settings - check
support_mfaproperty - Normalize identifiers for consistent matching
- Log security events for auditing
Related Components
- Authentication Overview - Core authentication concepts
- Permissions System - Access control
- Data Entry Flow - Flow framework used by login flows