From 97501782d6f5237b73f9a0c4ca66637ca4278592 Mon Sep 17 00:00:00 2001 From: Robert Ginsburg Date: Thu, 6 Jul 2023 17:50:53 -0400 Subject: [PATCH] Fixed bug where user-supplied cache is loaded into memory before looking into the cache --- lib/msal-node/src/client/ClientCredentialClient.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/msal-node/src/client/ClientCredentialClient.ts b/lib/msal-node/src/client/ClientCredentialClient.ts index be0507fb4c..fa36f3e2f8 100644 --- a/lib/msal-node/src/client/ClientCredentialClient.ts +++ b/lib/msal-node/src/client/ClientCredentialClient.ts @@ -25,6 +25,7 @@ import { ServerAuthorizationTokenResponse, StringUtils, TimeUtils, + TokenCacheContext, UrlString, } from "@azure/msal-common"; @@ -71,6 +72,16 @@ export class ClientCredentialClient extends BaseClient { private async getCachedAuthenticationResult( request: CommonClientCredentialRequest ): Promise { + // read the user-supplied cache into memory, if applicable + if (this.config.serializableCache && this.config.persistencePlugin) { + const cacheContext = new TokenCacheContext( + this.config.serializableCache, + true, + ); + + await this.config.persistencePlugin.beforeCacheAccess(cacheContext); + } + const cachedAccessToken = this.readAccessTokenFromCache(); if (!cachedAccessToken) {