diff --git a/homeassistant/auth/__init__.py b/homeassistant/auth/__init__.py index c0beba1a22760f..5f50bfd5fb3fc8 100644 --- a/homeassistant/auth/__init__.py +++ b/homeassistant/auth/__init__.py @@ -235,13 +235,6 @@ async def async_enable_user_mfa(self, user: models.User, raise ValueError('Unable find multi-factor auth module: {}' .format(mfa_module_id)) - if module.setup_schema is not None: - try: - # pylint: disable=not-callable - data = module.setup_schema(data) - except vol.Invalid as err: - raise ValueError('Data does not match schema: {}'.format(err)) - await module.async_setup_user(user.id, data) async def async_disable_user_mfa(self, user: models.User, diff --git a/homeassistant/auth/mfa_modules/__init__.py b/homeassistant/auth/mfa_modules/__init__.py index cec1d29f51f990..7f8e426ae19c67 100644 --- a/homeassistant/auth/mfa_modules/__init__.py +++ b/homeassistant/auth/mfa_modules/__init__.py @@ -64,20 +64,12 @@ def input_schema(self) -> vol.Schema: """Return a voluptuous schema to define mfa auth module's input.""" raise NotImplementedError - @property - def setup_schema(self) -> Optional[vol.Schema]: - """Return a vol schema to validate mfa auth module's setup input. - - Optional - """ - return None - async def async_setup_flow(self, user_id: str) -> 'SetupFlow': """Return a data entry flow handler for setup module. Mfa module should extend SetupFlow """ - return SetupFlow(self, user_id) + return SetupFlow(self, vol.Schema({}), user_id) async def async_setup_user(self, user_id: str, setup_data: Any) -> Any: """Set up user for mfa auth module.""" @@ -101,9 +93,11 @@ class SetupFlow(data_entry_flow.FlowHandler): """Handler for the setup flow.""" def __init__(self, auth_module: MultiFactorAuthModule, + setup_schema: vol.Schema, user_id: str) -> None: """Initialize the setup flow.""" self._auth_module = auth_module + self._setup_schema = setup_schema self._user_id = user_id async def async_step_init( @@ -126,7 +120,7 @@ async def async_step_init( return self.async_show_form( step_id='init', - data_schema=self._auth_module.setup_schema, + data_schema=self._setup_schema, errors=errors ) diff --git a/homeassistant/auth/mfa_modules/insecure_example.py b/homeassistant/auth/mfa_modules/insecure_example.py index e870fa2ee27856..8bd68c565ac6e0 100644 --- a/homeassistant/auth/mfa_modules/insecure_example.py +++ b/homeassistant/auth/mfa_modules/insecure_example.py @@ -7,7 +7,7 @@ from homeassistant.core import HomeAssistant from . import MultiFactorAuthModule, MULTI_FACTOR_AUTH_MODULES, \ - MULTI_FACTOR_AUTH_MODULE_SCHEMA + MULTI_FACTOR_AUTH_MODULE_SCHEMA, SetupFlow CONFIG_SCHEMA = MULTI_FACTOR_AUTH_MODULE_SCHEMA.extend({ vol.Required('data'): [vol.Schema({ @@ -36,10 +36,17 @@ def input_schema(self) -> vol.Schema: return vol.Schema({'pin': str}) @property - def setup_schema(self) -> Optional[vol.Schema]: + def setup_schema(self) -> vol.Schema: """Validate async_setup_user input data.""" return vol.Schema({'pin': str}) + async def async_setup_flow(self, user_id: str) -> SetupFlow: + """Return a data entry flow handler for setup module. + + Mfa module should extend SetupFlow + """ + return SetupFlow(self, self.setup_schema, user_id) + async def async_setup_user(self, user_id: str, setup_data: Any) -> Any: """Set up user to use mfa module.""" # data shall has been validate in caller