-
Notifications
You must be signed in to change notification settings - Fork 35
feat: Add x-utcp-auth OpenAPI extension with auth inheritance for tools #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
Add docs and update http to 1.0.2
Fix response json parsing when content type is wrong
…col/dev Update CLI
addresses #65 |
Add support for the x-utcp-auth extension in OpenAPI specifications with seamless authentication inheritance from manual call templates. ## Features - Support x-utcp-auth extension that takes precedence over standard security schemes - Inherit authentication configuration from manual call templates - Case-insensitive header name comparison for auth inheritance compatibility - Safe handling of non-dict x-utcp-auth values - Fall back to placeholder generation when auth is incompatible - Maintain backward compatibility with existing OpenAPI security ## Usage Example Manual call template with auth: ```json { "manual_call_templates": [{ "name": "aws_api", "call_template_type": "http", "url": "https://api.example.com/openapi.json", "auth": { "auth_type": "api_key", "api_key": "Bearer token-123", "var_name": "Authorization", "location": "header" } }] } ``` OpenAPI operations with x-utcp-auth extension: ```json { "paths": { "/protected": { "get": { "operationId": "get_protected_data", "x-utcp-auth": { "auth_type": "api_key", "var_name": "Authorization", "location": "header" } } } } } ``` Generated tools automatically inherit the auth from manual call templates.
13cc21d
to
5f519b7
Compare
Ah wait actually, I just look over the code. |
If we put the auth in the manual auth, then the request to the /openapi endpoint will be authenticated. Which doesn't make sense, if the actual openapi endpoint is an open GET request |
Wouldn't it work to just add this to the openapi spec? {
"paths": {
"/protected": {
"get": {
"operationId": "get_protected_data",
"x-utcp-auth": {
"auth_type": "api_key",
"api_key": "Bearer $TOKEN",
"var_name": "Authorization",
"location": "header"
}
}
}
}
} In which case there is no inheritance, its just a way to define security following the UTCP way of doing it |
my point is the following:
Thinking a bit about it, maybe this could suffice: "manual_call_templates": [{
"name": "github_api",
"call_template_type": "http",
"url": "https://api.github.com/openapi.json",
"auth": { // ← EXISTING SECTION, TO BE FILLED IF THE OPENAPI ENDPOINT IS PROTECTED
"auth_type": "api_key",
"api_key": "Bearer ghp_xxxxxxxxxxxx",
"var_name": "Authorization",
"location": "header"
},
"auth_tools": { // ← NEW SECTION BEING PROPOSED, TO BE FILLED IF THE TOOLS ENDPOINT ARE PROTECTED, AND TO BE APPLIED ONLY ON THE PROTECTED ENDPOINTS IN THE TRANSIENT UTCP MANUAL, AS PER SPECIFICATIONS IN THE OPENAPI FILE
"auth_type": "api_key",
"api_key": "Bearer ghp_xxxxxxxxxxxx",
"var_name": "Authorization",
"location": "header"
}
}] |
Summary
Adds support for the
x-utcp-auth
OpenAPI extension that enables seamless authentication inheritance from manual call templates, providing fine-grained per-operation auth control while maintaining backward compatibility.Problem Solved
Key Features
x-utcp-auth
→ OpenAPI security → Inherited auth → No authx-utcp-auth
is used, it reuses inherited auth values if compatible, otherwise generates placeholdersx-utcp-auth
valuesActual Precedence (in order):
x-utcp-auth
extension (if present) - always takes precedencex-utcp-auth
but security schemes exist)x-utcp-auth
AND no OpenAPI security)Usage Example
•
x-utcp-auth
is a novel extension field created by this PR specifically for UTCP• It's an optional OpenAPI extension (following OpenAPI's
x-*
extension pattern) that maintains backward compatibility• The UTCP converter recognizes and processes this extension during conversion
• It gets consumed and transformed into standard UTCP auth based on the precedence rules
x-utcp-auth
Extension (Create as transient step by the UTCP converter, but could be also defined inside an UTCP-friendly OpenAPI spec):This PR introduces support for the new
x-utcp-auth
extension field that API providers can optionally add to their OpenAPI specifications for UTCP-specific authentication control:Note: This extension is backward-compatible with OpenAPI standards, so it could be included in an OpenAPI spec and would be ignored by non-UTCP tools.
The UTCP converter processes the
x-utcp-auth
extension and applies the precedence rules to generate tools with concrete authentication:All generated tools automatically inherit the GitHub token authentication without requiring environment variables or additional configuration.
Testing
Files Changed
openapi_converter.py
: Core implementation of auth inheritance andx-utcp-auth
extensionhttp_communication_protocol.py
: Pass manual call template auth to convertertest_x_utcp_auth_extension.py
: Comprehensive test coverage