1. Opening Problem Statement
Imagine you’re Ali, an IT administrator responsible for managing access controls across multiple secure systems. Every time Ali needs a fresh two-factor authentication code to log in, he manually opens an authentication app, copies the Time-Based One-Time Password (TOTP), and quickly inputs it before it expires. This manual process is not only time-consuming but prone to delays and occasional errors that lock Ali out, especially during critical operations. Ali wastes several minutes daily just generating TOTP codes manually, accumulating to hours of lost productivity per month.
Manually handling TOTP generation also increases the risk of human error, especially in environments requiring frequent multi-account authentications. Ali’s challenge is clear: How can he automate the generation of these secure, time-sensitive authentication codes to save time and ensure login reliability?
2. What This Automation Does
This n8n workflow provides a simple yet powerful solution that automatically generates a fresh TOTP code with a single click. Here is what happens when you run this workflow:
- Instant TOTP Code Generation: Generates a valid TOTP code according to your configured secret.
- Manual Trigger: You control when the code is generated by clicking the “Test workflow” button, giving you flexibility.
- Secure Credential Management: Your TOTP secret key is safely stored and accessed via n8n’s credential system, ensuring security.
- Timezone Awareness: The workflow respects your timezone settings to generate time-accurate codes.
- Easy Integration: This setup can be extended or integrated with other n8n workflows to automate login sequences or notifications.
- Zero External Dependencies: Generates TOTP codes locally without relying on external APIs or services.
By automating TOTP code generation, users like Ali save valuable time and eliminate manual errors, enhancing secure access practices significantly.
3. Prerequisites ⚙️
- n8n account for building and running the workflow.
- TOTP credentials configured in n8n with your secret key through the TOTP node’s credential system 🔐.
- Manual Trigger node to initiate the TOTP code generation.
- Optional: Self-hosting setup possible for private control; see Hostinger n8n hosting guide.
4. Step-by-Step Guide
Step 1: Create a New Workflow and Add a Manual Trigger Node
Open your n8n editor and click “New Workflow”. Then, in the node panel, search for Manual Trigger and drag it into the canvas.
This node will allow you to start your workflow by clicking the Execute Workflow button manually, perfect for generating TOTP codes on demand.
After adding, name it When clicking ‘Test workflow’ to match the workflow example.
Common mistake: Don’t forget to connect this node to the TOTP node to pass the trigger signal.
Step 2: Add the TOTP Node
Next, add the TOTP node from the node list. This node handles generating your one-time password codes.
Connect the output of the Manual Trigger node to the input of the TOTP node.
Visual clue: You should see a wire connecting the two nodes once connected.
Step 3: Configure Your TOTP Credentials
In the TOTP node settings, select your existing TOTP credentials or create new ones:
- Click on the Credentials dropdown in the TOTP node.
- If you haven’t set up TOTP credentials yet, click “Create New” and input your secret key obtained from your authentication setup.
- Name it descriptively, e.g., “TOTP account Mars55”, as in this workflow.
Tip: Store credentials securely and never share your secret codes.
Step 4: Set Timezone Preference
In your workflow settings, confirm that the timezone is properly set (in this case, it’s Asia/Tehran). This ensures your TOTP codes are accurate according to the local time.
Step 5: Test the Workflow
Click the Execute Workflow button on the Manual Trigger node.
The TOTP node executes instantly and outputs a fresh TOTP code based on your secret.
Expected result: You see the generated TOTP code in the execution result panel.
Step 6: Use the Generated TOTP
Use the generated TOTP code immediately for your login or on other systems requiring 2FA codes.
Step 7: Extend or Integrate
Consider extending this workflow by adding nodes that send the code via email, SMS, or chat apps, enabling automated secure delivery.
5. Customizations ✏️
- Change TOTP Account: In the TOTP node, select different TOTP credentials to generate codes for various accounts.
- Automatic Trigger: Replace the Manual Trigger with a Cron node to generate and deliver codes at scheduled intervals.
- Output Formatting: Add a Code node after the TOTP node to format or concatenate the code with custom messages for easier use.
6. Troubleshooting 🔧
Problem: “TOTP code does not generate or is incorrect”
Cause: Incorrect secret key or timezone mismatch.
Solution: Double-check your TOTP credential’s secret and ensure your workflow timezone matches your local time exactly.
Problem: “Manual Trigger does not start workflow”
Cause: Misconnected nodes or workflow not activated.
Solution: Ensure the Manual Trigger node is connected to the TOTP node and the workflow is activated before testing.
7. Pre-Production Checklist ✅
- Verify TOTP credentials are correctly entered and saved in n8n.
- Test manual triggering produces a valid TOTP code immediately.
- Confirm timezone settings align with your locale.
- Backup workflow before making changes.
8. Deployment Guide
Activate your workflow by toggling the switch to live mode in n8n’s workflow editor.
You can now generate TOTP codes instantly on demand.
For scaling, consider integrating notifications or secure code delivery nodes.
Use n8n’s execution logs to monitor TOTP generation history for troubleshooting and audit.
9. FAQs
Q: Can I use this workflow without storing TOTP credentials in n8n?
A: No, the TOTP node requires credentials to generate codes securely.
Q: Does generating TOTP codes consume API credits?
A: No, it runs locally within n8n without external API calls.
Q: Can I schedule TOTP generation?
A: Yes, by swapping the Manual Trigger with a Cron Trigger node.
10. Conclusion
By following this guide, you’ve set up a secure, automated n8n workflow to generate TOTP codes on demand. You’ve saved valuable time and reduced login errors through automation.
Next, you might consider automating delivery of these codes through email or messaging services, or integrate this with full login workflows for seamless secure access.
Keep experimenting and enhancing your automation skills — secure authentication just got easier with n8n!