In-Workflow TOTP Code Validation with Python
detail.loadingPreview
This workflow provides a robust solution for validating Time-based One-Time Passwords (TOTP) directly within n8n using a custom Python Code node. It allows you to securely verify 6-digit authentication codes against their corresponding Base32 secrets without relying on external services or n8n's credential store for the secrets themselves. Ideal for enhancing authentication flows in your automated processes.
About This Workflow
This n8n template empowers you to implement secure TOTP (Time-based One-Time Password) validation entirely within your workflow. Leveraging a custom Python script in a 'Code' node, it decodes Base32 secrets, generates expected TOTP codes, and verifies user-provided codes against them. This self-contained approach means you don't need to manage TOTP secrets in n8n's credential store, making it highly flexible. The workflow provides clear outputs, enabling conditional logic based on validation success or failure. It's a powerful tool for integrating strong two-factor authentication into various applications and systems, such as user login, secure API access, or internal tool access control.
Key Features
- Self-Contained TOTP Logic: All TOTP generation and validation logic is embedded directly within a Python Code node, ensuring portability and reducing external dependencies.
- Base32 Secret Support: Easily handle standard Base32 encoded TOTP secrets for compatibility with most authenticator apps.
- Flexible Integration: Verify 6-digit TOTP codes from any source, allowing seamless integration into custom authentication systems or user management workflows.
- Clear Validation Output: Returns a simple
status(1 for valid, 0 for invalid) for straightforward conditional branching and subsequent actions. - No External Credential Storage Needed: Manage TOTP secrets within your existing databases or systems, rather than n8n's credential management, for enhanced control.
How To Use
- Import the Workflow: Download and import this workflow JSON into your n8n instance.
- Locate the 'TOTP VALIDATION' Node: This is the core Python node responsible for the validation.
- Configure Input Values:
-
Open the 'TOTP VALIDATION' node.
-
Scroll to lines 39 and 40 in the Python code block: python secret = _input.item.json.totp_secret_example # Secret key base32 (example) code = _input.item.json.code_to_verify_example # Code to check (example)
-
Crucially, replace
_input.item.json.totp_secret_exampleand_input.item.json.code_to_verify_examplewith the actual expressions that retrieve your TOTP secret (Base32 encoded) and the code to be verified. These values will typically come from a preceding node (e.g., a database query, a webhook payload).
-
- Connect Your Data Source: Ensure a previous node in your workflow provides the
totp_secretand thecode_to_verifyto the 'TOTP VALIDATION' node. - Utilize the 'IF CODE IS VALID' Node: The workflow is set up with an 'IF' node that checks the output
status. Connect your "Code Valid" actions to the true branch and "Code Invalid" actions to the false branch. - Test the Workflow: Use the 'EXAMPLE FIELDS' node for initial testing, then replace with your real data sources.
Apps Used
Workflow JSON
{
"id": "778b4861-cf6f-4e8d-a36c-e0521c6c42dc",
"name": "In-Workflow TOTP Code Validation with Python",
"nodes": 6,
"category": "DevOps",
"status": "active",
"version": "1.0.0"
}Note: This is a sample preview. The full workflow JSON contains node configurations, credentials placeholders, and execution logic.
Get This Workflow
ID: 778b4861-cf6f...
About the Author
Free n8n Workflows Official
System Admin
The official repository for verified enterprise-grade workflows.
Statistics
Related Workflows
Discover more workflows you might like
Effortless Bug Reporting: Slack Slash Command to Linear Issue
Streamline your bug reporting process by instantly creating Linear issues directly from Slack using a simple slash command. This workflow enhances team collaboration by providing immediate feedback and a structured approach to logging defects, saving valuable time for development and QA teams.
Automate Qualys Report Generation and Retrieval
Streamline your Qualys security reporting by automating the generation and retrieval of reports. This workflow ensures timely access to crucial security data without manual intervention.
Automated PR Merged QA Notifications
Streamline your QA process with this automated workflow that notifies your team upon successful Pull Request merges. Leverage AI and vector stores to enrich notifications and ensure seamless integration into your development pipeline.