gws.lib.otp
¶
Generate HOTP and TOTP tokens.
References
https://datatracker.ietf.org/doc/html/rfc4226 https://datatracker.ietf.org/doc/html/rfc6238
Source code: gws.lib.otp
Package Contents¶
- gws.lib.otp.base32_decode(s: str) bytes ¶
- gws.lib.otp.base32_encode(s: str | bytes) str ¶
- gws.lib.otp.check_totp(input: str, secret: str, timestamp: int, options: Options | None = 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)
.
- gws.lib.otp.DEFAULTS¶
- gws.lib.otp.hotp_key_uri(secret: str | bytes, issuer_name: str, account_name: str, counter: int | None = None, options: Options | None = None) str ¶
- gws.lib.otp.new_hotp(secret: str | bytes, counter: int, options: Options | None = None) str ¶
Generate a new HOTP value as per rfc4226 section 5.3.
- gws.lib.otp.new_totp(secret: str | bytes, timestamp: int, options: Options | None = None) str ¶
Generate a new TOTP value as per rfc6238 section 4.2.
- class gws.lib.otp.Options(*args, **kwargs)¶
Bases:
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.- algo: str¶
- length: int¶
- start: int¶
- step: int¶
- tolerance: int¶
- gws.lib.otp.random_secret(base32_length: int = 32) str ¶
Generate a random printable secret that fits into base32_length.