Skip to content

Commit 32c6a1b

Browse files
authored
Adding new UX_NOT_ALLOWED suberror under InteractionRequired error type (#7834)
- UX_NOT_ALLOWED is a new sub_error in the platform auth flow that is thrown when there was a token request made from a web page without user interaction/presence on the page (Edge browser feature). - This PR also updates some logger statements.
1 parent 14fe619 commit 32c6a1b

10 files changed

+84
-37
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": "added UX_NOT_ALLOWED suberror to InteractionRequired error type #7834",
4+
"packageName": "@azure/msal-browser",
5+
"email": "[email protected]",
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": "patch",
3+
"comment": "added UX_NOT_ALLOWED suberror to InteractionRequired error type #7834",
4+
"packageName": "@azure/msal-common",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

lib/msal-browser/src/broker/nativeBroker/NativeStatusCodes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ export const TRANSIENT_ERROR = "TRANSIENT_ERROR";
1111
export const PERSISTENT_ERROR = "PERSISTENT_ERROR";
1212
export const DISABLED = "DISABLED";
1313
export const ACCOUNT_UNAVAILABLE = "ACCOUNT_UNAVAILABLE";
14+
export const UX_NOT_ALLOWED = "UX_NOT_ALLOWED";

lib/msal-browser/src/broker/nativeBroker/PlatformAuthProvider.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,18 +128,18 @@ export function isPlatformAuthAllowed(
128128
platformAuthProvider?: IPlatformAuthHandler,
129129
authenticationScheme?: AuthenticationScheme
130130
): boolean {
131-
logger.trace("isBrokerAvailable called");
131+
logger.trace("isPlatformAuthAllowed called");
132132
if (!config.system.allowPlatformBroker) {
133133
logger.trace(
134-
"isBrokerAvailable: allowPlatformBroker is not enabled, returning false"
134+
"isPlatformAuthAllowed: allowPlatformBroker is not enabled, returning false"
135135
);
136136
// Developer disabled WAM
137137
return false;
138138
}
139139

140140
if (!platformAuthProvider) {
141141
logger.trace(
142-
"isBrokerAvailable: Platform auth provider is not initialized, returning false"
142+
"isPlatformAuthAllowed: Platform auth provider is not initialized, returning false"
143143
);
144144
// Platform broker auth providers are not available
145145
return false;
@@ -150,12 +150,12 @@ export function isPlatformAuthAllowed(
150150
case AuthenticationScheme.BEARER:
151151
case AuthenticationScheme.POP:
152152
logger.trace(
153-
"isBrokerAvailable: authenticationScheme is supported, returning true"
153+
"isPlatformAuthAllowed: authenticationScheme is supported, returning true"
154154
);
155155
return true;
156156
default:
157157
logger.trace(
158-
"isBrokerAvailable: authenticationScheme is not supported, returning false"
158+
"isPlatformAuthAllowed: authenticationScheme is not supported, returning false"
159159
);
160160
return false;
161161
}

lib/msal-browser/src/error/NativeAuthError.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ export function createNativeAuthError(
102102
return createBrowserAuthError(
103103
BrowserAuthErrorCodes.noNetworkConnectivity
104104
);
105+
case NativeStatusCodes.UX_NOT_ALLOWED:
106+
return createInteractionRequiredAuthError(
107+
InteractionRequiredAuthErrorCodes.uxNotAllowed
108+
);
105109
}
106110
}
107111

lib/msal-browser/test/broker/PlatformAuthDOMHandler.spec.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
} from "../utils/StringConstants.js";
1717
import { PlatformAuthRequest } from "../../src/broker/nativeBroker/PlatformAuthRequest.js";
1818
import { NativeAuthError } from "../../src/error/NativeAuthError.js";
19-
import { sign } from "crypto";
2019

2120
describe("PlatformAuthDOMHandler tests", () => {
2221
let performanceClient: IPerformanceClient;
@@ -517,37 +516,38 @@ describe("PlatformAuthDOMHandler tests", () => {
517516
});
518517
});
519518

520-
describe("getDOMExtraParams tests", () => {});
521-
it("should return a valid DOMExtraParameters object", async () => {
522-
getSupportedContractsMock.mockResolvedValue([
523-
PlatformAuthConstants.PLATFORM_DOM_APIS,
524-
]);
525-
const platformAuthDOMHandler =
526-
await PlatformAuthDOMHandler.createProvider(
527-
logger,
528-
performanceClient,
529-
"test-correlation-id"
530-
);
531-
const testExtraParameters = {
532-
prompt: PromptValue.NONE,
533-
nonce: "test-nonce",
534-
claims: "test-claims",
535-
instanceAware: true,
536-
windowTitleSubstring: "test-window-substring",
537-
extendedExpiryToken: true,
538-
signPopToken: true,
539-
};
540-
const domExtraParams =
541-
//@ts-ignore
542-
platformAuthDOMHandler.getDOMExtraParams(testExtraParameters);
543-
expect(domExtraParams).toEqual({
544-
prompt: "none",
545-
nonce: "test-nonce",
546-
claims: "test-claims",
547-
instanceAware: "true",
548-
windowTitleSubstring: "test-window-substring",
549-
extendedExpiryToken: "true",
550-
signPopToken: "true",
519+
describe("getDOMExtraParams tests", () => {
520+
it("should return a valid DOMExtraParameters object", async () => {
521+
getSupportedContractsMock.mockResolvedValue([
522+
PlatformAuthConstants.PLATFORM_DOM_APIS,
523+
]);
524+
const platformAuthDOMHandler =
525+
await PlatformAuthDOMHandler.createProvider(
526+
logger,
527+
performanceClient,
528+
"test-correlation-id"
529+
);
530+
const testExtraParameters = {
531+
prompt: PromptValue.NONE,
532+
nonce: "test-nonce",
533+
claims: "test-claims",
534+
instanceAware: true,
535+
windowTitleSubstring: "test-window-substring",
536+
extendedExpiryToken: true,
537+
signPopToken: true,
538+
};
539+
const domExtraParams =
540+
//@ts-ignore
541+
platformAuthDOMHandler.getDOMExtraParams(testExtraParameters);
542+
expect(domExtraParams).toEqual({
543+
prompt: "none",
544+
nonce: "test-nonce",
545+
claims: "test-claims",
546+
instanceAware: "true",
547+
windowTitleSubstring: "test-window-substring",
548+
extendedExpiryToken: "true",
549+
signPopToken: "true",
550+
});
551551
});
552552
});
553553
});

lib/msal-browser/test/error/NativeAuthError.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
} from "../../src/error/NativeAuthError";
77
import {
88
InteractionRequiredAuthError,
9+
InteractionRequiredAuthErrorCodes,
910
InteractionRequiredAuthErrorMessage,
1011
} from "@azure/msal-common";
1112
import {
@@ -119,6 +120,23 @@ describe("NativeAuthError Unit Tests", () => {
119120
);
120121
});
121122

123+
it("translates UX_NOT_ALLOWED status into corresponding InteractionRequiredError", () => {
124+
const error = createNativeAuthError(
125+
"interaction_required",
126+
"interaction is required",
127+
{
128+
error: 1,
129+
protocol_error: "testProtocolError",
130+
properties: {},
131+
status: NativeStatusCode.UX_NOT_ALLOWED,
132+
}
133+
);
134+
expect(error).toBeInstanceOf(InteractionRequiredAuthError);
135+
expect(error.errorCode).toBe(
136+
InteractionRequiredAuthErrorCodes.uxNotAllowed
137+
);
138+
});
139+
122140
it("translates USER_CANCEL status into corresponding BrowserAuthError", () => {
123141
const error = createNativeAuthError(
124142
"user_cancel",

lib/msal-common/apiReview/msal-common.api.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2603,6 +2603,7 @@ declare namespace InteractionRequiredAuthErrorCodes {
26032603
noTokensFound,
26042604
nativeAccountUnavailable,
26052605
refreshTokenExpired,
2606+
uxNotAllowed,
26062607
interactionRequired,
26072608
consentRequired,
26082609
loginRequired,
@@ -4481,6 +4482,11 @@ const userCanceled = "user_canceled";
44814482
// @public (undocumented)
44824483
const userTimeoutReached = "user_timeout_reached";
44834484

4485+
// Warning: (ae-missing-release-tag) "uxNotAllowed" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
4486+
//
4487+
// @public (undocumented)
4488+
const uxNotAllowed = "ux_not_allowed";
4489+
44844490
// Warning: (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
44854491
// Warning: (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
44864492
// Warning: (ae-missing-release-tag) "validateAuthorizationResponse" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)

lib/msal-common/src/error/InteractionRequiredAuthError.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const InteractionRequiredServerErrorMessage = [
1616
InteractionRequiredAuthErrorCodes.consentRequired,
1717
InteractionRequiredAuthErrorCodes.loginRequired,
1818
InteractionRequiredAuthErrorCodes.badToken,
19+
InteractionRequiredAuthErrorCodes.uxNotAllowed,
1920
];
2021

2122
export const InteractionRequiredAuthSubErrorMessage = [
@@ -36,6 +37,8 @@ const InteractionRequiredAuthErrorMessages = {
3637
"Refresh token has expired.",
3738
[InteractionRequiredAuthErrorCodes.badToken]:
3839
"Identity provider returned bad_token due to an expired or invalid refresh token. Please invoke an interactive API to resolve.",
40+
[InteractionRequiredAuthErrorCodes.uxNotAllowed]:
41+
"`canShowUI` flag in Edge was set to false. User interaction required on web page. Please invoke an interactive API to resolve.",
3942
};
4043

4144
/**

lib/msal-common/src/error/InteractionRequiredAuthErrorCodes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
export const noTokensFound = "no_tokens_found";
88
export const nativeAccountUnavailable = "native_account_unavailable";
99
export const refreshTokenExpired = "refresh_token_expired";
10+
export const uxNotAllowed = "ux_not_allowed";
1011

1112
// Codes potentially returned by server
1213
export const interactionRequired = "interaction_required";

0 commit comments

Comments
 (0)