OAuth2: key token caches by the full credential configuration

Merged
H3
2mo ago
+203-35

Follow-up to the 1.1.12 release. The http, sse, streamable_http, websocket and gql protocols cached OAuth2 tokens by client_id alone, so two templates sharing a client_id but differing in token URL, secret or scope received each other's tokens. The MCP plugin and the TypeScript SDK already keyed by the full configuration; this brings the rest of Python into line.

Design. One source of truth: OAuth2Auth.cache_key() on the core model is the identity of a credential configuration (token URL, client id, secret, scope; absent scope normalised to empty). Every plugin keys its cache by it and the MCP plugin's private helper delegates to it, so there are no per-package copies of the rule that must agree. The key embeds the secret and is only ever a dict key.

Packages. utcp 1.1.4 (new method), utcp-http 1.1.13, utcp-mcp 1.1.4, utcp-websocket 1.1.5, utcp-gql 1.1.5. The four plugins now require utcp>=1.1.4, so publish core first.

Tests. Core pins the key's identity semantics; each plugin has a network-free cache-isolation test (seed the cache for config A, confirm A is served from it, confirm a config sharing only the client_id has no entry). Suites: core 45, http 238, mcp 48, websocket 38, gql 23, all passing. Two pre-existing network-dependent tests (OpenAPI spec fetch from apis.guru, the public Countries GraphQL API) timed out once under parallel load and pass in isolation.

šŸ¤– Generated with Claude Code


Summary by cubic

Stops the http, sse, streamable_http, websocket, and gql protocols from handing OAuth2 tokens to configs that share a client_id but differ in token URL, secret, or scope; caches are now keyed by the full credential configuration. CI now also installs and runs the file, websocket, and gql plugin suites, which previously shipped without coverage.

Migration

  • Publish utcp 1.1.4 first, then utcp-http 1.1.13, utcp-gql 1.1.5, utcp-mcp 1.1.4, and utcp-websocket 1.1.5, since the plugins now require utcp>=1.1.4.
  • The new OAuth2Auth.cache_key() embeds the secret, so use it only as a dict key and never log it.