Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/lib/node-oauth-client-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<string> {
if (DEBUG) await debugLog(this.serverUrlHash, 'Getting state parameter')
return this.options.state || crypto.randomBytes(32).toString('hex')
}
}
2 changes: 2 additions & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down