feat: Add x-utcp-auth OpenAPI extension with auth inheritance for tools#64
Closed
feat: Add x-utcp-auth OpenAPI extension with auth inheritance for tools#64
Conversation
Add docs and update http to 1.0.2
Fix response json parsing when content type is wrong
…col/dev Update CLI
Contributor
Author
|
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
Member
|
Ah wait actually, I just look over the code. |
Member
|
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 |
Member
|
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 |
Contributor
Author
|
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"
}
}] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds support for the
x-utcp-authOpenAPI 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-authis used, it reuses inherited auth values if compatible, otherwise generates placeholdersx-utcp-authvaluesActual Precedence (in order):
x-utcp-authextension (if present) - always takes precedencex-utcp-authbut security schemes exist)x-utcp-authAND no OpenAPI security)Usage Example
•
x-utcp-authis 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
{ "manual_call_templates": [{ "name": "github_api", "call_template_type": "http", "url": "https://api.github.com/openapi.json", "auth": { "auth_type": "api_key", "api_key": "Bearer ghp_xxxxxxxxxxxx", "var_name": "Authorization", "location": "header" } }] }x-utcp-authExtension (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-authextension field that API providers can optionally add to their OpenAPI specifications for UTCP-specific authentication control:{ "paths": { "/user/repos": { "get": { "operationId": "list_user_repos", "x-utcp-auth": { "auth_type": "api_key", "var_name": "Authorization", "location": "header" } } } } }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-authextension and applies the precedence rules to generate tools with concrete authentication:{ "name": "list_user_repos", "tool_call_template": { "auth": { "auth_type": "api_key", "api_key": "Bearer ghp_xxxxxxxxxxxx", // ← Inherited from manual call template "var_name": "Authorization", "location": "header" } } }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-authextensionhttp_communication_protocol.py: Pass manual call template auth to convertertest_x_utcp_auth_extension.py: Comprehensive test coverage