s365b.auth.totp

Time-based one-time passwords (RFC 6238) for break-glass accounts.

Attributes

Functions

new_secret() → str

Create a new random TOTP secret.

provisioning_uri(secret, username, issuer) → str

Return the otpauth:// URI shown as a QR code during enrolment.

verify(secret, code, last_step, *[, now]) → int | None

Verify a TOTP code, rejecting replays.

Module Contents

s365b.auth.totp.STEP_SECONDS = 30[source]
s365b.auth.totp.new_secret() → str[source]

Create a new random TOTP secret.

Returns:

Base32 secret.

s365b.auth.totp.provisioning_uri(secret: str, username: str, issuer: str) → str[source]

Return the otpauth:// URI shown as a QR code during enrolment.

Parameters:
  • secret – Base32 secret.

  • username – Account name shown in the authenticator app.

  • issuer – Product name shown in the authenticator app (from branding).

Returns:

The URI.

s365b.auth.totp.verify(secret: str, code: str, last_step: int | None, *, now: float | None = None) → int | None[source]

Verify a TOTP code, rejecting replays.

Accepts the current code and the one before or after (clock drift), but never a code from a time step at or before last_step.

Parameters:
  • secret – Base32 secret.

  • code – Six-digit code from the user.

  • last_step – Time step of the last accepted code for this account.

  • now – Current Unix time (tests).

Returns:

The matched time step (store it as the new last_step), or None if the code is wrong or was already used.