SDKsPython SDKAuthentication
Multi-Factor Authentication
Enroll and verify TOTP and recovery codes with the Python SDK.
Multi-Factor Authentication
enroll_totp()
totp = client.enroll_totp()
print(f"Secret key: {totp.secret_key}")
print(f"QR code URI: {totp.qr_code_uri}")
# After user scans QR code and enters the code:
session = client.verify_totp(flow_id=totp.flow_id, code="482901")
print(session.authenticator_assurance_level) # "aal2"verify_totp()
from avnology_id.errors import InvalidCodeError
try:
session = client.verify_totp(code="482901")
except InvalidCodeError as e:
print(f"Invalid code. {e.attempts_remaining} attempts remaining")generate_recovery_codes()
codes = client.generate_recovery_codes()
print("Save these codes:")
for code in codes.codes:
print(f" {code}")verify_recovery_code()
session = client.verify_recovery_code(code="abc12-def34")disable_totp()
client.disable_totp()See also
- Login -- MFA during login
- Error types -- Exception classes