(input: string)
| 224 | } |
| 225 | |
| 226 | function parseAuthCodeInput(input: string): { code: string; state?: string } { |
| 227 | const trimmed = input.trim() |
| 228 | |
| 229 | if (trimmed.startsWith('http://') || trimmed.startsWith('https://')) { |
| 230 | const callback = new URL(trimmed) |
| 231 | const code = callback.searchParams.get('code') |
| 232 | const state = callback.searchParams.get('state') ?? undefined |
| 233 | |
| 234 | if (!code) { |
| 235 | throw new Error('No authorization code found in callback URL.') |
| 236 | } |
| 237 | |
| 238 | return { code, state } |
| 239 | } |
| 240 | |
| 241 | return { code: trimmed } |
| 242 | } |
| 243 | |
| 244 | export async function exchangeChatGptCodeForTokens( |
| 245 | authCodeInput: string, |
no test coverage detected