Documentation / @agentick/mcp / DefaultOAuthProvider
Class: DefaultOAuthProvider
Defined in: client/oauth.ts:204
Default OAuth provider for automatic auth on HTTP transports.
Uses in-memory storage for tokens, client info, PKCE, and discovery. When authorization is needed, calls onAuthorizationNeeded (or logs the URL if no callback is provided).
For production use, implement OAuthProvider directly with persistent storage and environment-appropriate redirect handling.
Implements
Constructors
Constructor
new DefaultOAuthProvider(
opts):DefaultOAuthProvider
Defined in: client/oauth.ts:212
Parameters
opts
Returns
DefaultOAuthProvider
Properties
clientMetadata
readonlyclientMetadata:object
Defined in: client/oauth.ts:205
OAuth client metadata for dynamic registration (RFC 7591).
Implementation of
redirectUrl
readonlyredirectUrl:string|URL|undefined
Defined in: client/oauth.ts:206
Redirect URI for the authorization callback. undefined for non-interactive flows.
Implementation of
Methods
cancelAuthorization()
cancelAuthorization():
void
Defined in: client/oauth.ts:278
Call this to cancel the pending auth flow (e.g., user closed the browser).
Returns
void
loadClientInfo()
loadClientInfo():
OAuthClientInformationMixed|undefined
Defined in: client/oauth.ts:233
Load stored client registration info, or undefined if not registered.
Returns
OAuthClientInformationMixed | undefined
Implementation of
loadTokens()
loadTokens(): { } |
undefined
Defined in: client/oauth.ts:224
Load stored tokens for this server, or undefined if none.
Returns
{ } | undefined
Implementation of
redirectToAuthorization()
redirectToAuthorization(
url):Promise<void>
Defined in: client/oauth.ts:242
Direct the user to the authorization URL to begin the OAuth flow.
Environments implement this differently:
- CLI: open system browser, start local HTTP callback server
- Server/gateway: store pending auth state, return URL to caller
- Embedded: post message to parent frame
Parameters
url
URL
Returns
Promise<void>
Implementation of
OAuthProvider.redirectToAuthorization
resolveAuthorizationCode()
resolveAuthorizationCode(
code):void
Defined in: client/oauth.ts:271
Call this from your callback handler to complete the pending auth flow. For example, from a local HTTP server receiving the OAuth redirect.
Parameters
code
string
Returns
void
saveClientInfo()
saveClientInfo(
info):void
Defined in: client/oauth.ts:237
Save client registration info after dynamic registration.
Parameters
info
OAuthClientInformationMixed
Returns
void
Implementation of
saveTokens()
saveTokens(
tokens):void
Defined in: client/oauth.ts:228
Save tokens after successful auth or refresh.
Parameters
tokens
Returns
void
Implementation of
waitForAuthorizationCode()
waitForAuthorizationCode():
Promise<string|undefined>
Defined in: client/oauth.ts:259
Wait for the authorization code after the user completes the browser flow.
This is called after redirectToAuthorization when the SDK transport throws UnauthorizedError. The connect loop blocks on this promise until the code arrives, then calls transport.finishAuth(code).
Implementations:
- CLI: resolve when the local callback server receives the redirect
- Server: resolve when the callback endpoint is hit
- Embedded: resolve when postMessage delivers the code
Return undefined to abort the auth flow (e.g., user cancelled).
Returns
Promise<string | undefined>