{"record":{"id":"b88775792a0d3e14","repo":"nocobase/nocobase","slug":"failed-to-load-oauth-metadata-formatoauthfetchfa","errorCode":null,"errorMessage":"Failed to load OAuth metadata. (formatOauthFetchFailure with envName, baseUrl, url, rawMessage)","messagePattern":"Failed to load OAuth metadata\\. \\(formatOauthFetchFailure with envName, baseUrl, url, rawMessage\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/cli/src/lib/env-auth.ts","lineNumber":342,"sourceCode":"}\n\nasync function fetchOauthServerMetadata(\n  baseUrl: string,\n  options: { envName?: string; onRetry?: (message: string) => void } = {},\n) {\n  const metadataUrl = getOauthMetadataUrl(baseUrl);\n  let response: Response;\n  try {\n    response = await fetchWithOauthRetry(\n      metadataUrl,\n      undefined,\n      {\n        operation: 'Loading OAuth metadata',\n        onRetry: options.onRetry,\n      },\n    );\n  } catch (error: any) {\n    throw new Error(\n      formatOauthFetchFailure('Failed to load OAuth metadata.', {\n        envName: options.envName,\n        baseUrl,\n        url: metadataUrl,\n        rawMessage: error?.message,\n      }),\n    );\n  }\n  const data = await parseJsonResponse(response);\n\n  if (!response.ok) {\n    throw new Error(formatOauthError(`Failed to load OAuth metadata from ${metadataUrl}`, data, response.status));\n  }\n\n  if (\n    !data ||\n    typeof data !== 'object' ||\n    typeof data.issuer !== 'string' ||","sourceCodeStart":324,"sourceCodeEnd":360,"githubUrl":"https://github.com/nocobase/nocobase/blob/fa42722fefe44265490dff2c27d79e2882bce4fa/packages/core/cli/src/lib/env-auth.ts#L324-L360","documentation":"fetchOauthServerMetadata fetches the OAuth authorization-server metadata document (via getOauthMetadataUrl from the configured baseUrl). If the underlying fetchWithOauthRetry call throws after all retries (network failure, timeout), the error is re-wrapped with formatOauthFetchFailure, producing this message plus env name, baseUrl, the metadata URL, and the raw network error.","triggerScenarios":"Signing in / initializing an environment whose baseUrl points at a server that does not respond: wrong port, server not started, DNS failure, TLS certificate problems, or requests timing out on every retry attempt.","commonSituations":"Typo in the environment's baseUrl (e.g. http vs https, wrong port); NocoBase backend not running or behind a reverse proxy that strips the OAuth metadata route; offline/VPN-required networks.","solutions":["Verify the environment's baseUrl is reachable: `curl <baseUrl>/.well-known/oauth-authorization-server` (or the metadata path the CLI uses)","Correct the baseUrl in your environment config if it is wrong","Ensure the NocoBase server is running and the OAuth discovery endpoint is served at the expected path","Check proxies/VPN/firewall if curl also fails to connect"],"exampleFix":"// before\nnocobase env use prod   # baseUrl: https://nocobase.example.co: wrong TLD/port\n// after\nfix baseUrl to https://nocobase.example.com then retry sign-in","handlingStrategy":"try-catch","validationCode":"const base = new URL(baseUrl); // validate scheme/host\nconst resp = await fetch(new URL('/.well-known/oauth-authorization-server', base), { signal: AbortSignal.timeout(5000) });\nif (!resp.ok) throw new Error(`Metadata endpoint returned HTTP ${resp.status}`);","typeGuard":"null","tryCatchPattern":"try {\n  await signIn(envName);\n} catch (err) {\n  if ((err as Error).message.includes('Failed to load OAuth metadata')) {\n    console.error('Check the environment baseUrl and that the server is running:', (err as Error).message);\n  } else throw err;\n}","preventionTips":["Validate the environment baseUrl (scheme, host, port) before storing it","Confirm the server exposes the OAuth discovery endpoint (curl the well-known URL)","Account for proxies/VPNs that block the metadata request","Keep server and CLI versions compatible"],"tags":["network","oauth","fetch","configuration"],"backgroundTag":"oauth-metadata-unavailable","analyzedSha":"fa42722fefe44265490dff2c27d79e2882bce4fa","analyzedAt":"2026-09-01T00:54:31.202Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}