Skip to content

Commit

Permalink
Fixed bug where user-supplied cache is loaded into memory before look…
Browse files Browse the repository at this point in the history
…ing into the cache
  • Loading branch information
rgins16 committed Jul 6, 2023
1 parent fb446dc commit 9750178
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/msal-node/src/client/ClientCredentialClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
ServerAuthorizationTokenResponse,
StringUtils,
TimeUtils,
TokenCacheContext,
UrlString,
} from "@azure/msal-common";

Expand Down Expand Up @@ -71,6 +72,16 @@ export class ClientCredentialClient extends BaseClient {
private async getCachedAuthenticationResult(
request: CommonClientCredentialRequest
): Promise<AuthenticationResult | null> {
// 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) {
Expand Down

0 comments on commit 9750178

Please sign in to comment.