Skip to content

Commit

Permalink
Merge branch 'dev' into node-22
Browse files Browse the repository at this point in the history
  • Loading branch information
tnorling authored Apr 29, 2024
2 parents f17a1b6 + b4736b1 commit b7667ac
Show file tree
Hide file tree
Showing 20 changed files with 386 additions and 198 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Add getAccount API to IPublicClientApplication (#7019)",
"packageName": "@azure/msal-browser",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": " Fixed inconsistencies with cancellationToken (timeout)",
"packageName": "@azure/msal-common",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Make performanceClient.discardMeasurements() flush aux cache data in addition to measurements #7061",
"packageName": "@azure/msal-common",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": " Fixed inconsistencies with cancellationToken (timeout)",
"packageName": "@azure/msal-node",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Fix useIsAuthenticated returning incorrect value during useEffect update #7057",
"packageName": "@azure/msal-react",
"email": "[email protected]",
"dependentChangeType": "patch"
}
1 change: 1 addition & 0 deletions lib/msal-browser/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const msalConfig = {
postLogoutRedirectUri: "enter_postlogout_uri_here",
navigateToLoginRequestUrl: true,
clientCapabilities: ["CP1"],
protocolMode: "AAD"
},
cache: {
cacheLocation: "sessionStorage",
Expand Down
15 changes: 14 additions & 1 deletion lib/msal-browser/docs/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ msalInstance.acquireTokenSilent(); // This will also no longer throw this error

## Other

Errors not thrown by MSAL, such as server errors.
Errors not thrown by MSAL, such as server or cache errors.

### Access to fetch at [url] has been blocked by CORS policy

Expand All @@ -418,3 +418,16 @@ This error occurs with MSAL.js v2.x and is due to improper configuration during
> Your Redirect URI is eligible for the Authorization Code Flow with PKCE.
![image](https://user-images.githubusercontent.com/5307810/110390912-922fa380-801b-11eb-9e2b-d7aa88ca0687.png)

### cache_quota_exceeded

**Error messages**:

- Exceeded cache storage capacity

This error occurs when MSAL.js surpasses the allotted storage limit when attempting to save token information in the [configured cache storage](./caching.md#cache-storage). See [here](https://developer.mozilla.org/en-US/docs/Web/API/Storage_API/Storage_quotas_and_eviction_criteria#web_storage) for web storage limits.

**Mitigation**:

1. Make sure the configured cache storage has enough capacity to allow MSAL.js to persist token payload. The amount of cache storage required depends on the number of [cached artifacts](./caching.md#cached-artifacts).
2. Disable [claimsBasedCachingEnabled](./configuration.md#cache-config-options) cache config option. When enabled, it caches access tokens under a key containing the hash of the requested claims. Depending on the MSAL.js API usage, it may result in the vast number of access tokens persisted in the cache storage.
5 changes: 5 additions & 0 deletions lib/msal-browser/src/app/IPublicClientApplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import {
AccountFilter,
AccountInfo,
Logger,
PerformanceCallbackFunction,
Expand Down Expand Up @@ -43,6 +44,7 @@ export interface IPublicClientApplication {
removePerformanceCallback(callbackId: string): boolean;
enableAccountStorageEvents(): void;
disableAccountStorageEvents(): void;
getAccount(accountFilter: AccountFilter): AccountInfo | null;
getAccountByHomeId(homeAccountId: string): AccountInfo | null;
getAccountByLocalId(localId: string): AccountInfo | null;
getAccountByUsername(userName: string): AccountInfo | null;
Expand Down Expand Up @@ -113,6 +115,9 @@ export const stubbedPublicClientApplication: IPublicClientApplication = {
getAllAccounts: () => {
return [];
},
getAccount: () => {
return null;
},
getAccountByHomeId: () => {
return null;
},
Expand Down
2 changes: 1 addition & 1 deletion lib/msal-common/src/network/INetworkModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface INetworkModule {
sendGetRequestAsync<T>(
url: string,
options?: NetworkRequestOptions,
cancellationToken?: number
timeout?: number
): Promise<NetworkResponse<T>>;

/**
Expand Down
13 changes: 2 additions & 11 deletions lib/msal-common/src/telemetry/performance/PerformanceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ export abstract class PerformanceClient implements IPerformanceClient {

if (isRoot) {
queueInfo = this.getQueueInfo(event.correlationId);
this.discardCache(rootEvent.correlationId);
this.discardMeasurements(rootEvent.correlationId);
} else {
rootEvent.incompleteSubMeasurements?.delete(event.eventId);
}
Expand Down Expand Up @@ -781,7 +781,7 @@ export abstract class PerformanceClient implements IPerformanceClient {
}

/**
* Removes measurements for a given correlation id.
* Removes measurements and aux data for a given correlation id.
*
* @param {string} correlationId
*/
Expand All @@ -791,15 +791,6 @@ export abstract class PerformanceClient implements IPerformanceClient {
correlationId
);
this.eventsByCorrelationId.delete(correlationId);
}

/**
* Removes cache for a given correlation id.
*
* @param {string} correlationId correlation identifier
*/
private discardCache(correlationId: string): void {
this.discardMeasurements(correlationId);

this.logger.trace(
"PerformanceClient: QueueMeasurements discarded",
Expand Down
6 changes: 4 additions & 2 deletions lib/msal-common/src/utils/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,24 @@ export const Constants = {
};

export const HttpStatus = {
SUCCESS_RANGE_START: 200,
SUCCESS: 200,
SUCCESS_RANGE_START: 200,
SUCCESS_RANGE_END: 299,
REDIRECT: 302,
CLIENT_ERROR: 400,
CLIENT_ERROR_RANGE_START: 400,
BAD_REQUEST: 400,
UNAUTHORIZED: 401,
NOT_FOUND: 404,
REQUEST_TIMEOUT: 408,
TOO_MANY_REQUESTS: 429,
CLIENT_ERROR_RANGE_END: 499,
SERVER_ERROR: 500,
SERVER_ERROR_RANGE_START: 500,
INTERNAL_SERVER_ERROR: 500,
SERVICE_UNAVAILABLE: 503,
GATEWAY_TIMEOUT: 504,
SERVER_ERROR_RANGE_END: 599,
MULTI_SIDED_ERROR: 600,
} as const;
export type HttpStatus = (typeof HttpStatus)[keyof typeof HttpStatus];

Expand Down
76 changes: 75 additions & 1 deletion lib/msal-common/test/telemetry/PerformanceClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ export class MockPerformanceClient
eventName: PerformanceEvents,
correlationId?: string | undefined
): void {
return;
this.preQueueTimeByCorrelationId.set(correlationId || "", {
name: eventName,
time: 12345,
});
}

getDurationMs(startTimeMs: number): number {
Expand Down Expand Up @@ -1122,4 +1125,75 @@ describe("PerformanceClient.spec.ts", () => {
rootEvent.end({ success: true });
});
});

describe("discard", () => {
it("discards cache data", () => {
const mockPerfClient = new MockPerformanceClient();
const correlationId = "test-correlation-id";
const dummyCorrelationId = "dummy-correlation-id";

const rootEvent = mockPerfClient.startMeasurement(
PerformanceEvents.AcquireTokenSilent,
correlationId
);
const firstEvent = mockPerfClient.startMeasurement(
PerformanceEvents.AcquireTokenSilentAsync,
correlationId
);
mockPerfClient.setPreQueueTime(
PerformanceEvents.AcquireTokenSilentAsync,
correlationId
);
const secondEvent = mockPerfClient.startMeasurement(
PerformanceEvents.AcquireTokenFromCache,
correlationId
);
mockPerfClient.setPreQueueTime(
PerformanceEvents.AcquireTokenFromCache,
correlationId
);
secondEvent.end({ success: true });
firstEvent.end({ success: true });
rootEvent.discard();

mockPerfClient.startMeasurement(
PerformanceEvents.AcquireTokenSilent,
dummyCorrelationId
);
mockPerfClient.setPreQueueTime(
PerformanceEvents.AcquireTokenSilent,
dummyCorrelationId
);

expect(
// @ts-ignore
mockPerfClient.eventsByCorrelationId.has(correlationId)
).toBeFalsy();
expect(
// @ts-ignore
mockPerfClient.preQueueTimeByCorrelationId.has(correlationId)
).toBeFalsy();
expect(
// @ts-ignore
mockPerfClient.queueMeasurements.has(correlationId)
).toBeFalsy();
// @ts-ignore
expect(mockPerfClient.eventStack.has(correlationId)).toBeFalsy();

expect(
// @ts-ignore
mockPerfClient.eventsByCorrelationId.has(dummyCorrelationId)
).toBeTruthy();
expect(
// @ts-ignore
mockPerfClient.preQueueTimeByCorrelationId.has(
dummyCorrelationId
)
).toBeTruthy();
expect(
// @ts-ignore
mockPerfClient.eventStack.has(dummyCorrelationId)
).toBeTruthy();
});
});
});
Loading

0 comments on commit b7667ac

Please sign in to comment.