Secure Two-Factor Authentication (TOTP) Code Generation - n8n Workflow

Use this practical n8n workflow to generate secure Time-based One-Time Passwords (TOTP) programmatically. Quickly implement 2FA using the dedicated n8n node.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

n8n Nodes Used

Who is this best for?

Automation developers who need to integrate 2FA into external services.
Users looking to secure API calls or login sequences within a larger n8n workflow.
Teams evaluating the security utilities provided by native n8n templates.
System administrators automating secure access flows.

Overview

Security is paramount in modern automation, and Two-Factor Authentication (2FA) using TOTP (Time-based One-Time Password) is a standard requirement. This n8n workflow provides a direct, reliable method to generate these security codes directly within your n8n environment. Instead of relying on external authenticator apps for automated processes, this n8n template allows the system itself to generate the necessary code, making complex secure integrations straightforward.

This simple, yet powerful n8n workflow demonstrates the immediate utility of the TOTP n8n node, enabling developers to build highly secure, credential-dependent automation pipelines. It acts as a foundational component for automating logins where a TOTP challenge is present.

How it Works

The entire process of this n8n workflow is executed in two steps:


  1. Start Execution (n8n trigger): The process begins with the Manual Trigger n8n node, which is activated when the user clicks 'Test workflow' or manually executes the workflow.

  2. TOTP Generation: The flow immediately passes control to the specialized TOTP n8n node. This node retrieves a pre-configured secret key stored securely in n8n credentials. Using this secret key and the current time, the TOTP n8n node calculates and outputs the six-digit, time-sensitive code.

  3. Output: The final output of the n8n workflow is the currently valid TOTP code, which can then be seamlessly passed to subsequent nodes for use in login forms or API authentication headers.

Installation Guide

To deploy and utilize this foundational n8n workflow, follow these steps:


  1. Import the n8n template: Copy the provided JSON and import it into your self-hosted or cloud n8n instance.

  2. Create TOTP Credentials: Before running the TOTP n8n node, you must set up the necessary credentials. When prompted by the node, create a new credential for 'TOTP API'.

  3. Enter Secret Key: In the credential setup, you will need to input the Base32 secret key provided by the service you wish to authenticate against (e.g., the key you would typically scan into Google Authenticator).

  4. Save and Activate: Save the credential. Ensure the TOTP n8n node is correctly linked to this new credential (named 'TOTP account Mars55' in the provided JSON).

  5. Test the n8n workflow: Click 'Test workflow' on the Manual Trigger n8n node to generate your first TOTP code and confirm successful configuration. This verifies that your n8n trigger is correctly linked to the functional node.

Node Details

When clicking ‘Test workflow’ (Manual Trigger):
Function: Serves as the initial n8n trigger for the workflow. It allows for quick, manual testing and immediate code generation.
Key Configuration: Standard manual trigger setup.

TOTP (TOTP n8n node):
Function: The core functional element of this n8n workflow. It uses a secure credential to generate a time-based one-time password.
Key Configuration: Relies heavily on the 'TOTP API' credential, which securely stores the Base32 secret key necessary for calculation.

Related n8n Workflows

Free

Nodes: 2 Nodes
Updated: December 26 2025
View all
Created by

Hi ! I'm Amirhossein Mansouri Zade, a student with 4 years of experience in SEO and search engine optimization. Currently, I'm focused on solving various problems and challenges. I’m gradually transitioning into the product field and enjoy building the tools I need using N8N. I'll be sharing my workflows and experiences here along the way. 🚀

Featured*