{
  "openapi": "3.0.0",
  "info": {
    "title": "n8n 公共 API",
    "version": "1.1.1"
  },
  "tags": [
    {
      "name": "SettingsSsoSaml",
      "description": "SAML SSO 设置相关操作"
    }
  ],
  "servers": [
    {
      "url": "/api/v1",
      "description": "当前 n8n 实例（自托管版本的内置测试台）"
    },
    {
      "url": "{url}/api/v1",
      "description": "自托管 n8n 实例",
      "variables": {
        "url": {
          "default": "https://example.com"
        }
      }
    }
  ],
  "security": [
    {
      "ApiKeyAuth": []
    },
    {
      "BearerAuth": []
    },
    {
      "CookieAuth": []
    }
  ],
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-N8N-API-KEY"
      },
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      },
      "CookieAuth": {
        "type": "apiKey",
        "in": "cookie",
        "name": "n8n-auth"
      }
    },
    "schemas": {
      "samlConfigurationPublicDto.generated": {
        "type": "object",
        "properties": {
          "entityID": {
            "type": "string",
            "description": "服务提供方实体 ID，即元数据 URL。",
            "readOnly": true
          },
          "returnUrl": {
            "type": "string",
            "description": "断言消费服务（ACS）返回 URL。",
            "readOnly": true
          },
          "mapping": {
            "type": "object",
            "properties": {
              "email": {
                "type": "string",
                "description": "映射到用户邮箱的 SAML 属性。"
              },
              "firstName": {
                "type": "string",
                "description": "映射到用户名字的 SAML 属性。"
              },
              "lastName": {
                "type": "string",
                "description": "映射到用户姓氏的 SAML 属性。"
              },
              "userPrincipalName": {
                "type": "string",
                "description": "映射到用户主体名称的 SAML 属性。"
              },
              "emailVerified": {
                "type": "string",
                "description": "表明身份提供方是否已验证用户邮箱的 SAML 属性；未使用时为空字符串。"
              },
              "n8nInstanceRole": {
                "type": "string",
                "description": "映射到 n8n 实例角色的 SAML 属性。"
              },
              "n8nProjectRoles": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "description": "映射到 n8n 项目角色的 SAML 属性，格式为 `<projectId>:<role>`。"
              }
            },
            "required": [
              "email",
              "firstName",
              "lastName",
              "userPrincipalName",
              "emailVerified",
              "n8nInstanceRole",
              "n8nProjectRoles"
            ],
            "description": "SAML 属性到 n8n 用户字段的映射。",
            "additionalProperties": false
          },
          "metadata": {
            "type": "string",
            "description": "XML 格式的身份提供方元数据。由于包含 IdP 证书，已设置时会在读取时遮蔽，绝不以明文返回。未设置时使用空字符串。"
          },
          "metadataUrl": {
            "type": "string",
            "description": "获取身份提供方元数据的 URL；未设置时使用空字符串。"
          },
          "ignoreSSL": {
            "type": "boolean",
            "description": "通过 URL 获取元数据时，是否忽略 SSL 证书错误。"
          },
          "loginBinding": {
            "type": "string",
            "enum": [
              "redirect",
              "post"
            ],
            "description": "SAML 登录请求的绑定方式。"
          },
          "loginEnabled": {
            "type": "boolean",
            "description": "是否启用 SAML 登录。"
          },
          "loginLabel": {
            "type": "string",
            "description": "SAML 登录按钮显示的标签。"
          },
          "authnRequestsSigned": {
            "type": "boolean",
            "description": "是否对身份验证请求签名。"
          },
          "wantAssertionsSigned": {
            "type": "boolean",
            "description": "是否要求断言带有签名。"
          },
          "wantMessageSigned": {
            "type": "boolean",
            "description": "是否要求 SAML 消息带有签名。"
          },
          "emailVerifiedRequired": {
            "type": "boolean",
            "description": "按邮箱将登录关联到现有用户之前，是否要求身份提供方断言用户邮箱已验证。关闭时，只有明确的否定断言会被拒绝。"
          },
          "signingPrivateKey": {
            "type": "string",
            "description": "用于签署 SAML AuthnRequests 的 PEM 编码私钥。已设置时，读取会遮蔽，绝不以明文返回。未设置时使用空字符串。"
          },
          "signingCertificate": {
            "type": "string",
            "description": "PEM 编码证书，包含与签名私钥匹配的公钥。已设置时，读取会遮蔽，绝不以明文返回。未设置时使用空字符串。"
          },
          "acsBinding": {
            "type": "string",
            "enum": [
              "redirect",
              "post"
            ],
            "description": "断言消费服务的绑定方式。"
          },
          "signatureConfig": {
            "type": "object",
            "properties": {
              "prefix": {
                "type": "string"
              },
              "location": {
                "type": "object",
                "properties": {
                  "reference": {
                    "type": "string"
                  },
                  "action": {
                    "type": "string",
                    "enum": [
                      "before",
                      "after",
                      "prepend",
                      "append"
                    ]
                  }
                },
                "required": [
                  "reference",
                  "action"
                ],
                "additionalProperties": false
              }
            },
            "required": [
              "prefix",
              "location"
            ],
            "description": "SAML 请求与响应中的签名配置。",
            "additionalProperties": false
          },
          "relayState": {
            "type": "string",
            "description": "SAML 请求的默认 relay state 值；未设置时使用空字符串。"
          }
        },
        "required": [
          "entityID",
          "returnUrl",
          "mapping",
          "metadata",
          "metadataUrl",
          "ignoreSSL",
          "loginBinding",
          "loginEnabled",
          "loginLabel",
          "authnRequestsSigned",
          "wantAssertionsSigned",
          "wantMessageSigned",
          "emailVerifiedRequired",
          "signingPrivateKey",
          "signingCertificate",
          "acsBinding",
          "signatureConfig",
          "relayState"
        ],
        "additionalProperties": false
      }
    },
    "responses": {
      "badRequest": {
        "description": "请求无效，或提供的数据格式错误。"
      },
      "unauthorized": {
        "description": "未授权"
      },
      "forbidden": {
        "description": "禁止访问"
      },
      "conflict": {
        "description": "冲突"
      },
      "unsupportedMediaType": {
        "description": "不支持的媒体类型。"
      }
    }
  },
  "paths": {
    "/settings/sso/saml": {
      "put": {
        "operationId": "updateSamlConfiguration",
        "tags": [
          "SettingsSsoSaml"
        ],
        "summary": "设置 SAML SSO 配置",
        "description": "使用提供的完整对象替换 SAML SSO 配置。必须发送所有可写字段；未设置的值使用空字符串或空数组。若包含 GET 返回的只读 `entityID` / `returnUrl`，写入时会忽略，因此可以将 GET 响应作为 PUT 请求体提交。已遮蔽的密钥占位符会使已存储值保持不变。更新使用与界面相同的校验，并以相同方式生效。需要 `saml:manage` 作用域，并获得 SAML 功能许可。配置通过环境变量管理时，写入会以 409 拒绝，且不作任何更改。",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "mapping": {
                    "type": "object",
                    "properties": {
                      "email": {
                        "type": "string",
                        "description": "映射到用户邮箱的 SAML 属性。"
                      },
                      "firstName": {
                        "type": "string",
                        "description": "映射到用户名字的 SAML 属性。"
                      },
                      "lastName": {
                        "type": "string",
                        "description": "映射到用户姓氏的 SAML 属性。"
                      },
                      "userPrincipalName": {
                        "type": "string",
                        "description": "映射到用户主体名称的 SAML 属性。"
                      },
                      "emailVerified": {
                        "type": "string",
                        "description": "表明身份提供方是否已验证用户邮箱的 SAML 属性。接受 `true` 和 `false`，不区分大小写。未使用时填写空字符串。"
                      },
                      "n8nInstanceRole": {
                        "type": "string",
                        "description": "映射到 n8n 实例角色的 SAML 属性；未使用时填写空字符串。"
                      },
                      "n8nProjectRoles": {
                        "type": "array",
                        "items": {
                          "type": "string"
                        },
                        "description": "映射到 n8n 项目角色的 SAML 属性，格式为 `<projectId>:<role>`。未使用时填写空数组。"
                      }
                    },
                    "required": [
                      "email",
                      "firstName",
                      "lastName",
                      "userPrincipalName",
                      "emailVerified",
                      "n8nInstanceRole",
                      "n8nProjectRoles"
                    ],
                    "additionalProperties": false,
                    "description": "SAML 属性到 n8n 用户字段的映射；未使用的属性填写空字符串或空数组。"
                  },
                  "metadata": {
                    "type": "string",
                    "description": "XML 格式的身份提供方元数据。使用空字符串可清除已存储元数据；未提供 URL 时，还会清除 metadataUrl。使用先前 GET 返回的遮蔽占位符，可保持现有值不变。"
                  },
                  "metadataUrl": {
                    "type": "string",
                    "description": "获取身份提供方元数据的 URL；使用空字符串可清除已存储的 URL。"
                  },
                  "ignoreSSL": {
                    "type": "boolean",
                    "description": "通过 URL 获取元数据时，是否忽略 SSL 证书错误。"
                  },
                  "loginBinding": {
                    "type": "string",
                    "enum": [
                      "redirect",
                      "post"
                    ],
                    "description": "SAML 登录请求的绑定方式。"
                  },
                  "loginEnabled": {
                    "type": "boolean",
                    "description": "是否启用 SAML 登录。"
                  },
                  "loginLabel": {
                    "type": "string",
                    "description": "SAML 登录按钮显示的标签。"
                  },
                  "authnRequestsSigned": {
                    "type": "boolean",
                    "description": "是否对身份验证请求签名。"
                  },
                  "wantAssertionsSigned": {
                    "type": "boolean",
                    "description": "是否要求断言带有签名。"
                  },
                  "wantMessageSigned": {
                    "type": "boolean",
                    "description": "是否要求 SAML 消息带有签名。"
                  },
                  "emailVerifiedRequired": {
                    "type": "boolean",
                    "description": "按邮箱将登录关联到现有用户之前，是否要求身份提供方断言用户邮箱已验证。关闭时，只有明确的否定断言会被拒绝。"
                  },
                  "signingPrivateKey": {
                    "type": "string",
                    "description": "用于签署 SAML AuthnRequests 的 PEM 编码私钥。使用空字符串可清除现有密钥，使用先前 GET 返回的遮蔽占位符可保持不变。"
                  },
                  "signingCertificate": {
                    "type": "string",
                    "description": "PEM 编码证书，包含与签名私钥匹配的公钥。未使用时，或要清除现有证书时，填写空字符串。"
                  },
                  "acsBinding": {
                    "type": "string",
                    "enum": [
                      "redirect",
                      "post"
                    ],
                    "description": "断言消费服务的绑定方式。"
                  },
                  "signatureConfig": {
                    "type": "object",
                    "properties": {
                      "prefix": {
                        "type": "string"
                      },
                      "location": {
                        "type": "object",
                        "properties": {
                          "reference": {
                            "type": "string"
                          },
                          "action": {
                            "type": "string",
                            "enum": [
                              "before",
                              "after",
                              "prepend",
                              "append"
                            ]
                          }
                        },
                        "required": [
                          "reference",
                          "action"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "required": [
                      "prefix",
                      "location"
                    ],
                    "additionalProperties": false,
                    "description": "SAML 请求与响应中的签名配置。"
                  },
                  "relayState": {
                    "type": "string",
                    "description": "SAML 请求的默认 relay state 值；未使用时填写空字符串。"
                  },
                  "entityID": {
                    "type": "string",
                    "description": "服务提供方实体 ID。GET 为方便使用而返回此值；写入时忽略，因此可以将 GET 响应作为 PUT 请求体提交。"
                  },
                  "returnUrl": {
                    "type": "string",
                    "description": "断言消费服务返回 URL。GET 为方便使用而返回此值；写入时忽略，因此可以将 GET 响应作为 PUT 请求体提交。"
                  }
                },
                "required": [
                  "mapping",
                  "metadata",
                  "metadataUrl",
                  "ignoreSSL",
                  "loginBinding",
                  "loginEnabled",
                  "loginLabel",
                  "authnRequestsSigned",
                  "wantAssertionsSigned",
                  "wantMessageSigned",
                  "emailVerifiedRequired",
                  "signingPrivateKey",
                  "signingCertificate",
                  "acsBinding",
                  "signatureConfig",
                  "relayState"
                ],
                "additionalProperties": false,
                "description": "完整 SAML SSO 配置。必须提供每个字段；未设置的值使用空字符串或空数组。不支持部分更新。"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "操作成功。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/samlConfigurationPublicDto.generated"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/badRequest"
          },
          "401": {
            "$ref": "#/components/responses/unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/forbidden"
          },
          "409": {
            "$ref": "#/components/responses/conflict"
          },
          "415": {
            "$ref": "#/components/responses/unsupportedMediaType"
          }
        }
      }
    }
  }
}
