{"id":"0255b3b73d7352a4","repo":"mongodb/node-mongodb-native","slug":"attempted-to-get-a-refresh-token-when-none-exists","errorCode":null,"errorMessage":"Attempted to get a refresh token when none exists.","messagePattern":"Attempted to get a refresh token when none exists\\.","errorType":"exception","errorClass":"MongoOIDCError","httpStatus":null,"severity":"error","filePath":"src/cmap/auth/mongodb_oidc/token_cache.ts","lineNumber":34,"sourceCode":"\n  get hasRefreshToken(): boolean {\n    return !!this.refreshToken;\n  }\n\n  get hasIdpInfo(): boolean {\n    return !!this.idpInfo;\n  }\n\n  getAccessToken(): string {\n    if (!this.accessToken) {\n      throw new MongoOIDCError('Attempted to get an access token when none exists.');\n    }\n    return this.accessToken;\n  }\n\n  getRefreshToken(): string {\n    if (!this.refreshToken) {\n      throw new MongoOIDCError('Attempted to get a refresh token when none exists.');\n    }\n    return this.refreshToken;\n  }\n\n  getIdpInfo(): IdPInfo {\n    if (!this.idpInfo) {\n      throw new MongoOIDCError('Attempted to get IDP information when none exists.');\n    }\n    return this.idpInfo;\n  }\n\n  put(response: OIDCResponse, idpInfo?: IdPInfo) {\n    this.accessToken = response.accessToken;\n    this.refreshToken = response.refreshToken;\n    this.expiresInSeconds = response.expiresInSeconds;\n    if (idpInfo) {\n      this.idpInfo = idpInfo;\n    }","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/cmap/auth/mongodb_oidc/token_cache.ts#L16-L52","documentation":"Thrown by the OIDC TokenCache.getRefreshToken() when no refresh token is cached (src/cmap/auth/mongodb_oidc/token_cache.ts:33). Internal invariant: the human workflow is expected to check hasRefreshToken before calling getRefreshToken. Surfaced as a MongoDriverError (local MongoOIDCError subclass), indicating an orchestration bug rather than user misconfiguration.","triggerScenarios":"Internal: the human callback workflow calls cache.getRefreshToken() without first verifying cache.hasRefreshToken. Not reachable via normal public API use.","commonSituations":"Not user-triggered normally. Could occur after a driver regression in the OIDC reauthenticate path, or if the cache state is corrupted by concurrent reauth attempts.","solutions":["Upgrade to the latest driver patch release.","If reproducible, file a driver bug with version and reproduction steps.","As a workaround, recreate the MongoClient to reset cache state.","Avoid sharing a MongoClient across processes or after an authentication failure."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await client.connect();\n} catch (e) {\n  if (e instanceof MongoDriverError && /get a refresh token when none exists/.test(e.message)) {\n    client.close();\n    throw new Error('Driver OIDC cache invariant violated - please file a bug.');\n  }\n  throw e;\n}","preventionTips":["Keep the driver patched to benefit from workflow-state fixes.","Recreate the MongoClient after auth failures to reset cache state.","Avoid concurrent reauthentications on the same connection pool."],"tags":["auth","oidc","internal","invariant","token-cache"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}