Skip to content

Commit dc60b43

Browse files
Ugonnaak1Copilot
andauthored
Surface Errors from MsalRuntime with Interaction Required (#7961)
When customers use `acquireTokenSilent` with msal-node-runtime, errors reported to OneAuth-MSAL (such as interaction_required) are surfaced as: ```   "errormessage": "interaction_required: (pii)",   "errorname": "InteractionRequiredAuthError",   "errorstack": "InteractionRequiredAuthError: interaction_required: (pii)\n at ue.wrapError (c:\\Program <REDACTED: user-file-path> VS <REDACTED: user-file-path>:2:386244)\n at Object.o (c:\\Program <REDACTED: user-file-path> VS <REDACTED: user-file-path>:2:381487)" ``` However, these errors lack critical context such as the error code and error tag from the broker or our library which makes it difficult for our team to diagnose and resolve their issues. This PR helps surface errors for interaction-required scenarios by replacing `InteractionRequiredAuthError` with `NativeAuthError` for InteractionRequired Status in NativeBrokerPlugin and enhancing the NativeAuthError context --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 5dc2f55 commit dc60b43

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "Surface Errors from MsalRuntime with Interaction Required #7961",
4+
"packageName": "@azure/msal-node-extensions",
5+
"email": "akaliugonna@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,12 +645,15 @@ export class NativeBrokerPlugin implements INativeBrokerPlugin {
645645
) {
646646
const { errorCode, errorStatus, errorContext, errorTag } =
647647
error as MsalRuntimeError;
648+
const enhancedErrorContext = errorContext
649+
? `${errorContext} (Error Code: ${errorCode}, Tag: ${errorTag})`
650+
: `(Error Code: ${errorCode}, Tag: ${errorTag})`;
648651
switch (errorStatus) {
649652
case ErrorStatus.InteractionRequired:
650653
case ErrorStatus.AccountUnusable:
651654
return new InteractionRequiredAuthError(
652655
ErrorCodes.INTERATION_REQUIRED_ERROR_CODE,
653-
errorContext
656+
enhancedErrorContext
654657
);
655658
case ErrorStatus.NoNetwork:
656659
case ErrorStatus.NetworkTemporarilyUnavailable:
@@ -680,7 +683,7 @@ export class NativeBrokerPlugin implements INativeBrokerPlugin {
680683
default:
681684
return new NativeAuthError(
682685
ErrorStatus[errorStatus],
683-
errorContext,
686+
enhancedErrorContext,
684687
errorCode,
685688
errorTag
686689
);

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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
jest.mock("@azure/msal-node-runtime", () => {
2+
const actual = jest.requireActual("@azure/msal-node-runtime");
23
return {
4+
...actual,
35
msalNodeRuntime: {
6+
...actual.msalNodeRuntime,
47
SignInSilentlyAsync: jest.fn(),
58
SignInAsync: jest.fn(),
69
AcquireTokenSilentlyAsync: jest.fn(),
@@ -20,18 +23,6 @@ jest.mock("@azure/msal-node-runtime", () => {
2023
SetAdditionalParameter: jest.fn(),
2124
})),
2225
},
23-
ErrorStatus: {
24-
Unexpected: 0,
25-
InteractionRequired: 1,
26-
AccountUnusable: 2,
27-
NoNetwork: 3,
28-
NetworkTemporarilyUnavailable: 4,
29-
ServerTemporarilyUnavailable: 5,
30-
UserCanceled: 6,
31-
AuthorityUntrusted: 7,
32-
UserSwitched: 8,
33-
AccountNotFound: 9,
34-
},
3526
};
3627
});
3728
import { NativeBrokerPlugin } from "../../src/broker/NativeBrokerPlugin";
@@ -95,9 +86,12 @@ function createMockAuthResult(
9586

9687
if (process.platform === "win32") {
9788
describe("NativeBrokerPlugin", () => {
89+
const enhancedErrorContext = msalRuntimeExampleError.errorContext
90+
? `${msalRuntimeExampleError.errorContext} (Error Code: ${msalRuntimeExampleError.errorCode}, Tag: ${msalRuntimeExampleError.errorTag})`
91+
: `(Error Code: ${msalRuntimeExampleError.errorCode}, Tag: ${msalRuntimeExampleError.errorTag})`;
9892
const testNativeAuthError = new NativeAuthError(
9993
ErrorStatus[msalRuntimeExampleError.errorStatus],
100-
msalRuntimeExampleError.errorContext,
94+
enhancedErrorContext,
10195
msalRuntimeExampleError.errorCode,
10296
msalRuntimeExampleError.errorTag
10397
);

0 commit comments

Comments
 (0)