Overview
This node generates a time-based one-time password (TOTP) secret code based on a provided OTP secret key. It is useful for implementing two-factor authentication (2FA) or other security mechanisms requiring time-sensitive codes. For example, it can generate a 6-digit TOTP code valid for 30 seconds using the SHA1 algorithm, which can be used to verify user identity during login.
Use Case Examples
- Generating a TOTP code for a user login verification process.
- Creating a time-sensitive token for secure API access.
Properties
| Name | Meaning |
|---|---|
| OTP Secret Key | The base32 encoded secret key used to generate the TOTP code. Required input. |
| Options | Additional settings for TOTP generation including algorithm, number of digits, and validity period. |
Output
JSON
token- The generated TOTP code as a string.secondsRemaining- Number of seconds remaining before the current TOTP code expires.validUntil- ISO timestamp indicating when the current TOTP code will expire.
Dependencies
- otpauth library for TOTP generation
- date-fns and @date-fns/utc for date and time calculations
Troubleshooting
- Ensure the OTP secret key is correctly base32 encoded and contains no spaces.
- If the generated token is not valid, verify that the system time is accurate as TOTP depends on synchronized time.
- Common errors may include invalid secret key format or unsupported algorithm selection. Verify input parameters and supported algorithms.
Links
- otpauth GitHub Repository - Library used for generating TOTP codes.
- TOTP Algorithm Explanation - Background information on how time-based one-time passwords work.