Skip to content

Commit a7a5206

Browse files
committed
fix: invalidate token in cache on error
1 parent 1121bbe commit a7a5206

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/cmap/auth/mongodb_oidc/callback_workflow.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,15 @@ export class CallbackWorkflow implements Workflow {
236236
// With no token in the cache we use the request callback.
237237
result = await requestCallback(serverInfo, context);
238238
}
239-
// Validate that the result returned by the callback is acceptable.
239+
// Validate that the result returned by the callback is acceptable. If it is not
240+
// we must clear the token result from the cache.
240241
if (isCallbackResultInvalid(result)) {
242+
this.cache.deleteEntry(
243+
connection.address,
244+
credentials.username || '',
245+
requestCallback,
246+
refreshCallback || null
247+
);
241248
throw new MongoMissingCredentialsError(
242249
'User provided OIDC callbacks must return a valid object with an accessToken.'
243250
);

0 commit comments

Comments
 (0)