1 """Example auth module."""
3 from __future__
import annotations
7 import voluptuous
as vol
12 MULTI_FACTOR_AUTH_MODULE_SCHEMA,
13 MULTI_FACTOR_AUTH_MODULES,
14 MultiFactorAuthModule,
18 CONFIG_SCHEMA = MULTI_FACTOR_AUTH_MODULE_SCHEMA.extend(
20 vol.Required(
"data"): [
21 vol.Schema({vol.Required(
"user_id"): str, vol.Required(
"pin"): str})
24 extra=vol.PREVENT_EXTRA,
28 @MULTI_FACTOR_AUTH_MODULES.register("insecure_example")
30 """Example auth module validate pin."""
32 DEFAULT_TITLE =
"Insecure Personal Identify Number"
34 def __init__(self, hass: HomeAssistant, config: dict[str, Any]) ->
None:
35 """Initialize the user data store."""
37 self.
_data_data = config[
"data"]
41 """Validate login flow input data."""
42 return vol.Schema({vol.Required(
"pin"): str})
46 """Validate async_setup_user input data."""
47 return vol.Schema({vol.Required(
"pin"): str})
50 """Return a data entry flow handler for setup module.
52 Mfa module should extend SetupFlow
54 return SetupFlow(self, self.
setup_schemasetup_schema, user_id)
57 """Set up user to use mfa module."""
59 pin = setup_data[
"pin"]
61 for data
in self.
_data_data:
62 if data[
"user_id"] == user_id:
67 self.
_data_data.append({
"user_id": user_id,
"pin": pin})
70 """Remove user from mfa module."""
72 for data
in self.
_data_data:
73 if data[
"user_id"] == user_id:
80 """Return whether user is setup."""
81 return any(data[
"user_id"] == user_id
for data
in self.
_data_data)
83 async
def async_validate(self, user_id: str, user_input: dict[str, Any]) -> bool:
84 """Return True if validation passed."""
86 data[
"user_id"] == user_id
and data[
"pin"] == user_input[
"pin"]
87 for data
in self.
_data_data
bool async_validate(self, str user_id, dict[str, Any] user_input)
Any async_setup_user(self, str user_id, Any setup_data)
None async_depose_user(self, str user_id)
SetupFlow async_setup_flow(self, str user_id)
vol.Schema setup_schema(self)
vol.Schema input_schema(self)
bool async_is_user_setup(self, str user_id)
None __init__(self, HomeAssistant hass, dict[str, Any] config)
bool remove(self, _T matcher)