Implement robust OIDC authentication within your applications using this detailed n8n workflow. Learn how to handle authorization codes, PKCE, and token exchange for seamless user login.
Download this n8n workflow template and start using it instantly.
• Developers needing a custom authentication layer for internal tools.
• Automation specialists building secure, access-controlled n8n templates.
• Users who need to integrate n8n directly with enterprise identity providers like Keycloak or Auth0.
• Security engineers looking for examples of robust token handling in a low-code environment.
Implementing secure user authentication often requires complex state management and interaction with authorization servers. This advanced n8n workflow template provides a robust solution for integrating OpenID Connect (OIDC) into any application served by n8n. It efficiently handles the authorization code flow, supports PKCE (Proof Key for Code Exchange) for enhanced security, manages token exchange, and processes user information retrieval. By utilizing a series of specialized n8n node configurations, this template ensures that users accessing the main webhook are either redirected through the authentication loop or granted access to the protected resource immediately if a valid session token is found. This saves significant development time compared to building a custom client from scratch.
The entire process is initiated by a user accessing the primary n8n trigger (the Webhook URL).
Webhook n8n node receives the inbound request. The Set variables n8n node defines critical OIDC parameters (authorization endpoint, token endpoint, client ID, scopes, etc.).Code n8n node executes custom JavaScript to parse the incoming request headers and extract any existing session cookies, specifically looking for a stored accesstoken.IF we have code in URI and not in PKCE mode n8n node checks if an authorization code is present in the URL query parameters (indicating a fresh redirect from the Identity Provider, or IdP) and if PKCE is disabled. If true, the get accesstoken from /token endpoint with code HTTP Request n8n node performs the token exchange.IF token is present n8n node checks if an accesstoken exists (either from a successful cookie extraction or the token exchange).user info HTTP Request n8n node uses the token as a Bearer authorization header to fetch the user's profile details from the OIDC userinfoendpoint.IF user info ok n8n node checks if user details (specifically email) were successfully retrieved.Welcome page HTML n8n node generates a personalized welcome message, and the send back welcome page n8n node responds to the initial request.login form HTML n8n node is displayed. This HTML contains embedded JavaScript that automatically triggers the OIDC authorization flow (including PKCE logic) by redirecting the user to the IdP's authentication endpoint. This redirects the browser back to the initial n8n webhook URL with the authorization code, restarting the n8n workflow logic to process the new code.To use this powerful n8n workflow, follow these steps:
Webhook n8n trigger is active. Note its full URL—this is your OIDC redirect URI.Set variables : auth, token, userinfo, client id, scope n8n node and input the required values from your Identity Provider (e.g., Keycloak):authendpoint, tokenendpoint, userinfoendpointclientid, clientsecret (if not using PKCE)scope (must include openid)redirecturi to the URL of the n8n trigger webhook. Webhook (n8n trigger): The entry point of the entire authentication flow, receiving initial requests and handling redirects from the OIDC IdP.
Set variables : auth, token, userinfo, client id, scope (Set n8n node): Crucial for defining all necessary OIDC endpoints, IDs, and configuration flags (like PKCE). All subsequent HTTP Requests use data dynamically retrieved from this n8n node.
Code (n8n node): Executes custom JavaScript to parse HTTP headers and extract cookies, specifically checking for a pre-existing accesstoken to bypass the login process.
IF nodes (IF token is present, IF user info ok): These corelogicflowcontrol n8n node components manage the conditional routing, determining if the user needs to be redirected to the IdP or if they have sufficient credentials to proceed.
get accesstoken from /token endpoint with code (HTTP Request n8n node): Used in the non-PKCE flow to exchange the authorization code for an accesstoken by posting credentials to the token endpoint.
user info (HTTP Request n8n node): Fetches the authenticated user's profile details using the Bearer access_token, ensuring the token is valid and associated with a user.
login form contains the embedded PKCE JavaScript logic required to initiate the secure OIDC authorization process and handle the subsequent token exchange. The success path uses the Welcome page HTML n8n node.Use this robust n8n workflow to automate website security header audits. Score results, trigger AI remediation suggestions using LLMs, and log detailed reports directly to Google Sheets. A perfect example of advanced n8n templates for DevOps and security teams.

Automate interview feedback quality audits using this n8n workflow. It leverages GPT-4o-mini to score responses, updates Google Sheets, and sends tailored coaching reports via Slack.

Use this comprehensive n8n workflow to automate daily security auditing of Google Drive file permissions. Identify files shared externally or publicly, log them in Google Sheets, and receive detailed reports via Gmail.

Automate your entire content pipeline using this powerful n8n workflow. Manage blog ideas in Google Sheets, generate drafts with AI, and automatically publish to WordPress.

Automate bug tracking by syncing Zendesk tickets tagged 'bug' into a centralized Google Sheets dashboard using this robust n8n workflow. Use this n8n template to streamline QA and support reporting.

This powerful n8n workflow automates daily ingestion of CVE and IOC threat feeds, applies custom AI logic for risk triage, and triggers incident response actions like email alerts, Google Sheets logging, and EDR isolation requests. Use this n8n template for compliant security operations.

Authentication consultant with over 6 years experience, we can help companies with their SSO, especially with Keycloak







































