s365b.auth.totp =============== .. py:module:: s365b.auth.totp .. autoapi-nested-parse:: Time-based one-time passwords (RFC 6238) for break-glass accounts. Attributes ---------- .. autoapisummary:: s365b.auth.totp.STEP_SECONDS Functions --------- .. autoapisummary:: s365b.auth.totp.new_secret s365b.auth.totp.provisioning_uri s365b.auth.totp.verify Module Contents --------------- .. py:data:: STEP_SECONDS :value: 30 .. py:function:: new_secret() -> str Create a new random TOTP secret. :returns: Base32 secret. .. py:function:: provisioning_uri(secret: str, username: str, issuer: str) -> str Return the ``otpauth://`` URI shown as a QR code during enrolment. :param secret: Base32 secret. :param username: Account name shown in the authenticator app. :param issuer: Product name shown in the authenticator app (from branding). :returns: The URI. .. py:function:: verify(secret: str, code: str, last_step: int | None, *, now: float | None = None) -> int | None 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``. :param secret: Base32 secret. :param code: Six-digit code from the user. :param last_step: Time step of the last accepted code for this account. :param 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.