Skip to content

second_factor

A second factor at sign-in: an authenticator app's codes, and recovery codes.

An account may add a time-based code from an authenticator app (RFC 6238) to its password. A sign-in of such an account answers a challenge after the password, and completes with a code, or one of the account's ten recovery codes, each of which works once. The recovery codes are the way back for someone who loses the app: they are made when the app is added, shown with its QR code, and work once the app is confirmed. Turning two-step sign-in on also takes a code emailed to the account's address. These are the bodies of /auth/login/mfa, /user/mfa and below.

SecondFactorActivated pydantic-model

Bases: BaseModel

The factor confirmed: which recovery codes now work, and a new session.

The recovery codes the enrolment answered now work, and any made earlier no longer do. Every other session of the account has ended; tokens replaces the one that confirmed, now verified with the factor.

Fields:

tokens pydantic-field

The session that replaces this one.

SecondFactorChallenge pydantic-model

Bases: BaseModel

The answer to a password sign-in of an account with a second factor.

No session yet: the password was right, and the sign-in completes with POST /auth/login/mfa, naming challenge and a code from the account's authenticator app, or one of its recovery codes. The challenge is single-use, lasts five minutes and takes five codes.

Fields:

challenge pydantic-field

What the second step names.

expires_at pydantic-field

When the challenge lapses.

mfa_required = True pydantic-field

Always true: the sign-in needs its second step.

SecondFactorConfirmation pydantic-model

Bases: BaseModel

Confirm an enrolment: a current code from the new app, and when turning two-step sign-in on, the emailed code.

Whether the account already has an app is judged here, so the emailed code is asked for whenever it has none. recovery_codes_made_at names the enrolment, so the codes that start working are the ones this client showed.

Config:

  • extra: forbid

Fields:

code pydantic-field

The new authenticator app's current code.

email_code = None pydantic-field

The code emailed to the account's address, when turning two-step sign-in on.

recovery_codes_made_at = None pydantic-field

The recovery_codes_made_at the enrolment answered, naming the enrolment this confirms. One started again since, for example in another tab, is refused (mfa_enrolment_replaced) rather than confirmed with recovery codes this client never showed. A client that leaves it out confirms whichever enrolment waits.

SecondFactorDisable pydantic-model

Bases: BaseModel

Turn the factor off: the password, and a current code or a recovery code.

Config:

  • extra: forbid

Fields:

Validators:

  • _one_proof

code = None pydantic-field

The authenticator app's current code.

recovery_code = None pydantic-field

One of the account's recovery codes, in place of a code.

SecondFactorDisabled pydantic-model

Bases: MessageResponse

The factor is off; every other session has ended, and this one is replaced.

Fields:

tokens pydantic-field

The session that replaces this one.

SecondFactorEnrolment pydantic-model

Bases: BaseModel

The new secret and its recovery codes, shown once, for the person to save and add to their app.

Nothing counts until a code from the app confirms it (POST /user/mfa/enrolment/confirm), within expires_at. The recovery codes do not work until then either; during a replacement, the earlier ones work until it is confirmed. Save them before confirming: they are not shown again.

Fields:

email_code_required pydantic-field

Whether the confirmation also takes a code emailed to the account's address, as turning two-step sign-in on does. When true, one is on its way, and it works for 15 minutes.

expires_at pydantic-field

When the enrolment lapses unconfirmed.

otpauth_uri pydantic-field

The otpauth:// URI the QR code holds.

qr_svg pydantic-field

The QR code of the URI as an SVG document, drawn by the server: never sent to a QR service.

recovery_codes pydantic-field

Ten recovery codes, each working once in place of a code, from when the enrolment is confirmed.

secret pydantic-field

The secret in Base32, to type into the app.

SecondFactorEnrolmentStart pydantic-model

Bases: BaseModel

Start adding a factor, or replacing the one in use.

The password, so a session alone cannot add a factor; and when replacing, the current code or one of the recovery codes too. Someone who has lost the app replaces it with a recovery code, which then stops working. Turning two-step sign-in on takes neither: its confirmation takes a code emailed to the account's address instead.

Config:

  • extra: forbid

Fields:

Validators:

  • _at_most_one_proof

code = None pydantic-field

The current code, when the account already has a factor.

recovery_code = None pydantic-field

One of the account's recovery codes, in place of a code.

SecondFactorRecoveryCodes pydantic-model

Bases: BaseModel

New recovery codes, shown this once; the earlier ones no longer work.

Fields:

recovery_codes pydantic-field

Ten recovery codes, each working once in place of a code.

SecondFactorRecoveryCodesRequest pydantic-model

Bases: BaseModel

Make new recovery codes: the password, and a current code or a recovery code.

Config:

  • extra: forbid

Fields:

Validators:

  • _one_proof

code = None pydantic-field

The authenticator app's current code.

recovery_code = None pydantic-field

One of the account's recovery codes, in place of a code.

SecondFactorSignIn pydantic-model

Bases: BaseModel

The second step of a sign-in: the challenge and one proof.

code is the six-digit code the authenticator app shows; recovery_code one of the account's ten recovery codes, which then stops working. Exactly one is given. Spaces are ignored, and a recovery code's dash and case too.

Config:

  • extra: forbid

Fields:

Validators:

  • _one_proof

challenge pydantic-field

The challenge the password step answered.

code = None pydantic-field

The authenticator app's current code.

recovery_code = None pydantic-field

One of the account's recovery codes, in place of a code.

SecondFactorState pydantic-model

Bases: BaseModel

The account's second factor, as GET /user/mfa answers it.

Fields:

activated_at = None pydantic-field

When the factor in use was confirmed.

available pydantic-field

Whether this account can add a second factor now: the server offers one to it, to administrators only or to everyone, and can seal it. False, none can be added; a factor already in use keeps working either way.

can_disable = False pydantic-field

Whether the account may turn its factor off. An administrator's is only replaced, by enrolling again.

enabled pydantic-field

Whether the account has a factor in use.

recovery_codes_left = 0 pydantic-field

How many of the account's recovery codes are unused.