Skip to content

Commit

Permalink
removed thrown error claimsBasedCaching. Marked it as deprecated in m…
Browse files Browse the repository at this point in the history
…sal-node
  • Loading branch information
Robbie-Microsoft committed Apr 30, 2024
1 parent 99ce409 commit 650c083
Show file tree
Hide file tree
Showing 14 changed files with 513 additions and 132 deletions.

This file was deleted.

This file was deleted.

6 changes: 0 additions & 6 deletions lib/msal-browser/src/config/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,6 @@ export function buildConfiguration(
}: Configuration,
isBrowserEnvironment: boolean
): BrowserConfiguration {
if (userInputCache?.claimsBasedCachingEnabled) {
throw createClientConfigurationError(
ClientConfigurationErrorCodes.claimsBasedCachingEnabled
);
}

// Default auth options for browser
const DEFAULT_AUTH_OPTIONS: InternalAuthOptions = {
clientId: Constants.EMPTY_STRING,
Expand Down
381 changes: 381 additions & 0 deletions lib/msal-browser/test/app/PublicClientApplication.spec.ts

Large diffs are not rendered by default.

23 changes: 2 additions & 21 deletions lib/msal-browser/test/config/Configuration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import {
ProtocolMode,
ServerResponseType,
Logger,
createClientConfigurationError,
ClientConfigurationErrorCodes,
} from "@azure/msal-common";
import sinon from "sinon";
import { BrowserCacheLocation } from "../../src/utils/BrowserConstants";
Expand Down Expand Up @@ -249,7 +247,7 @@ describe("Configuration.ts Class Unit Tests", () => {
cacheLocation: BrowserCacheLocation.LocalStorage,
storeAuthStateInCookie: true,
secureCookies: true,
claimsBasedCachingEnabled: false,
claimsBasedCachingEnabled: true,
},
system: {
windowHashTimeout: TEST_POPUP_TIMEOUT_MS,
Expand Down Expand Up @@ -281,7 +279,7 @@ describe("Configuration.ts Class Unit Tests", () => {
expect(newConfig.cache?.storeAuthStateInCookie).not.toBeNull();
expect(newConfig.cache?.storeAuthStateInCookie).toBe(true);
expect(newConfig.cache?.secureCookies).toBe(true);
expect(newConfig.cache?.claimsBasedCachingEnabled).toBe(false);
expect(newConfig.cache?.claimsBasedCachingEnabled).toBe(true);
// System config checks
expect(newConfig.system).not.toBeNull();
expect(newConfig.system?.windowHashTimeout).not.toBeNull();
Expand Down Expand Up @@ -313,21 +311,4 @@ describe("Configuration.ts Class Unit Tests", () => {
);
expect(loggerSpy).toBeCalled();
});

it("throws an error when claimsBasedCaching is enabled", () => {
expect(() => {
buildConfiguration(
{
// @ts-ignore
auth: null,
cache: { claimsBasedCachingEnabled: true },
},
true
);
}).toThrow(
createClientConfigurationError(
ClientConfigurationErrorCodes.claimsBasedCachingEnabled
)
);
});
});
10 changes: 0 additions & 10 deletions lib/msal-common/src/config/ClientConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ import {
ClientAuthErrorCodes,
createClientAuthError,
} from "../error/ClientAuthError";
import {
ClientConfigurationErrorCodes,
createClientConfigurationError,
} from "../error/ClientConfigurationError";

/**
* Use the configuration object to configure MSAL Modules and initialize the base interfaces for MSAL.
Expand Down Expand Up @@ -237,12 +233,6 @@ export function buildClientConfiguration({
persistencePlugin: persistencePlugin,
serializableCache: serializableCache,
}: ClientConfiguration): CommonClientConfiguration {
if (userCacheOptions?.claimsBasedCachingEnabled) {
throw createClientConfigurationError(
ClientConfigurationErrorCodes.claimsBasedCachingEnabled
);
}

const loggerOptions = {
...DEFAULT_LOGGER_IMPLEMENTATION,
...userLoggerOption,
Expand Down
2 changes: 0 additions & 2 deletions lib/msal-common/src/error/ClientConfigurationError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ export const ClientConfigurationErrorMessages = {
"Cannot set allowNativeBroker parameter to true when not in AAD protocol mode.",
[ClientConfigurationErrorCodes.authorityMismatch]:
"Authority mismatch error. Authority provided in login request or PublicClientApplication config does not match the environment of the provided account. Please use a matching account or make an interactive request to login to this authority.",
[ClientConfigurationErrorCodes.claimsBasedCachingEnabled]:
"Claims based caching is not supported in MSALJS.",
};

/**
Expand Down
1 change: 0 additions & 1 deletion lib/msal-common/src/error/ClientConfigurationErrorCodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,3 @@ export const invalidAuthenticationHeader = "invalid_authentication_header";
export const cannotSetOIDCOptions = "cannot_set_OIDCOptions";
export const cannotAllowNativeBroker = "cannot_allow_native_broker";
export const authorityMismatch = "authority_mismatch";
export const claimsBasedCachingEnabled = "claims_based_caching_enabled";
65 changes: 65 additions & 0 deletions lib/msal-common/test/client/SilentFlowClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,71 @@ describe("SilentFlowClient unit tests", () => {
);
});

it("acquireCachedToken does not throw when given valid claims with claimsBasedCachingEnabled", async () => {
const testScopes = [
Constants.OPENID_SCOPE,
Constants.PROFILE_SCOPE,
...TEST_CONFIG.DEFAULT_GRAPH_SCOPE,
];
testAccessTokenEntity.target = testScopes.join(" ");
sinon
.stub(
Authority.prototype,
<any>"getEndpointMetadataFromNetwork"
)
.resolves(DEFAULT_OPENID_CONFIG_RESPONSE.body);
sinon
.stub(CacheManager.prototype, "readAccountFromCache")
.returns(testAccountEntity);
sinon
.stub(CacheManager.prototype, "getIdToken")
.returns(testIdToken);
sinon
.stub(CacheManager.prototype, "getAccessToken")
.returns(testAccessTokenEntity);
sinon
.stub(CacheManager.prototype, "getRefreshToken")
.returns(testRefreshTokenEntity);
const config =
await ClientTestUtils.createTestClientConfiguration();
const client = new SilentFlowClient(
{
...config,
cacheOptions: {
...config.cacheOptions,
claimsBasedCachingEnabled: true,
},
},
stubPerformanceClient
);
sinon.stub(TimeUtils, <any>"isTokenExpired").returns(false);

const silentFlowRequest: CommonSilentFlowRequest = {
scopes: TEST_CONFIG.DEFAULT_GRAPH_SCOPE,
account: testAccount,
authority: TEST_CONFIG.validAuthority,
correlationId: TEST_CONFIG.CORRELATION_ID,
forceRefresh: false,
claims: `{ "access_token": { "xms_cc":{"values":["cp1"] } }}`,
};

const response = await client.acquireCachedToken(silentFlowRequest);
const authResult: AuthenticationResult = response[0];
expect(authResult.authority).toEqual(
`${TEST_URIS.DEFAULT_INSTANCE}${TEST_CONFIG.TENANT}/`
);
expect(authResult.uniqueId).toEqual(ID_TOKEN_CLAIMS.oid);
expect(authResult.tenantId).toEqual(ID_TOKEN_CLAIMS.tid);
expect(authResult.scopes).toEqual(testScopes);
expect(authResult.account).toEqual(testAccount);
expect(authResult.idToken).toEqual(testIdToken.secret);
expect(authResult.idTokenClaims).toEqual(ID_TOKEN_CLAIMS);
expect(authResult.accessToken).toEqual(
testAccessTokenEntity.secret
);
expect(authResult.state).toBe("");
});

it("acquireCachedToken returns correct token when max age is provided and has not transpired yet", async () => {
const testScopes = [
Constants.OPENID_SCOPE,
Expand Down
54 changes: 19 additions & 35 deletions lib/msal-common/test/config/ClientConfiguration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ import {
import { MockStorageClass, mockCrypto } from "../client/ClientTestUtils";
import { MockCache } from "../cache/entities/cacheConstants";
import { Constants } from "../../src/utils/Constants";
import {
ClientAuthErrorCodes,
ClientConfigurationErrorCodes,
createClientAuthError,
createClientConfigurationError,
} from "../../src";
import { ClientAuthErrorCodes, createClientAuthError } from "../../src";

describe("ClientConfiguration.ts Class Unit Tests", () => {
it("buildConfiguration assigns default functions", async () => {
Expand All @@ -36,21 +31,21 @@ describe("ClientConfiguration.ts Class Unit Tests", () => {
expect(emptyConfig.cryptoInterface.base64Decode).not.toBeNull();
expect(() =>
emptyConfig.cryptoInterface.base64Decode("test input")
).toThrow(
).toThrowError(
createClientAuthError(ClientAuthErrorCodes.methodNotImplemented)
);
expect(() =>
emptyConfig.cryptoInterface.base64Decode("test input")
).toThrow(AuthError);
).toThrowError(AuthError);
expect(emptyConfig.cryptoInterface.base64Encode).not.toBeNull();
expect(() =>
emptyConfig.cryptoInterface.base64Encode("test input")
).toThrow(
).toThrowError(
createClientAuthError(ClientAuthErrorCodes.methodNotImplemented)
);
expect(() =>
emptyConfig.cryptoInterface.base64Encode("test input")
).toThrow(AuthError);
).toThrowError(AuthError);
// Storage interface checks
expect(emptyConfig.storageInterface).not.toBeNull();
expect(emptyConfig.storageInterface.clear).not.toBeNull();
Expand All @@ -62,35 +57,37 @@ describe("ClientConfiguration.ts Class Unit Tests", () => {
expect(emptyConfig.storageInterface.getAccount).not.toBeNull();
expect(() =>
emptyConfig.storageInterface.getAccount("testKey")
).toThrow(
).toThrowError(
createClientAuthError(ClientAuthErrorCodes.methodNotImplemented)
);
expect(() =>
emptyConfig.storageInterface.getAccount("testKey")
).toThrow(AuthError);
).toThrowError(AuthError);
expect(emptyConfig.storageInterface.getKeys).not.toBeNull();
expect(() => emptyConfig.storageInterface.getKeys()).toThrow(
expect(() => emptyConfig.storageInterface.getKeys()).toThrowError(
createClientAuthError(ClientAuthErrorCodes.methodNotImplemented)
);
expect(() => emptyConfig.storageInterface.getKeys()).toThrow(AuthError);
expect(() => emptyConfig.storageInterface.getKeys()).toThrowError(
AuthError
);
expect(emptyConfig.storageInterface.removeItem).not.toBeNull();
expect(() =>
emptyConfig.storageInterface.removeItem("testKey")
).toThrow(
).toThrowError(
createClientAuthError(ClientAuthErrorCodes.methodNotImplemented)
);
expect(() =>
emptyConfig.storageInterface.removeItem("testKey")
).toThrow(AuthError);
).toThrowError(AuthError);
expect(emptyConfig.storageInterface.setAccount).not.toBeNull();
expect(() =>
emptyConfig.storageInterface.setAccount(MockCache.acc)
).toThrow(
).toThrowError(
createClientAuthError(ClientAuthErrorCodes.methodNotImplemented)
);
expect(() =>
emptyConfig.storageInterface.setAccount(MockCache.acc)
).toThrow(AuthError);
).toThrowError(AuthError);
// Network interface checks
expect(emptyConfig.networkInterface).not.toBeNull();
expect(emptyConfig.networkInterface.sendGetRequestAsync).not.toBeNull();
Expand Down Expand Up @@ -194,6 +191,9 @@ describe("ClientConfiguration.ts Class Unit Tests", () => {
): void => {},
piiLoggingEnabled: true,
},
cacheOptions: {
claimsBasedCachingEnabled: true,
},
libraryInfo: {
sku: TEST_CONFIG.TEST_SKU,
version: TEST_CONFIG.TEST_VERSION,
Expand Down Expand Up @@ -265,7 +265,7 @@ describe("ClientConfiguration.ts Class Unit Tests", () => {
expect(newConfig.loggerOptions.piiLoggingEnabled).toBe(true);
// Cache options tests
expect(newConfig.cacheOptions).not.toBeNull();
expect(newConfig.cacheOptions.claimsBasedCachingEnabled).toBe(false);
expect(newConfig.cacheOptions.claimsBasedCachingEnabled).toBe(true);
// Client info tests
expect(newConfig.libraryInfo.sku).toBe(TEST_CONFIG.TEST_SKU);
expect(newConfig.libraryInfo.version).toBe(TEST_CONFIG.TEST_VERSION);
Expand All @@ -279,20 +279,4 @@ describe("ClientConfiguration.ts Class Unit Tests", () => {
TEST_CONFIG.TEST_APP_VER
);
});

test("throws an error when claimsBasedCaching is enabled", async () => {
expect(() => {
buildClientConfiguration({
//@ts-ignore
authOptions: {
clientId: TEST_CONFIG.MSAL_CLIENT_ID,
},
cacheOptions: { claimsBasedCachingEnabled: true },
});
}).toThrow(
createClientConfigurationError(
ClientConfigurationErrorCodes.claimsBasedCachingEnabled
)
);
});
});
11 changes: 3 additions & 8 deletions lib/msal-node/src/config/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import {
AzureCloudOptions,
ApplicationTelemetry,
INativeBrokerPlugin,
createClientConfigurationError,
ClientConfigurationErrorCodes,
} from "@azure/msal-common";
import { HttpClient } from "../network/HttpClient.js";
import http from "http";
Expand Down Expand Up @@ -67,6 +65,9 @@ export type NodeAuthOptions = {
*/
export type CacheOptions = {
cachePlugin?: ICachePlugin;
/**
* @deprecated claims-based-caching functionality will be removed in the next version of MSALJS
*/
claimsBasedCachingEnabled?: boolean;
};

Expand Down Expand Up @@ -205,12 +206,6 @@ export function buildAppConfiguration({
system,
telemetry,
}: Configuration): NodeConfiguration {
if (cache?.claimsBasedCachingEnabled) {
throw createClientConfigurationError(
ClientConfigurationErrorCodes.claimsBasedCachingEnabled
);
}

const systemOptions: Required<NodeSystemOptions> = {
...DEFAULT_SYSTEM_OPTIONS,
networkClient: new HttpClient(
Expand Down
16 changes: 0 additions & 16 deletions lib/msal-node/test/client/ClientCredentialClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import {
createClientAuthError,
ClientAuthErrorCodes,
CacheHelpers,
createClientConfigurationError,
ClientConfigurationErrorCodes,
} from "@azure/msal-common";
import { ClientCredentialClient, UsernamePasswordClient } from "../../src";
import {
Expand Down Expand Up @@ -502,20 +500,6 @@ describe("ClientCredentialClient unit tests", () => {
);
});

it("An error is thrown when claims based caching is enabled", async () => {
expect(() => {
// will use msal-common's buildAppConfiguration
new ClientCredentialClient({
...config,
cacheOptions: { claimsBasedCachingEnabled: true },
});
}).toThrow(
createClientConfigurationError(
ClientConfigurationErrorCodes.claimsBasedCachingEnabled
)
);
});

it("Does not add claims when empty object provided", async () => {
const client: ClientCredentialClient = new ClientCredentialClient(
config
Expand Down
Loading

0 comments on commit 650c083

Please sign in to comment.