{
  "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": {
      "unauthorized": {
        "description": "未授权"
      },
      "forbidden": {
        "description": "禁止访问"
      }
    }
  },
  "paths": {
    "/settings/sso/saml": {
      "get": {
        "operationId": "getSamlConfiguration",
        "tags": [
          "SettingsSsoSaml"
        ],
        "summary": "获取 SAML SSO 配置",
        "description": "获取当前 SAML SSO 配置，包括界面中提供的所有字段，以及服务提供方实体 ID 和 ACS 返回 URL。读取时会遮蔽签名私钥、签名证书和身份提供方元数据。需要 `saml:manage` 作用域，并获得 SAML 功能许可。",
        "responses": {
          "200": {
            "description": "操作成功。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/samlConfigurationPublicDto.generated"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/forbidden"
          }
        }
      }
    }
  }
}
