Auth0用户登录

高级

这是一个Engineering、DevOps、Product、IT Ops领域的自动化工作流,包含 16 个节点。主要使用 If、Set、Webhook、HttpRequest、StopAndError 等节点。 使用Auth0进行用户验证和登录

前置要求
  • HTTP Webhook 端点(n8n 会自动生成)
  • 可能需要目标 API 的认证凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "AS2Rj41p6OyA0xZK",
  "meta": {
    "instanceId": "7858a8e25b8fc4dae485c1ef345e6fe74effb1f5060433ef500b4c186c965c18",
    "templateCredsSetupCompleted": true
  },
  "name": "Auth0 用户登录",
  "tags": [],
  "nodes": [
    {
      "id": "25022573-c99e-40d2-88e2-a0e7a9780181",
      "name": "请求访问令牌",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1260,
        320
      ],
      "parameters": {
        "url": "={{ $json.domain }}/oauth/token",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"grant_type\": \"authorization_code\",\n  \"code\": \"{{ $json.query.code }}\",\n  \"client_id\": \"{{ $json.client_id }}\",\n  \"client_secret\": \"{{ $json.client_secret }}\",\n  \"redirect_uri\": \"{{ $json.my_server }}\",\n  \"audience\": \"{{ $json.domain }}/api/v2/\"\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "headerParameters": {
          "parameters": [
            {
              "name": "content-type",
              "value": "application/x-www-form-urlencoded"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "233d69ed-d835-4022-815e-e786706ec78a",
      "name": "获取用户信息",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1500,
        320
      ],
      "parameters": {
        "url": "={{ $('Set Application Details1').item.json.domain }}/userinfo",
        "options": {},
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $json.access_token }}"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "860e8a20-f6a3-4c8e-be71-361e6f1f8641",
      "name": "条件判断",
      "type": "n8n-nodes-base.if",
      "position": [
        720,
        320
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "fa80ac35-7029-4507-b5ea-845bec07b672",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{$json.query.code}}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "7c4e15c7-2ee0-4c54-8255-e7cc250e718a",
      "name": "未找到代码",
      "type": "n8n-nodes-base.stopAndError",
      "position": [
        880,
        540
      ],
      "parameters": {
        "errorMessage": "Couldn't get authorization code!"
      },
      "typeVersion": 1
    },
    {
      "id": "2e0b2ff5-47ce-4199-bdd2-e31a4d32fd15",
      "name": "打开认证网页",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        1020,
        40
      ],
      "parameters": {
        "options": {},
        "redirectURL": "={{ $json.domain }}/authorize?response_type=code&scope=openid+email+profile+image+name&client_id={{ $json.client_id }}&redirect_uri={{ $json.my_server }}/webhook/receive-token",
        "respondWith": "redirect"
      },
      "typeVersion": 1.1
    },
    {
      "id": "d790ce47-725a-4a69-b66f-f7e80e2d9e5e",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1180,
        80
      ],
      "parameters": {
        "color": 6,
        "width": 238.05017098334866,
        "height": 140.50170983348636,
        "content": "### 您还可以在授权 URL 末尾添加 &connection=github,让用户通过 Github、Facebook 等方式登录"
      },
      "typeVersion": 1
    },
    {
      "id": "1c5bb01a-0fed-4783-b18d-d8f7e818371c",
      "name": "设置应用详情",
      "type": "n8n-nodes-base.set",
      "position": [
        780,
        40
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "003d523a-5e14-4a5a-aed6-f72c3fce6e6d",
              "name": "domain",
              "type": "string",
              "value": ""
            },
            {
              "id": "7db513f3-55f6-4bab-92b0-e62d0b7f05a1",
              "name": "client_id",
              "type": "string",
              "value": ""
            },
            {
              "id": "52da7d5d-6683-4cf9-a7de-c2ab2ce48f3d",
              "name": "my_server",
              "type": "string",
              "value": ""
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "8ced9fb6-fd49-4d57-8d74-b04e45b6c216",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        80,
        -456.1003419666973
      ],
      "parameters": {
        "color": 5,
        "width": 623.7263504769883,
        "height": 397.87914003146636,
        "content": "## 1. 首先访问 https://auth0.com 并创建单页应用。从仪表板/应用程序中,点击新应用设置。第一步是将以下内容添加到允许的回调 URL:"
      },
      "typeVersion": 1
    },
    {
      "id": "94155312-1230-4c13-9104-5e26a6f68e91",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1280,
        -40
      ],
      "parameters": {
        "color": 6,
        "width": 437.4336297478876,
        "height": 107.35461655041311,
        "content": "### 此步骤将向用户返回认证页面,让他使用 Gmail 登录或创建新账户。"
      },
      "typeVersion": 1
    },
    {
      "id": "9a7bcabf-1cc0-43e5-8f52-cc3f2781150f",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        420,
        -40
      ],
      "parameters": {
        "width": 1296.8510714753793,
        "height": 256.53228919365705,
        "content": "## 步骤 1:认证"
      },
      "typeVersion": 1
    },
    {
      "id": "7e7560d6-4c26-4e80-ad62-07a674e928f9",
      "name": "便签4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        420,
        260
      ],
      "parameters": {
        "width": 1302.371850917427,
        "height": 444.78164181462137,
        "content": "## 步骤 2:获取访问令牌"
      },
      "typeVersion": 1
    },
    {
      "id": "97c8bc77-bc7d-4be2-9858-668c5e325f49",
      "name": "便利贴5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        420,
        560.9464093496792
      ],
      "parameters": {
        "color": 6,
        "width": 327.74230574931124,
        "height": 144.40136786678917,
        "content": "### 如果步骤 1 成功,Auth0 将在其回调中自动调用步骤 2 并附带一个代码。此代码用于生成访问令牌,可验证用户是否合法且邮箱已验证。"
      },
      "typeVersion": 1
    },
    {
      "id": "fe103ba1-8143-482c-846f-0f381ca2661a",
      "name": "设置应用详情1",
      "type": "n8n-nodes-base.set",
      "position": [
        1000,
        320
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "003d523a-5e14-4a5a-aed6-f72c3fce6e6d",
              "name": "domain",
              "type": "string",
              "value": ""
            },
            {
              "id": "7db513f3-55f6-4bab-92b0-e62d0b7f05a1",
              "name": "client_id",
              "type": "string",
              "value": ""
            },
            {
              "id": "52da7d5d-6683-4cf9-a7de-c2ab2ce48f3d",
              "name": "my_server",
              "type": "string",
              "value": ""
            },
            {
              "id": "d339dd3d-ed57-4b0f-81c6-a8f5f7c474fb",
              "name": "client_secret",
              "type": "string",
              "value": ""
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "b3bb59b8-16fc-483d-ae8d-ec3e65c3326d",
      "name": "/login",
      "type": "n8n-nodes-base.webhook",
      "position": [
        540,
        40
      ],
      "webhookId": "046e2370-0ae1-4d64-be9b-cbb0545de323",
      "parameters": {
        "path": "login",
        "options": {},
        "responseMode": "responseNode"
      },
      "typeVersion": 2
    },
    {
      "id": "79825832-6d06-4a48-aa0a-bad3d52ab2c1",
      "name": "/receive-token",
      "type": "n8n-nodes-base.webhook",
      "position": [
        540,
        320
      ],
      "webhookId": "7bd9ea5a-c354-41c0-9d17-4a02ca8e3055",
      "parameters": {
        "path": "receive-token",
        "options": {},
        "responseMode": "lastNode"
      },
      "typeVersion": 2
    },
    {
      "id": "b9406ef0-3567-46da-9989-d7f458ad73fb",
      "name": "便签 7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        760,
        -460
      ],
      "parameters": {
        "color": 5,
        "width": 426.62126002791706,
        "height": 393.48225931142105,
        "content": "## 2. 填写设置应用详情和设置应用详情1"
      },
      "typeVersion": 1
    }
  ],
  "active": true,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "7d2f0dad-3951-49e2-9467-03124dbc52ba",
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Set Application Details1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Code Found",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "/login": {
      "main": [
        [
          {
            "node": "Set Application Details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "/receive-token": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Request Access Token": {
      "main": [
        [
          {
            "node": "Get Userinfo",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Application Details": {
      "main": [
        [
          {
            "node": "Open Auth Webpage",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Application Details1": {
      "main": [
        [
          {
            "node": "Request Access Token",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

这是一个高级难度的工作流,适用于Engineering、DevOps、Product、IT Ops等场景。适合高级用户,包含 16+ 个节点的复杂工作流

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
高级
节点数量16
分类4
节点类型7
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

作者
Jay Hartley

Jay Hartley

@jay

Low-code/no-code developer for automated solutions. Several years experience in automated workflow building for content creation management, distribution and marketing.

外部链接
在 n8n.io 上查看 →

分享此工作流