{
  "openapi": "3.0.1",
  "info": {
    "title": "Tokens API",
    "version": "v1"
  },
  "paths": {
    "/v1/tokens": {
      "post": {
        "summary": "Request a new token",
        "tags": [
          "Authentication"
        ],
        "description": "Generates a new token using client credentials",
        "security": [],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Token created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "token": {
                      "type": "string",
                      "description": "The Bearer access token"
                    },
                    "expires_at": {
                      "type": "integer",
                      "description": "Unix epoch timestamp (seconds) when the token expires"
                    },
                    "expires_in": {
                      "type": "integer",
                      "description": "Number of seconds until the token expires"
                    },
                    "token_type": {
                      "type": "string",
                      "description": "The type of token (always Bearer)"
                    }
                  },
                  "required": [
                    "token",
                    "expires_at",
                    "expires_in",
                    "token_type"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Parameter missing",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "message"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Invalid credentials",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        },
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "object",
                    "properties": {
                      "client_id": {
                        "type": "string"
                      },
                      "client_secret": {
                        "type": "string"
                      }
                    },
                    "required": [
                      "client_id",
                      "client_secret"
                    ]
                  }
                },
                "required": [
                  "token"
                ]
              }
            }
          }
        }
      }
    },
    "/v1/tokens/validate": {
      "post": {
        "summary": "Validate a bearer token",
        "tags": [
          "Authentication"
        ],
        "description": "Validates whether a bearer token is valid and active. If this endpoint is reached, the token passed middleware validation and is valid.",
        "parameters": [
          {
            "name": "Authorization",
            "in": "header",
            "description": "Bearer token to validate (required by middleware)",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Token is valid",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "valid": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "valid",
                    "message"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Token is invalid"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {},
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    }
  },
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "x-tagGroups": [
    {
      "name": "Tokens",
      "tags": [
        "Authentication"
      ]
    }
  ],
  "servers": [
    {
      "url": "https://api.sandbox.congruitcredit.com",
      "description": "Sandbox Environment"
    },
    {
      "url": "https://api.congruitcredit.com",
      "description": "Production Environment"
    }
  ]
}