Handle Two-Step and Two-Factor Authentication (2SA/2FA)
mainIf your account has security enabled, you must handle the authentication flow by checking api.requires_2fa or api.requires_2sa.
For 2FA:
- Check
api.requires_2fa. - Prompt the user for the code received on an approved device.
- Call
api.validate_2fa_code(code). - If the session is not trusted, call
api.trust_session().
For 2SA:
- Check
api.requires_2sa. - Iterate through
api.trusted_devicesto let the user pick a device. - Call
api.send_verification_code(device). - Prompt for the code and call
api.validate_verification_code(device, code).