jam.otp.base¶
__base__
¶
Classes:
| Name | Description |
|---|---|
BaseOTP |
Base *OTP. |
OTPConfig |
Config for Jam instance. |
BaseOTP
¶
BaseOTP(
secret: bytes | str,
digits: int = 6,
digest: Literal["sha1", "sha256", "sha512"] = "sha1",
)
Base *OTP.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
secret
|
bytes | str
|
Secret key(str or Byte32). |
required |
digits
|
int
|
Number of digits in the code. Default is 6. |
6
|
digest
|
str
|
Hash algorithm (sha1, sha256, sha512). Default is |
'sha1'
|
Methods:
| Name | Description |
|---|---|
at |
Generate OTP code. |
provisioning_uri |
Generates an otpauth:// URI for Google Authenticator. |
verify |
Verify OTP code. |
at
¶
at(factor: int | None = None) -> str
Generate OTP code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
factor
|
int | None
|
TOTP uses current time if None, HOTP uses counter. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
OTP code |
provisioning_uri
¶
provisioning_uri(
name: str,
issuer: str,
type_: str = "totp",
counter: int | None = None,
) -> str
Generates an otpauth:// URI for Google Authenticator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Account name (e.g., email). |
required |
issuer
|
str
|
Service name (e.g., "GitHub"). |
required |
type_
|
str
|
OTP type (“totp” or 'hotp'). Default is "totp". |
'totp'
|
counter
|
int | None
|
Counter (for HOTP). Default is None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A string of the form "otpauth://..." |
verify
¶
verify(
code: str,
factor: int | None = None,
look_ahead: int = 1,
) -> bool
Verify OTP code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
Code to verify |
required |
factor
|
int | None
|
TOTP uses current time if None, HOTP uses counter. |
None
|
look_ahead
|
int
|
How many intervals to check ahead |
1
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if valid |
OTPConfig
dataclass
¶
OTPConfig(
type: str,
digits: int,
digest: Literal["sha1", "sha256", "sha512"],
interval: int = 30,
)
Config for Jam instance.