TOTP

Generate a time-based one-time password

Overview

This node generates a Time-based One-Time Password (TOTP) token based on a provided TOTP key. TOTPs are commonly used for two-factor authentication (2FA) to enhance security by generating temporary codes that change every fixed interval (usually 30 seconds). This node is useful in automation workflows where you need to generate such tokens dynamically, for example, to authenticate API requests or logins requiring 2FA.

Practical examples:

  • Automatically generating a TOTP code to authenticate with an external service that requires 2FA.
  • Integrating TOTP generation into a workflow that triggers secure access or verification steps.

Properties

Name Meaning
TOTP Key The secret key used to generate the TOTP token. This is typically a base32 encoded string shared between the client and server for generating synchronized codes.

Output

The node outputs JSON data containing two fields:

  • code: The generated TOTP token as a string.
  • secondsRemaining: The number of seconds remaining before the current TOTP token expires and a new one is generated.

Example output JSON:

{
  "code": "123456",
  "secondsRemaining": 15
}

This output allows downstream nodes to use the current valid TOTP code and know how long it remains valid.

Dependencies

  • The node depends on the otpauth library to generate the TOTP tokens.
  • No additional external services or API keys are required beyond providing the TOTP secret key.
  • No special environment variables or n8n credentials are needed.

Troubleshooting

  • Invalid TOTP Key: If the provided TOTP key is incorrect or malformed, the generated code may be invalid or cause errors. Ensure the key is correctly copied and formatted (usually base32).
  • Time Synchronization Issues: Since TOTP relies on time synchronization, if the system clock is significantly off, generated codes may not match expected values. Verify the system time is accurate.
  • Empty TOTP Key: Providing an empty TOTP key will result in invalid token generation. Always provide a valid secret key.

Common error messages might relate to invalid secret format or issues initializing the TOTP generator. Double-check the input key and ensure it matches the expected format.

Links and References

Discussion