woob.browser.mfa

class TwoFactorBrowser(*args, **kwargs)[source]

Bases: LoginBrowser, StatesMixin

Browser which inherits from LoginBrowser to implement 2FA authentication.

Parameters:

config (BackendConfig) – configuration of the backend

TWOFA_DURATION: ClassVar[int | float | None] = None

Period to keep the same state

It is different from STATE_DURATION which updates the expire date at each dump.

INTERACTIVE_NAME: ClassVar[str] = 'request_information'

Config’s key which is set to a non-empty value when we are in interactive mode.

AUTHENTICATION_METHODS: ClassVar[Dict[str, Callable]] = {}

Dict of config keys and methods used for double authentication.

Must be set up in the init to handle function pointers.

COOKIES_TO_CLEAR: ClassVar[Tuple[str, ...]] = ()

List of cookie keys to clear before dumping state

HAS_CREDENTIALS_ONLY: ClassVar[bool] = False

Login can also be done with credentials without 2FA

SKIP_LOCATE_BROWSER_ON_CONFIG_VALUES: ClassVar[Tuple[str, ...]] = ()

Skip locate_browser if one of the config values is defined (for example its useful to prevent calling twice the url that sends an OTP)

get_expire()[source]

Get expiration of the state object, using the STATE_DURATION class attribute.

Return type:

str | None

dump_state()[source]

Dump the current state in a state object.

Can be overloaded by the browser subclass.

Return type:

Dict[str, Any]

should_skip_locate_browser()[source]
Return type:

bool

locate_browser(state)[source]

From the state object, go on the saved url.

load_state(state)[source]

Supply a state object and load it.

init_login()[source]

Abstract method to implement initiation of login on website.

This method should raise an exception.

SCA exceptions : - AppValidation for polling method - BrowserQuestion for SMS method, token method etc.

Any other exceptions, default to BrowserIncorrectPassword.

clear_init_cookies()[source]
clear_not_2fa_cookies()[source]
check_interactive()[source]
do_double_authentication()[source]

This method will check AUTHENTICATION_METHODS to dispatch to the right handle_* method.

If no backend configuration could be found, it will then call init_login method.

do_login()

This method will check AUTHENTICATION_METHODS to dispatch to the right handle_* method.

If no backend configuration could be found, it will then call init_login method.