Update security schemes for MCP (OAuth + API Key fallback).
(
self, schema: dict[str, Any], oauth: OAuthConfig
)
| 125 | return operation |
| 126 | |
| 127 | def _update_security_for_mcp( |
| 128 | self, schema: dict[str, Any], oauth: OAuthConfig |
| 129 | ) -> dict[str, Any]: |
| 130 | """Update security schemes for MCP (OAuth + API Key fallback).""" |
| 131 | schema = schema.copy() |
| 132 | schema["components"] = schema.get("components", {}).copy() |
| 133 | schema["components"]["securitySchemes"] = { |
| 134 | "oauth2": { |
| 135 | "type": "oauth2", |
| 136 | "flows": { |
| 137 | "authorizationCode": { |
| 138 | "authorizationUrl": f"{oauth.frontend_url}/oauth/authorize/", |
| 139 | "tokenUrl": f"{oauth.api_url}/o/token/", |
| 140 | "scopes": oauth.scopes, |
| 141 | }, |
| 142 | }, |
| 143 | }, |
| 144 | "TOKEN_AUTH": { |
| 145 | "type": "apiKey", |
| 146 | "in": "header", |
| 147 | "name": "Authorization", |
| 148 | "description": "Organisation API Key. Format: Api-Key <key>", |
| 149 | }, |
| 150 | } |
| 151 | schema["security"] = [ |
| 152 | {"oauth2": list(oauth.scopes.keys())}, |
| 153 | {"TOKEN_AUTH": []}, |
| 154 | ] |
| 155 | return schema |
| 156 | |
| 157 | |
| 158 | class TypedDictSchemaExtension(OpenApiSerializerExtension): |