MCPcopy Create free account
hub / github.com/freecodexyz/free-code / parseCodexCallbackInput

Function parseCodexCallbackInput

src/services/oauth/codex-client.ts:375–399  ·  view source on GitHub ↗

* Parses a manually pasted callback input (could be the full redirect URL * or just the raw code).

(
  input: string,
  expectedState: string,
)

Source from the content-addressed store, hash-verified

373 * or just the raw code).
374 */
375function parseCodexCallbackInput(
376 input: string,
377 expectedState: string,
378): { code: string | undefined } {
379 const value = input.trim()
380 if (!value) return { code: undefined }
381
382 try {
383 const url = new URL(value)
384 const urlState = url.searchParams.get('state')
385 if (urlState && urlState !== expectedState) {
386 throw new Error('State mismatch in pasted URL')
387 }
388 return { code: url.searchParams.get('code') ?? undefined }
389 } catch {
390 // Not a URL — treat as raw code
391 }
392
393 if (value.includes('code=')) {
394 const params = new URLSearchParams(value)
395 return { code: params.get('code') ?? undefined }
396 }
397
398 return { code: value }
399}

Callers 1

runCodexOAuthFlowFunction · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected