Skip to content

Commit c4835e8

Browse files
sameeragCopilot
andcommitted
[correlationId] Make correlationId a required parameter on AuthError constructors
Squash-rebased onto dev. Threads a required correlationId through error constructors and creation helpers across msal-common, msal-browser, msal-node, msal-react, msal-angular, and msal-node-extensions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f06838b commit c4835e8

176 files changed

Lines changed: 2690 additions & 1052 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "minor",
3+
"comment": "Pass correlationId to errors to match the updated msal-browser error signature [#8609](https://github.com/AzureAD/microsoft-authentication-library-for-js/pull/8609)",
4+
"packageName": "@azure/msal-angular",
5+
"email": "sameera.gajjarapu@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "minor",
3+
"comment": "Make correlationId a required parameter on AuthError and all derived error classes [#8609](https://github.com/AzureAD/microsoft-authentication-library-for-js/pull/8609)",
4+
"packageName": "@azure/msal-browser",
5+
"email": "sameera.gajjarapu@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "minor",
3+
"comment": "Make correlationId a required parameter on AuthError and all derived error classes [#8609](https://github.com/AzureAD/microsoft-authentication-library-for-js/pull/8609)",
4+
"packageName": "@azure/msal-common",
5+
"email": "sameera.gajjarapu@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "minor",
3+
"comment": "Make correlationId a required parameter on NodeAuthError and ManagedIdentityError, [#8609](https://github.com/AzureAD/microsoft-authentication-library-for-js/pull/8609)",
4+
"packageName": "@azure/msal-node",
5+
"email": "sameera.gajjarapu@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "minor",
3+
"comment": "Match the updated msal-common error signatures [#8609](https://github.com/AzureAD/microsoft-authentication-library-for-js/pull/8609)",
4+
"packageName": "@azure/msal-node-extensions",
5+
"email": "sameera.gajjarapu@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "minor",
3+
"comment": "Match the updated msal-browser AuthError signature [#8609](https://github.com/AzureAD/microsoft-authentication-library-for-js/pull/8609)",
4+
"packageName": "@azure/msal-react",
5+
"email": "sameera.gajjarapu@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}

