deux.oauth2.validators

class deux.oauth2.validators.MFAOAuth2Validator[source]

OAuth2 validator class for MFA that validates requests to authenticate with username and password by also verifying that they supply the correct MFA code or backup code if multifactor authentication is enabled.

validate_user(username, password, client, request, *args, **kwargs)[source]

Overrides the OAuth2Validator validate method to implement multi factor authentication.

If MFA is disabled, authentication requires just a username and password.

If MFA is enabled, authentication requires a username, password, and either a MFA code or a backup code. If the request only provides the username and password, the server will generate an appropriate challenge and respond with mfa_required = True.

Upon using a backup code to authenticate, MFA will be disabled.

Parameters:

attrs – Dictionary of data inputted by the user.

Raises: