Skip to content

设置 OIDC(Set up OIDC)#

Feature availability

  • Available on Enterprise plans.
  • You need to be an instance owner or admin to enable and configure OIDC.

设置并启用 OIDC(Setting up and enabling OIDC)#

  1. 在 n8n 中,前往 设置 > 单点登录 (SSO)
  2. 选择认证协议 下拉菜单中,选择 OIDC
  3. 复制显示的重定向 URL(例如,https://yourworkspace.app.n8n.cloud/rest/sso/oidc/callback)。

    负载均衡器或代理的额外配置

    如果你在负载均衡器后运行 n8n,请确保设置 N8N_EDITOR_BASE_URL 环境变量

  4. 使用你的身份提供者(IdP)设置 OIDC。你需要:

    • 在你的身份提供商 (IdP) 中创建一个新的 OIDC 客户端/应用。
    • 配置上一步中的重定向 URL。
    • 记下你的身份提供者(IdP)提供的客户端ID客户端密钥
  5. 在你的身份提供商(IdP)中,找到发现端点(也称为知名配置端点)。它通常具有以下格式:

    1
    https://your-idp-domain/.well-known/openid-configuration
    
  6. 在 n8n 中,完成 OIDC 配置:

    • 发现端点:输入你身份提供者(IdP)的发现端点 URL。
    • 客户端ID:输入你在向身份提供商(IdP)注册应用时收到的客户端ID。
    • 客户端密钥:输入你在向身份提供商注册应用时收到的客户端密钥。
  7. 选择 保存设置
  8. 将 OIDC 设置为 已激活

实例和项目访问权限配置(Instance and project access provisioning)#

从版本 1.122.2 起,n8n 支持从你的身份提供商 (IdP) 配置实例角色和项目角色。

🌐 From version 1.122.2 upwards, n8n supports provisioning the instance role and project roles from your IdP.

你需要在你的 OIDC 授权服务器中添加一个名为 n8n 的额外作用域。

🌐 You need to add a an additional scope called n8n to your OIDC authorization server.

在这个 n8n 范围内,你需要添加这两个声明:

🌐 On this n8n scope, you need to add these two claims:

名称 数据类型 作用域 令牌类型
n8n_instance_role 字符串 n8n ID
n8n_projects 字符串数组 n8n ID

这两个需要始终包含在你的授权服务器提供的“ID 令牌”中。

🌐 These two need to always be included in the "ID Token" from your authorization server.

确保在有权访问 n8n 的身份提供商用户组中配置了这两个属性。

🌐 Ensure that these two attributes are configured in the user groups of your identity provider that have access to n8n.

在 n8n 的 设置 > SSO 页面上的表单中,你会在表单中找到一个名为“用户角色配置”的下拉菜单。

🌐 Inside the form on the Settings > SSO page in n8n, you will find a dropdown labeled "User role provisioning" in the form.

默认情况下,此项设置为“在 n8n 中管理”。

🌐 By default this is set to "Manged in n8n".

你可以选择将其设置为:

🌐 You can choose to set it to:

  • 实例角色
    • 每个已配置用户的实例角色只会从 SAML 响应中的 n8n_instance_role 属性读取。项目访问仍将仅在 n8n 内管理。
    • 如果你的身份提供商(IdP)上没有配置 n8n_instance_role 的值,则会使用 global:member 角色作为备用。
  • 实例和项目角色
    • 每个已配置用户的实例角色和项目访问权限将从 SAML 响应中的 n8n_instance_rolen8n_projects 属性中读取。

现有访问权限将被覆盖

一旦启用“用户角色配置”,下次任何用户使用 SAML 登录时,所有在 n8n 内授予但未反映在 n8n_instance_role 和 n8n_projects 中的访问权限都将从该用户中移除。

在激活此功能时,你需要在保存此更改之前下载两个 CSV 文件。这些文件包含你当前的所有访问设置,以便日后参考。

配置 n8n_instance_role 属性

n8n_instance_role 属性是一个简单的字符串,用于配置身份提供商 (IdP) 上的组或用户。

🌐 The n8n_instance_role attribute is a simple string configured for a group or user on your IdP.

支持的实例角色:

🌐 Supported instance roles are:

  • global:member
  • global:admin

配置 n8n_projects 属性

n8n_projects 属性是一个字符串数组,用于配置身份提供商 (IdP) 上的组或用户。

🌐 The n8n_projects attribute is a string array configured for a group or user on your IdP.

此数组中的每个元素都需要遵循以下格式: :

例如:

🌐 For example:

  • bHsykgeFirmIhezz:viewer
  • 4K3zrg3DvlMFFTB7:编辑
  • dCjnYuEpYOUBVaNe:admin

对于使用身份提供商 (IdP) 启用项目访问权限配置时已有的访问设置,你可以在下载的 CSV 文件中找到项目 ID。

🌐 For existing access settings at the time of enabling project access provisioning using your IdP, you can find the project IDs in the downloaded CSV file.

从头开始创建项目时,请在浏览器中查看项目时从 URL 获取项目 ID。

🌐 When creating a project from scratch, get the project ID from the URL when viewing the project in your browser:

例如,在 URL <your-domain>/projects/VVRWZaq5DRxaf9O1/workflows 中,项目 ID 是 VVRWZaq5DRxaf9O1

🌐 In the URL <your-domain>/projects/VVRWZaq5DRxaf9O1/workflows for example, the project ID is VVRWZaq5DRxaf9O1.

特定提供商的 OIDC 设置(Provider-specific OIDC setup)#

Okta#

在 Okta 中设置 OIDC 的步骤与下文所述的 Auth0 类似。

🌐 The steps to setup OIDC in Okta are similar as with Auth0 described below.

对于 Okta,你可以下载 PDF 格式的图文分步指南:

🌐 For Okta, you can download a visual step-by-step guide as PDF:

n8n-oidc-with-okta.pdf

Auth0#

  1. 在 Auth0 中创建一个应用
    • 登录你的 Auth0 控制面板。
    • 进入 应用 > 应用
    • 点击 创建应用
    • 输入一个名称(例如,“n8n SSO”),并选择 常规 Web 应用
    • 点击 创建
  2. 配置应用
    • 转到新应用的设置选项卡。
    • 允许的回调 URL:从 设置 > SSO > OIDC 添加你的 n8n 重定向 URL。
    • 允许的网页来源:添加你的 n8n 基础 URL(例如,https://yourworkspace.app.n8n.cloud)。
    • 点击 保存更改
  3. 获取你的凭证
    • 客户端 ID:在 设置 标签中找到。
    • 客户端密钥:位于设置选项卡中。
    • 发现端点: https://{your-auth0-domain}.auth0.com/.well-known/openid-configuration
  4. 在 n8n 中,完成 OIDC 配置:
    • 发现端点:输入来自 Auth0 的发现端点 URL。
    • 客户端 ID:输入你在 Auth0 设置中找到的客户端 ID。
    • 客户端密钥:输入你在 Auth0 设置中找到的客户端密钥。
  5. 选择 保存设置
  6. 将 OIDC 设置为 已激活

Discovery 端点参考(Discovery endpoints reference)#

  • 谷歌发现端点示例
1
https://accounts.google.com/.well-known/openid-configuration
  • Microsoft Azure AD 发现端点示例
1
https://login.microsoftonline.com/{tenant-id}/v2.0/.well-known/openid-configuration
  • Auth0 发现端点示例
1
https://{your-domain}.auth0.com/.well-known/openid-configuration
  • Okta 发现端点示例
1
https://{your-domain}.okta.com/.well-known/openid-configuration
  • Amazon Cognito 发现端点示例
1
https://cognito-idp.{region}.amazonaws.com/{user-pool-id}/.well-known/openid-configuration