extensions/msal-node-extensions/src/broker/NativeBrokerPlugin.ts

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export class NativeBrokerPlugin implements INativeBrokerPlugin {
120120
loggerOptions.piiLoggingEnabled || false
121121
);
122122
} catch (e) {
123-
const wrappedError = this.wrapError(e);
123+
const wrappedError = this.wrapError(e, "");
124124
if (wrappedError) {
125125
throw wrappedError;
126126
}
@@ -155,7 +155,7 @@ export class NativeBrokerPlugin implements INativeBrokerPlugin {
155155
try {
156156
result.CheckError();
157157
} catch (e) {
158-
const wrappedError = this.wrapError(e);
158+
const wrappedError = this.wrapError(e, correlationId);
159159
if (wrappedError) {
160160
reject(wrappedError);
161161
return;
@@ -176,7 +176,7 @@ export class NativeBrokerPlugin implements INativeBrokerPlugin {
176176
resultCallback
177177
);
178178
} catch (e) {
179-
const wrappedError = this.wrapError(e);
179+
const wrappedError = this.wrapError(e, correlationId);
180180
if (wrappedError) {
181181
reject(wrappedError);
182182
}
@@ -209,7 +209,10 @@ export class NativeBrokerPlugin implements INativeBrokerPlugin {
209209
try {
210210
result.CheckError();
211211
} catch (e) {
212-
const wrappedError = this.wrapError(e);
212+
const wrappedError = this.wrapError(
213+
e,
214+
request.correlationId
215+
);
213216
if (wrappedError) {
214217
reject(wrappedError);
215218
return;
@@ -238,7 +241,10 @@ export class NativeBrokerPlugin implements INativeBrokerPlugin {
238241
);
239242
}
240243
} catch (e) {
241-
const wrappedError = this.wrapError(e);
244+
const wrappedError = this.wrapError(
245+
e,
246+
request.correlationId
247+
);
242248
if (wrappedError) {
243249
reject(wrappedError);
244250
}
@@ -274,7 +280,10 @@ export class NativeBrokerPlugin implements INativeBrokerPlugin {
274280
try {
275281
result.CheckError();
276282
} catch (e) {
277-
const wrappedError = this.wrapError(e);
283+
const wrappedError = this.wrapError(
284+
e,
285+
request.correlationId
286+
);
278287
if (wrappedError) {
279288
reject(wrappedError);
280289
return;
@@ -360,7 +369,10 @@ export class NativeBrokerPlugin implements INativeBrokerPlugin {
360369
break;
361370
}
362371
} catch (e) {
363-
const wrappedError = this.wrapError(e);
372+
const wrappedError = this.wrapError(
373+
e,
374+
request.correlationId
375+
);
364376
if (wrappedError) {
365377
reject(wrappedError);
366378
}
@@ -377,15 +389,21 @@ export class NativeBrokerPlugin implements INativeBrokerPlugin {
377389

378390
const account = await this.getAccount(request);
379391
if (!account) {
380-
throw createClientAuthError(ClientAuthErrorCodes.noAccountFound);
392+
throw createClientAuthError(
393+
ClientAuthErrorCodes.noAccountFound,
394+
request.correlationId
395+
);
381396
}
382397

383398
return new Promise((resolve, reject) => {
384399
const resultCallback = (result: SignOutResult) => {
385400
try {
386401
result.CheckError();
387402
} catch (e) {
388-
const wrappedError = this.wrapError(e);
403+
const wrappedError = this.wrapError(
404+
e,
405+
request.correlationId
406+
);
389407
if (wrappedError) {
390408
reject(wrappedError);
391409
return;
@@ -402,7 +420,7 @@ export class NativeBrokerPlugin implements INativeBrokerPlugin {
402420
resultCallback
403421
);
404422
} catch (e) {
405-
const wrappedError = this.wrapError(e);
423+
const wrappedError = this.wrapError(e, request.correlationId);
406424
if (wrappedError) {
407425
reject(wrappedError);
408426
}
@@ -437,7 +455,7 @@ export class NativeBrokerPlugin implements INativeBrokerPlugin {
437455
try {
438456
result.CheckError();
439457
} catch (e) {
440-
const wrappedError = this.wrapError(e);
458+
const wrappedError = this.wrapError(e, correlationId);
441459
if (wrappedError) {
442460
reject(wrappedError);
443461
return;
@@ -453,7 +471,7 @@ export class NativeBrokerPlugin implements INativeBrokerPlugin {
453471
resultCallback
454472
);
455473
} catch (e) {
456-
const wrappedError = this.wrapError(e);
474+
const wrappedError = this.wrapError(e, correlationId);
457475
if (wrappedError) {
458476
reject(wrappedError);
459477
}
@@ -534,7 +552,7 @@ export class NativeBrokerPlugin implements INativeBrokerPlugin {
534552
})
535553
);
536554
} catch (e) {
537-
const wrappedError = this.wrapError(e);
555+
const wrappedError = this.wrapError(e, request.correlationId);
538556
if (wrappedError) {
539557
throw wrappedError;
540558
}
@@ -657,7 +675,10 @@ export class NativeBrokerPlugin implements INativeBrokerPlugin {
657675
);
658676
}
659677

660-
private wrapError(error: unknown): PlatformBrokerError | Object | null {
678+
private wrapError(
679+
error: unknown,
680+
correlationId: string
681+
): PlatformBrokerError | Object | null {
661682
if (
662683
error &&
663684
typeof error === "object" &&
@@ -668,6 +689,7 @@ export class NativeBrokerPlugin implements INativeBrokerPlugin {
668689

669690
const msalNodeRuntimeError = new PlatformBrokerError(
670691
ErrorStatus[errorStatus],
692+
correlationId,
671693
errorContext,
672694
errorCode,
673695
errorTag
@@ -680,42 +702,49 @@ export class NativeBrokerPlugin implements INativeBrokerPlugin {
680702
case ErrorStatus.AccountUnusable:
681703
wrappedError = new InteractionRequiredAuthError(
682704
ErrorCodes.INTERATION_REQUIRED_ERROR_CODE,
705+
correlationId,
683706
msalNodeRuntimeError.message
684707
);
685708
break;
686709
case ErrorStatus.NoNetwork:
687710
case ErrorStatus.NetworkTemporarilyUnavailable:
688711
wrappedError = createClientAuthError(
689-
ClientAuthErrorCodes.noNetworkConnectivity
712+
ClientAuthErrorCodes.noNetworkConnectivity,
713+
correlationId
690714
);
691715
break;
692716
case ErrorStatus.ServerTemporarilyUnavailable:
693717
wrappedError = new ServerError(
694718
ErrorCodes.SERVER_UNAVAILABLE,
719+
correlationId,
695720
msalNodeRuntimeError.message
696721
);
697722
break;
698723
case ErrorStatus.UserCanceled:
699724
wrappedError = createClientAuthError(
700-
ClientAuthErrorCodes.userCanceled
725+
ClientAuthErrorCodes.userCanceled,
726+
correlationId
701727
);
702728
break;
703729
case ErrorStatus.AuthorityUntrusted:
704730
wrappedError = createClientConfigurationError(
705-
ClientConfigurationErrorCodes.untrustedAuthority
731+
ClientConfigurationErrorCodes.untrustedAuthority,
732+
correlationId
706733
);
707734
break;
708735
case ErrorStatus.UserSwitched:
709736
// Not an error case, if there's customer demand we can surface this as a response property
710737
return null;
711738
case ErrorStatus.AccountNotFound:
712739
wrappedError = createClientAuthError(
713-
ClientAuthErrorCodes.noAccountFound
740+
ClientAuthErrorCodes.noAccountFound,
741+
correlationId
714742
);
715743
break;
716744
default:
717745
wrappedError = createClientAuthError(
718-
ClientAuthErrorCodes.platformBrokerError
746+
ClientAuthErrorCodes.platformBrokerError,
747+
correlationId
719748
);
720749
}
721750

extensions/msal-node-extensions/test/broker/NativeBrokerPlugin.spec.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,16 @@ if (process.platform === "win32") {
8888
describe("NativeBrokerPlugin", () => {
8989
const testPlatformBrokerError = new PlatformBrokerError(
9090
ErrorStatus[msalRuntimeExampleError.errorStatus],
91+
"",
9192
msalRuntimeExampleError.errorContext,
9293
msalRuntimeExampleError.errorCode,
9394
msalRuntimeExampleError.errorTag
9495
);
9596

9697
// Expected wrapped error for the default case (Unexpected status)
9798
const testWrappedBrokerError = createClientAuthError(
98-
ClientAuthErrorCodes.platformBrokerError
99+
ClientAuthErrorCodes.platformBrokerError,
100+
""
99101
);
100102
testWrappedBrokerError.platformBrokerError = testPlatformBrokerError;
101103

@@ -1770,7 +1772,10 @@ if (process.platform === "win32") {
17701772
await expect(
17711773
nativeBrokerPlugin.signOut(request)
17721774
).rejects.toThrowError(
1773-
createClientAuthError(ClientAuthErrorCodes.noAccountFound)
1775+
createClientAuthError(
1776+
ClientAuthErrorCodes.noAccountFound,
1777+
""
1778+
)
17741779
);
17751780
});
17761781

@@ -2040,7 +2045,8 @@ if (process.platform === "win32") {
20402045
.catch((error) => {
20412046
expect(error).toStrictEqual(
20422047
createClientAuthError(
2043-
ClientAuthErrorCodes.noNetworkConnectivity
2048+
ClientAuthErrorCodes.noNetworkConnectivity,
2049+
""
20442050
)
20452051
);
20462052
done();
@@ -2100,7 +2106,8 @@ if (process.platform === "win32") {
21002106
.catch((error) => {
21012107
expect(error).toStrictEqual(
21022108
createClientAuthError(
2103-
ClientAuthErrorCodes.noNetworkConnectivity
2109+
ClientAuthErrorCodes.noNetworkConnectivity,
2110+
""
21042111
)
21052112
);
21062113
done();
@@ -2215,7 +2222,8 @@ if (process.platform === "win32") {
22152222
.catch((error) => {
22162223
expect(error).toStrictEqual(
22172224
createClientAuthError(
2218-
ClientAuthErrorCodes.userCanceled
2225+
ClientAuthErrorCodes.userCanceled,
2226+
""
22192227
)
22202228
);
22212229
done();
@@ -2274,7 +2282,8 @@ if (process.platform === "win32") {
22742282
.catch((error) => {
22752283
expect(error).toStrictEqual(
22762284
createClientConfigurationError(
2277-
ClientConfigurationErrorCodes.untrustedAuthority
2285+
ClientConfigurationErrorCodes.untrustedAuthority,
2286+
""
22782287
)
22792288
);
22802289
done();
@@ -2397,7 +2406,8 @@ if (process.platform === "win32") {
23972406
.catch((error) => {
23982407
expect(error).toStrictEqual(
23992408
createClientAuthError(
2400-
ClientAuthErrorCodes.noAccountFound
2409+
ClientAuthErrorCodes.noAccountFound,
2410+
""
24012411
)
24022412
);
24032413
done();

lib/msal-angular/src/msal.guard.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ export class MsalGuard {
132132
) {
133133
throw new BrowserConfigurationAuthError(
134134
"invalid_interaction_type",
135+
"",
135136
"Invalid interaction type provided to MSAL Guard. InteractionType.Popup or InteractionType.Redirect must be provided in the MsalGuardConfiguration"
136137
);
137138
}

lib/msal-angular/src/msal.interceptor.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ describe("MsalInterceptor", () => {
490490

491491
msalBroadcastService.inProgress$ = _inProgress.asObservable();
492492

493-
const sampleError = new AuthError("123", "message");
493+
const sampleError = new AuthError("123", "", "message");
494494
const sampleAccessToken = {
495495
accessToken: "123abc",
496496
};
@@ -549,7 +549,7 @@ describe("MsalInterceptor", () => {
549549

550550
msalBroadcastService.inProgress$ = _inProgress.asObservable();
551551

552-
const sampleError = new AuthError("123", "message");
552+
const sampleError = new AuthError("123", "", "message");
553553

554554
spyOn(
555555
PublicClientApplication.prototype,
@@ -593,7 +593,7 @@ describe("MsalInterceptor", () => {
593593

594594
msalBroadcastService.inProgress$ = _inProgress.asObservable();
595595

596-
const sampleError = new AuthError("123", "message");
596+
const sampleError = new AuthError("123", "", "message");
597597
const sampleAccessToken = {
598598
accessToken: "123abc",
599599
};
@@ -656,7 +656,7 @@ describe("MsalInterceptor", () => {
656656

657657
msalBroadcastService.inProgress$ = _inProgress.asObservable();
658658

659-
const sampleError = new AuthError("123", "message");
659+
const sampleError = new AuthError("123", "", "message");
660660
const sampleAccessToken = {
661661
accessToken: "123abc",
662662
};

0 commit comments

Comments
 (0)