File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed
Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -93,6 +93,8 @@ type EnvironmentName = 'test' | 'azure' | 'gcp' | 'k8s' | undefined;
9393
9494/** @internal */
9595export interface Workflow {
96+ cache : TokenCache ;
97+
9698 /**
9799 * All device workflows must implement this method in order to get the access
98100 * token and then call authenticate with it.
Original file line number Diff line number Diff line change @@ -61,6 +61,7 @@ import {
6161 WaitQueueTimeoutError
6262} from './errors' ;
6363import { ConnectionPoolMetrics } from './metrics' ;
64+ import { MongoDBOIDC } from './auth/mongodb_oidc' ;
6465
6566/** @public */
6667export interface ConnectionPoolOptions extends Omit < ConnectionOptions , 'id' | 'generation' > {
@@ -428,6 +429,19 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
428429 return ;
429430 }
430431
432+ // If we are clearing the connnection pool when using OIDC, we need to remove the access token
433+ // from the cache so we dont' try to use the same token again for initial auth on a new connection
434+ // when the token may have expired.
435+ const clientState = this . server . topology . client . s ;
436+ const credentials = clientState . options . credentials ;
437+ if ( credentials ?. mechanism === 'MONGODB-OIDC' ) {
438+ const provider = this . server . topology . client . s . authProviders . getOrCreateProvider (
439+ credentials . mechanism ,
440+ credentials . mechanismProperties
441+ ) as MongoDBOIDC ;
442+ provider . workflow . cache . removeAccessToken ( ) ;
443+ }
444+
431445 // handle load balanced case
432446 if ( this . loadBalanced ) {
433447 const { serviceId } = options ;
You can’t perform that action at this time.
0 commit comments