1.4 KiB
1.4 KiB
| @modelcontextprotocol/client |
|---|
| minor |
Add AuthProvider for composable bearer-token auth; transports adapt OAuthClientProvider automatically
- New
AuthProviderinterface:{ token(): Promise<string | undefined>; onUnauthorized?(ctx): Promise<void> }. Transports calltoken()before every request andonUnauthorized()on 401 (then retry once). - Transport
authProvideroption now acceptsAuthProvider | OAuthClientProvider. OAuth providers are adapted internally viaadaptOAuthProvider()— no changes needed to existingOAuthClientProviderimplementations. - For simple bearer tokens (API keys, gateway-managed tokens, service accounts):
{ authProvider: { token: async () => myKey } }— one-line object literal, no class. - New
adaptOAuthProvider(provider)export for explicit adaptation. - New
handleOAuthUnauthorized(provider, ctx)helper — the standard OAuthonUnauthorizedbehavior. - New
isOAuthClientProvider()type guard. - New
UnauthorizedContexttype. - Exported previously-internal auth helpers for building custom flows:
applyBasicAuth,applyPostAuth,applyPublicAuth,executeTokenRequest.
Transports are simplified internally — ~50 lines of inline OAuth orchestration (auth() calls, WWW-Authenticate parsing, circuit-breaker state) moved into the adapter's onUnauthorized() implementation. OAuthClientProvider itself is unchanged.