:tocdepth: 3 :py:mod:`gws.lib.otp` ===================== .. py:module:: gws.lib.otp .. autoapi-nested-parse:: Generate HOTP and TOTP tokens. .. rubric:: References https://datatracker.ietf.org/doc/html/rfc4226 https://datatracker.ietf.org/doc/html/rfc6238 **Source code:** :source:`gws.lib.otp` Package Contents ---------------- .. py:function:: base32_decode(s: str) -> bytes .. py:function:: base32_encode(s: str | bytes) -> str .. py:function:: check_totp(input: str, secret: str, timestamp: int, options: Optional[Options] = None) -> bool Check if the input TOTP is valid. Compares the input against several TOTPs within the tolerance window ``(timestamp-step*tolerance...timestamp+step*tolerance)``. .. py:data:: DEFAULTS .. py:function:: hotp_key_uri(secret: str | bytes, issuer_name: str, account_name: str, counter: Optional[int] = None, options: Optional[Options] = None) -> str .. py:function:: new_hotp(secret: str | bytes, counter: int, options: Optional[Options] = None) -> str Generate a new HOTP value as per rfc4226 section 5.3. .. py:function:: new_totp(secret: str | bytes, timestamp: int, options: Optional[Options] = None) -> str Generate a new TOTP value as per rfc6238 section 4.2. .. py:class:: Options(*args, **kwargs) Bases: :py:obj:`gws.Data` Basic data object. This object can be instantiated by passing one or or ``dict`` arguments and/or keyword args. All dicts keys and keywords become attributes of the object. Accessing an undefined attribute returns ``None`` and no error is raised, unless the attribute name starts with an underscore. .. py:attribute:: algo :type: str .. py:attribute:: length :type: int .. py:attribute:: start :type: int .. py:attribute:: step :type: int .. py:attribute:: tolerance :type: int .. py:function:: random_secret(base32_length: int = 32) -> str Generate a random printable secret that fits into base32_length. .. py:function:: totp_key_uri(secret: str | bytes, issuer_name: str, account_name: str, options: Optional[Options] = None) -> str