diff --git a/src/lib/node-oauth-client-provider.ts b/src/lib/node-oauth-client-provider.ts index f070a88..95078f3 100644 --- a/src/lib/node-oauth-client-provider.ts +++ b/src/lib/node-oauth-client-provider.ts @@ -10,6 +10,7 @@ import type { OAuthProviderOptions, StaticOAuthClientMetadata } from './types' import { readJsonFile, writeJsonFile, readTextFile, writeTextFile } from './mcp-auth-config' import { StaticOAuthClientInformationFull } from './types' import { getServerUrlHash, log, debugLog, DEBUG, MCP_REMOTE_VERSION } from './utils' +import crypto from 'crypto' /** * Implements the OAuthClientProvider interface for Node.js environments. @@ -193,4 +194,13 @@ export class NodeOAuthClientProvider implements OAuthClientProvider { if (DEBUG) await debugLog(this.serverUrlHash, 'Code verifier found:', !!verifier) return verifier } + + /** + * Gets the state parameter for OAuth authorization request + * @returns The state parameter if provided in options, or a generated state + */ + async state(): Promise { + if (DEBUG) await debugLog(this.serverUrlHash, 'Getting state parameter') + return this.options.state || crypto.randomBytes(32).toString('hex') + } } diff --git a/src/lib/types.ts b/src/lib/types.ts index 74b3a96..526a274 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -27,6 +27,8 @@ export interface OAuthProviderOptions { staticOAuthClientMetadata?: StaticOAuthClientMetadata /** Static OAuth client information to use instead of OAuth registration */ staticOAuthClientInfo?: StaticOAuthClientInformationFull + /** State parameter for OAuth authorization request */ + state?: string } /**