Skip to main content

Authenticate a user in a workflow with OpenID Connect

Workflow preview

Workflow preview
100%
Authenticate a user in a workflow with OpenID Connect preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

Intro This workflow needs a user to authenticate by using an openid connect provider in order to call the webhook. If the user is not authenticated, it starts a login process by using an Authorizat...

Best for

  • Engineering automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

n8n-nodes-base.webhook, n8n-nodes-base.code, n8n-nodes-base.httprequest, n8n-nodes-base.respondtowebhook, n8n-nodes-base.if, n8n-nodes-base.html, n8n-nodes-base.stickynote, n8n-nodes-base.set

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by please-open.it.

Original n8n.io source

1.1 Workflow description

Title
Authenticate a user in a workflow with OpenID Connect
Workflow name
Authenticate a user in a workflow with OpenID Connect

Intro

This workflow needs a user to authenticate by using an openid connect provider in order to call the webhook.

If the user is not authenticated, it starts a login process by using an Authorization Code with PKCE https://datatracker.ietf.org/doc/html/rfc7636, a standard way to authenticate users with openid connect.

Then, after the user logs in, the webhook is refreshed and gets the user's token from a cookie. With this token, all details about the user are requested through the userinfo endpoint on the identity provider.

How to set up with Keycloak

Keycloak Keycloak is an open source identity and access management solution.

Feel free to get a demo realm at https://please-open.it or get your own Keycloak server up and running.

After creating a realm, go to "Realm Settings" and click on "OpenID Endpoint Configuration"

Retrieve authorization_endpoint, token_endpoint and userinfo_endpoint values. Set those variables in the "Set variables" node.

In Keycloak, create a new client (name it as you want)

Disable the client authentication, check only "standard flow" :

At the third step, put the webhook url in "valid redirect URIs", fill "Web origins" with a "+".

You're done, open the webhook and it asks you to authenticate.

Usage

User informations

The userinfo node returns this structure about the user has logged in :

[
  {
    "sub":"73a6543f-f420-4fa6-9811-209e903c348b",
    "email_verified":true,
    "preferred_username": "[email protected]",
    "email": "[email protected]"
  }
]

I can use those infos in my workflow for custom operations.

APIs calls

the "code" node returns me a cookie named "n8n-custom-auth" which is the access_token returned by the identity provider. This access_token can be used to call APIs connected to this identity provider (for example, we call userinfo API with this token).

Example : asks a user to log in with his Google account then call an API (Gmail, drive...) with his own token.

How it works

We published a blog post about this flow, how it works and how you can use it : https://blog.please-open.it/n8n-openid-client/

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - Webhook

Type / Role
n8n-nodes-base.webhook - webhook
Config choices
Version 1

Block 2 - Code

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 3 - user info

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.1

Block 4 - send back login page

Type / Role
n8n-nodes-base.respondToWebhook - respondToWebhook
Config choices
Version 1

Block 5 - IF token is present

Type / Role
n8n-nodes-base.if - if
Config choices
Version 1

Block 6 - Welcome page

Type / Role
n8n-nodes-base.html - html
Config choices
Version 1

Block 7 - send back welcome page

Type / Role
n8n-nodes-base.respondToWebhook - respondToWebhook
Config choices
Version 1

Block 8 - IF user info ok

Type / Role
n8n-nodes-base.if - if
Config choices
Version 1

Block 9 - login form

Type / Role
n8n-nodes-base.html - html
Config choices
Version 1

Block 10 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 11 - Sticky Note1

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 12 - Sticky Note2

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 13 - Set variables : auth, token, userinfo, client id, scope

Type / Role
n8n-nodes-base.set - set
Config choices
Version 2

Block 14 - IF we have code in URI and not in PKCE mode

Type / Role
n8n-nodes-base.if - if
Config choices
Version 1

Block 15 - get access_token from /token endpoint with code

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.1

3. Summary Table

Workflow Authenticate a user in a workflow with OpenID Connect
Complexity advanced
Nodes 15
Categories Engineering
Author please-open.it
Published 29 Nov 2023

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/1997/1997.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Authenticate a user in a workflow with OpenID Connect do?

Intro This workflow needs a user to authenticate by using an openid connect provider in order to call the webhook. If the user is not authenticated, it starts a login process by using an Authorizat...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Engineering use case.