{
  "openapi": "3.1.0",
  "info": {
    "title": "HeySO SaaS Application Integration",
    "version": "1.0.0",
    "description": "Confidential application integration contract. Not an OIDC provider; no ID tokens, refresh tokens, password grant or implicit flow."
  },
  "servers": [
    {
      "url": "/api/integrations/v1"
    }
  ],
  "paths": {
    "/contract": {
      "get": {
        "summary": "Read versioned contract",
        "operationId": "get_contract",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Permission denied",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Configuration conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/manifest-schema": {
      "get": {
        "summary": "Read versioned manifest-schema",
        "operationId": "get_manifest-schema",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Permission denied",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Configuration conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/openapi": {
      "get": {
        "summary": "Read versioned openapi",
        "operationId": "get_openapi",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Permission denied",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Configuration conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/registry": {
      "get": {
        "summary": "List app registrations (superadmin only)",
        "operationId": "get_registry",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Permission denied",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Configuration conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "SaaSCookie": []
          }
        ]
      },
      "post": {
        "summary": "Create/update registration; changes invalidate old authorizations",
        "operationId": "post_registry",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Permission denied",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Configuration conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "SaaSCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-Heyso-Admin",
            "in": "header",
            "required": true,
            "schema": {
              "const": "1"
            },
            "description": "Same-origin CSRF client header; a foreign Origin is rejected."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "revision": {
                    "type": "integer"
                  },
                  "manifest": {
                    "$ref": "#/components/schemas/Manifest"
                  }
                },
                "required": [
                  "revision",
                  "manifest"
                ]
              }
            }
          }
        }
      }
    },
    "/organizations/{tenantId}": {
      "get": {
        "summary": "Read installation and member grants (organization admin)",
        "operationId": "get_organizations_tenantId",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Permission denied",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Configuration conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "SaaSCookie": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "description": "Returns installations with read-only effectiveGrants explanations: userId, role (null when denied), source (explicit/organization/unassigned), requested role, viewerCeiling, scopes, enabled, and projectBound. Project-bound explanations remain subject to the selected project permission at entry. These explanations are not authorization credentials; every business request must use /check."
      },
      "post": {
        "summary": "Install, disable or update app/member grants",
        "operationId": "post_organizations_tenantId",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Permission denied",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Configuration conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "SaaSCookie": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-Heyso-Admin",
            "in": "header",
            "required": true,
            "schema": {
              "const": "1"
            },
            "description": "Same-origin CSRF client header; a foreign Origin is rejected."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Installation"
              }
            }
          }
        }
      }
    },
    "/catalog": {
      "get": {
        "summary": "List current selected organization apps accessible to current member",
        "operationId": "get_catalog",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApplicationCatalog"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Permission denied",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Configuration conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "SaaSCookie": []
          }
        ],
        "description": "Available applications include read-only category (official or third-party) and authorizationMode (organization or user-consent). Classification cannot be submitted in a manifest."
      }
    },
    "/authorize": {
      "post": {
        "summary": "Issue 60-second code after explicit browser consent",
        "operationId": "post_authorize",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "redirectUri": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "redirectUri"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Permission denied",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Configuration conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "SaaSCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-Heyso-Admin",
            "in": "header",
            "required": true,
            "schema": {
              "const": "1"
            },
            "description": "Same-origin CSRF client header; a foreign Origin is rejected."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Authorize"
              }
            }
          }
        }
      }
    },
    "/token": {
      "post": {
        "summary": "Redeem single-use audience-bound code with PKCE S256",
        "operationId": "post_token",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TokenResult"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Permission denied",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Configuration conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Token"
              }
            },
            "application/x-www-form-urlencoded": {
              "schema": {
                "$ref": "#/components/schemas/Token"
              }
            }
          }
        },
        "description": "Confidential server-to-server request. client_id and client_secret in request body; JSON and form encoding supported. Never call from browser JavaScript."
      }
    },
    "/introspect": {
      "post": {
        "summary": "Check live account, session, organization, app and project access",
        "operationId": "post_introspect",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "type": "object",
                      "properties": {
                        "active": {
                          "const": false
                        }
                      },
                      "required": [
                        "active"
                      ]
                    },
                    {
                      "allOf": [
                        {
                          "$ref": "#/components/schemas/Identity"
                        },
                        {
                          "type": "object",
                          "properties": {
                            "active": {
                              "const": true
                            }
                          },
                          "required": [
                            "active"
                          ]
                        }
                      ]
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Permission denied",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Configuration conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ClientToken"
              }
            },
            "application/x-www-form-urlencoded": {
              "schema": {
                "$ref": "#/components/schemas/ClientToken"
              }
            }
          }
        },
        "description": "Confidential server-to-server request. client_id and client_secret in request body; JSON and form encoding supported. Never call from browser JavaScript."
      }
    },
    "/check": {
      "post": {
        "summary": "Authorize an exact tenant/project permission",
        "operationId": "post_check",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "allowed": {
                      "type": "boolean"
                    },
                    "identity": {
                      "$ref": "#/components/schemas/Identity"
                    }
                  },
                  "required": [
                    "allowed",
                    "identity"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Permission denied",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Configuration conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Check"
              }
            },
            "application/x-www-form-urlencoded": {
              "schema": {
                "$ref": "#/components/schemas/Check"
              }
            }
          }
        },
        "description": "Confidential server-to-server request. client_id and client_secret in request body; JSON and form encoding supported. Never call from browser JavaScript."
      }
    },
    "/revoke": {
      "post": {
        "summary": "Idempotently revoke own-app token",
        "operationId": "post_revoke",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "const": true
                    }
                  },
                  "required": [
                    "ok"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Permission denied",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Configuration conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ClientToken"
              }
            },
            "application/x-www-form-urlencoded": {
              "schema": {
                "$ref": "#/components/schemas/ClientToken"
              }
            }
          }
        },
        "description": "Confidential server-to-server request. client_id and client_secret in request body; JSON and form encoding supported. Never call from browser JavaScript."
      }
    }
  },
  "components": {
    "securitySchemes": {
      "SaaSCookie": {
        "type": "apiKey",
        "in": "cookie",
        "name": "heyso_admin"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "requestId": {
            "type": "string"
          }
        },
        "required": [
          "error",
          "code"
        ]
      },
      "Manifest": {
        "title": "HeySO SaaS application manifest 1.0.0",
        "type": "object",
        "additionalProperties": false,
        "required": [
          "contractVersion",
          "id",
          "name",
          "description",
          "launchUrl",
          "redirectUris",
          "secretEnv",
          "scopes",
          "scope",
          "status"
        ],
        "properties": {
          "contractVersion": {
            "const": "1.0.0"
          },
          "id": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9-]{1,47}$",
            "not": {
              "const": "heyso"
            }
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80
          },
          "description": {
            "type": "string",
            "maxLength": 500
          },
          "launchUrl": {
            "type": "string",
            "format": "uri",
            "pattern": "^https://"
          },
          "redirectUris": {
            "type": "array",
            "minItems": 1,
            "maxItems": 8,
            "uniqueItems": true,
            "items": {
              "type": "string",
              "format": "uri",
              "pattern": "^https://"
            }
          },
          "secretEnv": {
            "type": "string",
            "pattern": "^HEYSO_APP_[A-Z0-9_]+_SECRET$"
          },
          "scopes": {
            "type": "array",
            "uniqueItems": true,
            "contains": {
              "const": "identity.read"
            },
            "items": {
              "enum": [
                "identity.read",
                "data.read",
                "data.write",
                "app.manage"
              ]
            }
          },
          "scope": {
            "enum": [
              "tenant",
              "project"
            ]
          },
          "status": {
            "enum": [
              "active",
              "disabled"
            ]
          }
        },
        "description": "Server additionally checks URL credentials/fragments, redirect origin equality, unique credential environment references and readiness before activation."
      },
      "Identity": {
        "type": "object",
        "properties": {
          "contractVersion": {
            "type": "string"
          },
          "issuer": {
            "type": "string"
          },
          "audience": {
            "type": "string"
          },
          "subject": {
            "type": "string"
          },
          "tenantId": {
            "type": "string"
          },
          "displayName": {
            "type": "string"
          },
          "organizationRole": {
            "type": "string"
          },
          "appRole": {
            "type": "string"
          },
          "projectId": {
            "type": [
              "string",
              "null"
            ]
          },
          "scopes": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "contractVersion",
          "issuer",
          "audience",
          "subject",
          "tenantId",
          "scopes"
        ]
      },
      "Client": {
        "type": "object",
        "properties": {
          "client_id": {
            "type": "string"
          },
          "client_secret": {
            "type": "string",
            "writeOnly": true
          }
        },
        "required": [
          "client_id",
          "client_secret"
        ]
      },
      "Authorize": {
        "type": "object",
        "properties": {
          "client_id": {
            "type": "string"
          },
          "tenant_id": {
            "type": "string"
          },
          "project_id": {
            "type": "string"
          },
          "redirect_uri": {
            "type": "string"
          },
          "scope": {
            "type": "string"
          },
          "state": {
            "type": "string"
          },
          "code_challenge": {
            "type": "string"
          },
          "code_challenge_method": {
            "type": "string"
          }
        },
        "required": [
          "client_id",
          "tenant_id",
          "redirect_uri",
          "scope",
          "state",
          "code_challenge",
          "code_challenge_method"
        ]
      },
      "Token": {
        "type": "object",
        "properties": {
          "client_id": {
            "type": "string",
            "writeOnly": false
          },
          "client_secret": {
            "type": "string",
            "writeOnly": true
          },
          "grant_type": {
            "type": "string",
            "writeOnly": false
          },
          "code": {
            "type": "string",
            "writeOnly": true
          },
          "code_verifier": {
            "type": "string",
            "writeOnly": true
          },
          "redirect_uri": {
            "type": "string",
            "writeOnly": false
          }
        },
        "required": [
          "client_id",
          "client_secret",
          "grant_type",
          "code",
          "code_verifier",
          "redirect_uri"
        ]
      },
      "TokenResult": {
        "type": "object",
        "properties": {
          "access_token": {
            "type": "string"
          },
          "token_type": {
            "const": "Bearer"
          },
          "expires_in": {
            "type": "integer"
          },
          "scope": {
            "type": "string"
          },
          "identity": {
            "$ref": "#/components/schemas/Identity"
          }
        },
        "required": [
          "access_token",
          "token_type",
          "expires_in",
          "scope",
          "identity"
        ]
      },
      "ClientToken": {
        "type": "object",
        "properties": {
          "client_id": {
            "type": "string"
          },
          "client_secret": {
            "type": "string",
            "writeOnly": true
          },
          "token": {
            "type": "string",
            "writeOnly": true
          }
        },
        "required": [
          "client_id",
          "client_secret",
          "token"
        ]
      },
      "Check": {
        "type": "object",
        "properties": {
          "client_id": {
            "type": "string"
          },
          "client_secret": {
            "type": "string",
            "writeOnly": true
          },
          "token": {
            "type": "string",
            "writeOnly": true
          },
          "tenantId": {
            "type": "string"
          },
          "projectId": {
            "type": [
              "string",
              "null"
            ]
          },
          "permission": {
            "enum": [
              "identity.read",
              "data.read",
              "data.write",
              "app.manage"
            ]
          }
        },
        "required": [
          "client_id",
          "client_secret",
          "token",
          "tenantId",
          "permission"
        ]
      },
      "Installation": {
        "type": "object",
        "properties": {
          "revision": {
            "type": "integer"
          },
          "appId": {
            "type": "string"
          },
          "status": {
            "enum": [
              "active",
              "disabled"
            ]
          },
          "accessMode": {
            "enum": [
              "organization",
              "members"
            ]
          },
          "scopes": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "grants": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "userId": {
                  "type": "string"
                },
                "role": {
                  "enum": [
                    "admin",
                    "editor",
                    "viewer",
                    "none"
                  ]
                }
              },
              "required": [
                "userId",
                "role"
              ]
            }
          }
        },
        "required": [
          "revision",
          "appId",
          "status",
          "accessMode",
          "scopes",
          "grants"
        ]
      },
      "ApplicationCategory": {
        "type": "string",
        "enum": [
          "official",
          "third-party"
        ],
        "readOnly": true,
        "description": "Platform-owned classification; not accepted in a submitted manifest."
      },
      "ApplicationPresentation": {
        "type": "object",
        "properties": {
          "category": {
            "$ref": "#/components/schemas/ApplicationCategory"
          },
          "authorizationMode": {
            "type": "string",
            "enum": [
              "organization",
              "user-consent"
            ],
            "readOnly": true
          }
        },
        "description": "Official platform-managed same-origin applications use organization-approved server sessions without user consent. Third-party applications retain consent and PKCE. Both enforce live tenant/member/record permissions."
      },
      "ApplicationCatalog": {
        "type": "object",
        "required": [
          "contractVersion",
          "tenantId",
          "applications"
        ],
        "properties": {
          "contractVersion": {
            "const": "1.0.0"
          },
          "tenantId": {
            "type": "string"
          },
          "applications": {
            "type": "array",
            "items": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/ApplicationPresentation"
                },
                {
                  "type": "object",
                  "required": [
                    "id",
                    "name",
                    "category",
                    "authorizationMode",
                    "effectiveScopes"
                  ],
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "name": {
                      "type": "string"
                    },
                    "effectiveScopes": {
                      "type": "array",
                      "items": {
                        "enum": [
                          "identity.read",
                          "data.read",
                          "data.write",
                          "app.manage"
                        ]
                      }
                    }
                  }
                }
              ]
            }
          }
        }
      }
    }
  }
}
