Skip to main content
Authentication providers are pluggable backends that handle user credential validation. Home Assistant supports multiple provider types, allowing flexible authentication strategies.

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()

Returns a LoginFlow instance that handles the authentication steps.

async_get_or_create_credentials()

Converts the login flow result into a Credentials object, creating one if it doesn’t exist.

async_user_meta_for_credentials()

Provides metadata used when creating a new user from credentials.

Optional Methods

async_initialize()

Called during auth manager setup for provider initialization.

async_validate_refresh_token()

Validates that a refresh token can still be used. Raises InvalidAuthError on failure.

async_will_remove_credentials()

Allows cleanup when credentials are deleted.

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:
Features:
  • Local username/password storage
  • bcrypt password hashing (12 rounds)
  • Normalized usernames (lowercase, trimmed)
  • Legacy mode for backwards compatibility
  • Username change support
  • Password change support
Key Methods:
Storage: Credentials stored in .storage/auth_provider.homeassistant:
Username Normalization: Location: 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
Getting the Provider:

Trusted Networks Provider

Location: homeassistant/auth/providers/trusted_networks.py:73 Passwordless authentication from trusted IP networks. Type: trusted_networks Configuration:
Configuration Options:
  • trusted_networks (required): List of IP networks in CIDR notation
  • trusted_users (optional): Map of networks to allowed user IDs or groups
  • allow_bypass_login (optional, default: false): Skip user selection if only one user available
Features:
  • 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
Key Methods:
Security Considerations:
  • 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:
Features:
  • 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:
Must either:
  • 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

Create homeassistant/auth/providers/my_provider.py:

Step 2: Add Configuration Schema

Define CONFIG_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

  1. Validate config with a CONFIG_SCHEMA
  2. Handle errors gracefully in login flows
  3. Use timing-safe comparison for sensitive checks
  4. Implement async_validate_refresh_token() if tokens can become invalid
  5. Clean up resources in async_will_remove_credentials()
  6. Don’t store passwords in credential data
  7. Use appropriate token types for different use cases
  8. Respect MFA settings - check support_mfa property
  9. Normalize identifiers for consistent matching
  10. Log security events for auditing