{"record":{"id":"2c2454290a4d90ca","repo":"decolua/9router","slug":"refresh-token-is-required","errorCode":null,"errorMessage":"refresh_token is required","messagePattern":"refresh_token is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/lib/oauth/kiroExternalIdp.js","lineNumber":105,"sourceCode":"  if (!input || typeof input !== \"object\") {\n    throw new Error(\"CLIProxyAPI auth JSON is required\");\n  }\n\n  const authMethod = normalizeString(input.auth_method || input.authMethod);\n  if (authMethod && authMethod !== \"external_idp\") {\n    throw new Error(\"Only external_idp Kiro auth is supported by this importer\");\n  }\n\n  const accessToken = normalizeString(input.access_token || input.accessToken);\n  const refreshToken = normalizeString(input.refresh_token || input.refreshToken);\n  const clientId = normalizeString(input.client_id || input.clientId);\n  const tokenEndpoint = validateMicrosoftTokenEndpoint(input.token_endpoint || input.tokenEndpoint);\n  const profileArn = normalizeString(input.profile_arn || input.profileArn);\n  const region = normalizeString(input.region) || DEFAULT_REGION;\n  const scope = normalizeScope(input.scopes || input.scope);\n\n  if (!accessToken) throw new Error(\"access_token is required\");\n  if (!refreshToken) throw new Error(\"refresh_token is required\");\n  if (!clientId) throw new Error(\"client_id is required\");\n  if (!scope) throw new Error(\"scopes is required\");\n  if (!profileArn) throw new Error(\"profile_arn is required\");\n\n  const payload = decodeJwtPayload(accessToken);\n  const email = input.email || payload?.email || payload?.preferred_username || payload?.upn || payload?.sub || null;\n\n  return {\n    accessToken,\n    refreshToken,\n    expiresAt: resolveExpiresAt(input),\n    email,\n    providerSpecificData: {\n      profileArn,\n      region,\n      authMethod: \"external_idp\",\n      provider: \"CLIProxyAPI\",\n      clientId,","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/decolua/9router/blob/90b52e06ffd666b7929554211474d01588f6b1f8/src/lib/oauth/kiroExternalIdp.js#L87-L123","documentation":"A non-empty refresh_token (or refreshToken) is mandatory: without it the stored Kiro credential can never be refreshed and would die at first expiry. The check fires when the field is absent, empty, or whitespace-only after trim.","triggerScenarios":"Auth JSON missing refresh_token/refreshToken; refresh token blanked by a redaction/sanitization step before import; importing a document that only carries a short-lived access token.","commonSituations":"Exporting auth from a tool that redacts refresh tokens for security; copying only the access token into the JSON; an upstream login flow that stored the refresh token elsewhere.","solutions":["Include the refresh_token (or refreshToken) field from the CLIProxyAPI auth document","Re-authenticate via the external IdP flow to get a document containing the refresh token","If the source redacts tokens, export with a non-redacting option or copy the token manually from the original store","Never import an access-token-only blob — it will fail here by design"],"exampleFix":"// before\n{ \"access_token\": \"eyJ...\" }\n// after\n{ \"access_token\": \"eyJ...\", \"refresh_token\": \"0.AXoA...\" }","handlingStrategy":"validation","validationCode":"const rt = auth.refresh_token ?? auth.refreshToken;\nif (typeof rt !== 'string' || !rt.trim()) throw new Error('refresh_token missing from Kiro auth');","typeGuard":"function hasRefreshToken(a) {\n  return typeof a === 'object' && a !== null &&\n    ['refresh_token', 'refreshToken'].some(k => typeof a[k] === 'string' && a[k].trim() !== '');\n}","tryCatchPattern":"try {\n  normalizeKiroExternalIdpAuth(auth);\n} catch (e) {\n  if (e.message === 'refresh_token is required') {\n    console.error('Source redacted the refresh token; export without redaction or re-login');\n  }\n  throw e;\n}","preventionTips":["Verify exports from other tools are not redacting refresh tokens before import","Require refresh_token presence in your config schema validation","Never build auth documents carrying only the access token","Re-run the IdP login if the refresh token is unavailable — refresh tokens cannot be derived"],"tags":["oauth","missing-field","refresh-token","validation"],"backgroundTag":"missing-required-field","analyzedSha":"90b52e06ffd666b7929554211474d01588f6b1f8","analyzedAt":"2026-08-30T21:05:45.952Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}