{
  "openapi": "3.1.0",
  "info": {
    "title": "CardBrawler Identity API",
    "version": "1.0.0",
    "description": "OpenID Connect, Auth.md user-claimed agent registration, and account-session endpoints for CardBrawler clients. OAuth authorization server and Auth.md registration metadata are published by the corresponding well-known discovery resources."
  },
  "servers": [
    {
      "url": "https://id.whambamstudios.com"
    }
  ],
  "paths": {
    "/.well-known/openid-configuration": {
      "get": {
        "operationId": "getOpenIdConfiguration",
        "summary": "Get OpenID Connect discovery metadata",
        "responses": {
          "200": {
            "description": "OpenID Connect provider metadata",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/JsonObject" }
              }
            }
          }
        }
      }
    },
    "/.well-known/oauth-authorization-server": {
      "get": {
        "operationId": "getOAuthAuthorizationServerMetadata",
        "summary": "Get OAuth authorization server metadata and Auth.md registration methods",
        "responses": {
          "200": {
            "description": "OAuth authorization server metadata with agent_auth registration information",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/JsonObject" }
              }
            }
          }
        }
      }
    },
    "/connect/authorize": {
      "get": {
        "operationId": "authorize",
        "summary": "Start an OpenID Connect authorization flow",
        "parameters": [
          { "name": "client_id", "in": "query", "required": true, "schema": { "type": "string" } },
          { "name": "redirect_uri", "in": "query", "required": true, "schema": { "type": "string", "format": "uri" } },
          { "name": "response_type", "in": "query", "required": true, "schema": { "type": "string" } },
          { "name": "scope", "in": "query", "schema": { "type": "string" } },
          { "name": "state", "in": "query", "schema": { "type": "string" } },
          { "name": "nonce", "in": "query", "schema": { "type": "string" } }
        ],
        "responses": {
          "302": { "description": "Redirect to the sign-in or client callback" },
          "400": { "description": "Authorization request is invalid" }
        }
      },
      "post": {
        "operationId": "submitAuthorization",
        "summary": "Continue an OpenID Connect authorization flow",
        "responses": {
          "302": { "description": "Redirect to the client callback" },
          "400": { "description": "Authorization request is invalid" }
        }
      }
    },
    "/connect/token": {
      "post": {
        "operationId": "issueToken",
        "summary": "Poll user-claimed agent registration or exchange a signed identity assertion for tokens",
        "requestBody": {
          "required": true,
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "grant_type": { "type": "string" },
                  "code": { "type": "string" },
                  "redirect_uri": { "type": "string", "format": "uri" },
                  "code_verifier": { "type": "string" },
                  "refresh_token": { "type": "string" },
                  "client_id": { "type": "string" },
                  "claim_token": { "type": "string" },
                  "assertion": { "type": "string", "description": "CardBrawler-signed identity assertion returned after user confirmation" },
                  "resource": { "type": "string", "format": "uri", "description": "Must be https://whambamstudios.com/ for the agent game-session credential" }
                },
                "required": ["grant_type"]
              }
            }
          }
        },
        "responses": {
          "200": { "description": "OAuth token response. Claim-grant responses also include identity_assertion and assertion_expires; JWT-bearer responses exchange that assertion for an access token." },
          "400": { "description": "Token request is invalid" },
          "401": { "description": "Client authentication failed" }
        }
      }
    },
    "/agent/identity": {
      "post": {
        "operationId": "registerUserClaimedAgent",
        "summary": "Start a user-claimed agent registration using a verified email login hint",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "oneOf": [
                  {
                    "properties": {
                      "type": { "const": "service_auth" },
                      "login_hint": { "type": "string", "format": "email" }
                    },
                    "required": ["type", "login_hint"]
                  },
                  {
                    "properties": {
                      "type": { "const": "identity_assertion" },
                      "assertion_type": { "const": "verified_email" },
                      "email": { "type": "string", "format": "email" }
                    },
                    "required": ["type", "assertion_type", "email"]
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
              "description": "Registration created. The response contains a claim token and user confirmation code. After confirmation, claim polling returns an access token and a signed identity assertion.",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/JsonObject" } } }
          },
          "400": { "description": "Registration type or email address is invalid" },
          "429": { "description": "Registration rate limit exceeded" }
        }
      }
    },
    "/agent/auth": {
      "post": {
        "operationId": "registerUserClaimedAgentCompatibility",
        "summary": "Compatibility alias for Auth.md agent registration",
        "description": "Accepts the same requests and responses as POST /agent/identity. Passive discovery clients must not invoke this operation.",
        "responses": {
          "200": { "description": "Registration created" },
          "400": { "description": "Registration request is invalid" },
          "429": { "description": "Registration rate limit exceeded" }
        }
      }
    },
    "/connect/logout": {
      "get": {
        "operationId": "endSession",
        "summary": "End the current identity session",
        "responses": {
          "302": { "description": "Redirect after sign-out" }
        }
      },
      "post": {
        "operationId": "submitEndSession",
        "summary": "End the current identity session",
        "responses": {
          "302": { "description": "Redirect after sign-out" }
        }
      }
    },
    "/connect/revoke": {
      "post": {
        "operationId": "revokeToken",
        "summary": "Revoke a token",
        "requestBody": {
          "required": true,
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": { "type": "string" },
                  "token_type_hint": { "type": "string" }
                },
                "required": ["token"]
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Token revocation request processed" },
          "400": { "description": "Revocation request is invalid" }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "JsonObject": {
        "type": "object",
        "additionalProperties": true
      }
    }
  }
}
