{"record":{"id":"12451a33e273430d","repo":"Kong/insomnia","slug":"failed-to-initiate-the-github-oauth-flow-errorm","errorCode":null,"errorMessage":"Failed to initiate the GitHub OAuth flow: ${errorMessage}","messagePattern":"Failed to initiate the GitHub OAuth flow: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/insomnia/src/sync/git/providers/github.ts","lineNumber":285,"sourceCode":"    try {\n      const state = v4();\n      githubStatesCache.set(state, credentialId);\n      const url = new URL(getAppWebsiteBaseURL() + '/oauth/github-app');\n\n      url.search = new URLSearchParams({\n        state,\n      }).toString();\n\n      await shell.openExternal(url.toString());\n\n      return {\n        authUrl: url.toString(),\n        state,\n      };\n    } catch (error) {\n      const errorMessage = error instanceof Error ? error.message : String(error);\n      console.error('Failed to initiate the GitHub OAuth flow:', error);\n      throw new Error(`Failed to initiate the GitHub OAuth flow: ${errorMessage}`);\n    }\n  }\n\n  /**\n   * Complete OAuth flow\n   * Exchanges code for token and creates/updates credential in database\n   */\n  async completeOAuth(code: string, state: string): Promise<OAuthCompleteResult> {\n    try {\n      // Validate state for security (CSRF protection)\n      if (!PLAYWRIGHT_TEST && !githubStatesCache.has(state)) {\n        throw new Error('Invalid state parameter. It looks like the authorization flow was not initiated by the app.');\n      }\n      const reauthorizingCredentialId = githubStatesCache.get(state);\n\n      // Exchange code for access token via Insomnia backend\n      const response = await net.fetch(getApiBaseURL() + '/v1/oauth/github-app', {\n        method: 'POST',","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/Kong/insomnia/blob/d9bb2b0142600f21309832daea3317942d285984/packages/insomnia/src/sync/git/providers/github.ts#L267-L303","documentation":"Error \"Failed to initiate the GitHub OAuth flow: ${errorMessage}\" thrown in Kong/insomnia.","triggerScenarios":"Thrown at packages/insomnia/src/sync/git/providers/github.ts:285 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"d9bb2b0142600f21309832daea3317942d285984","analyzedAt":"2026-08-26T18:04:05.187Z","schemaVersion":2},"datasetVersion":"2026-08-26T21:11:00.512Z"}