Skip to content

Commit e1f7a50

Browse files
authored
[Identity] No more inMemoryPersistence! (Azure#14530)
Now that we've released 2.0.0-beta.1 and the Identity hotfix that I wanted to release, I was able to sit down and start writing a sample showcasing some of the "bugs" I found. This helped me bounce against the code and eventually figure out that it was in fact _me_ who had written a bug! This if: ```ts if (this.publicApp && this.confidentialApp) { return; } ``` in the code that defines the configuration for Node.js was causing the MSAL client to be defined multiple times, rendering the in-memory cache as useless. The solution? To switch `&&` to `||`. It seems obvious in retrospective! This means that there's no need neither for the `inMemoryCache`, nor for the line that I used to "read" from the cache. Therefore: Fixes Azure#14372 Fixes Azure#14373
1 parent e050256 commit e1f7a50

File tree

2 files changed

+1
-54
lines changed

2 files changed

+1
-54
lines changed

sdk/identity/identity/src/msal/nodeFlows/nodeCommon.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { DeveloperSignOnClientId } from "../../constants";
99
import { IdentityClient, TokenCredentialOptions } from "../../client/identityClient";
1010
import { TokenCachePersistenceOptions } from "../../tokenCache/persistencePlatforms";
1111
import { TokenCachePersistence } from "../../tokenCache/TokenCachePersistence";
12-
import { inMemoryPersistence } from "../../tokenCache/InMemoryPersistence";
1312
import { resolveTenantId } from "../../util/resolveTenantId";
1413
import { TokenCache } from "../../tokenCache/types";
1514
import { CredentialFlowGetTokenOptions } from "../credentials";
@@ -56,10 +55,6 @@ export abstract class MsalNode extends MsalBaseUtilities implements MsalFlow {
5655

5756
if (options.tokenCachePersistenceOptions) {
5857
this.tokenCache = new TokenCachePersistence(options.tokenCachePersistenceOptions);
59-
} else {
60-
// To allow silent authentications on the same credential, we provide a very simple in memory token cache.
61-
// It can't be used to re-use the account information returned from the authenticate() method.
62-
this.tokenCache = inMemoryPersistence();
6358
}
6459
}
6560

@@ -102,7 +97,7 @@ export abstract class MsalNode extends MsalBaseUtilities implements MsalFlow {
10297
});
10398
}
10499

105-
if (this.publicApp && this.confidentialApp) {
100+
if (this.publicApp || this.confidentialApp) {
106101
return;
107102
}
108103

@@ -210,11 +205,6 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
210205
scopes
211206
};
212207

213-
// Currently we need to call getAllAccounts before the silent request is attempted.
214-
// The MSAL team is actively investigating why this is necessary.
215-
// TODO: Remove this once this is no longer necessary.
216-
await this.publicApp?.getTokenCache().getAllAccounts();
217-
218208
try {
219209
this.logger.info("Attempting to acquire token silently");
220210
const response = await this.publicApp!.acquireTokenSilent(silentRequest);

sdk/identity/identity/src/tokenCache/InMemoryPersistence.ts

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)