gws.base.auth.mfa¶
Base multi-factor authentication adapter.
Source code: gws.base.auth.mfa
Module Contents¶
- class gws.base.auth.mfa.Config(*args, **kwargs)¶
Bases:
gws.ConfigMulti-factor authorization configuration.
- lifeTime: gws.Duration | None = '120'¶
Time allowed to complete the MFA step.
- class gws.base.auth.mfa.Object¶
Bases:
gws.AuthMultiFactorAdapterBase multi-factor authentication adapter.
Implements the transaction life cycle (start, state checks, restarts, counting of verification attempts) and provides TOTP code generation and checking. Subclasses implement
verifyand usually extendstart.- otpOptions: gws.lib.otp.Options¶
Options for one-time password generation.
- check_restart(mfa)¶
Check if a transaction can be restarted.
- Parameters:
mfa – The transaction.
- Returns:
Trueif a restart is allowed.
- check_state(mfa)¶
Check if a transaction is still valid, and mark it failed if not.
- Parameters:
mfa – The transaction.
- Returns:
Trueif the transaction is valid.
- check_totp(mfa: gws.AuthMultiFactorTransaction, input: str) bool¶
Check a TOTP code against the transaction secret for the current time.
- Parameters:
mfa – The transaction.
input – The code entered by the user.
- Returns:
Trueif the code is valid.
- configure()¶
Configuration hook.
Called when the node is initialized. Raising an exception here aborts the creation of the node.
- current_timestamp()¶
Return the current time.
- Returns:
The current time as a Unix timestamp in seconds.
- generate_totp(mfa: gws.AuthMultiFactorTransaction) str¶
Generate a TOTP code from the transaction secret for the current time.
Also records the generation time in the transaction.
- Parameters:
mfa – The transaction.
- Returns:
The code.
- restart(mfa)¶
Restart a transaction, for example by sending a new code.
- Parameters:
mfa – The transaction.
- Returns:
A new transaction, or
Noneif a restart is not possible.
- start(user)¶
Start a transaction for a user.
- Parameters:
user – The user who logs in.
- Returns:
A new transaction, or
Noneif the adapter cannot be used for this user, for example because a required user attribute is missing.
- verify_attempt(mfa, payload_valid: bool)¶
Count a verification attempt and update the transaction state.
The state becomes
okif the payload is valid,failedif the transaction is no longer valid or the attempts are used up, andretryotherwise.- Parameters:
mfa – The transaction.
payload_valid – Whether the submitted payload was valid.
- Returns:
The same transaction, updated.
- class gws.base.auth.mfa.OtpConfig(*args, **kwargs)¶
Bases:
gws.ConfigOptions for one-time password generation.