Skip to content

Commit 6232735

Browse files
authored
Nested App Auth: allow empty parameters for loginPopup (#6941)
This change allows empty parameters for loginPopup by using a default request to match the behavior of StandardController. It also removes the dependency on crypto.randomUUID() which is not used elsewhere in the MSAL code base. Use the shared implementation to generate UUID v7 instead.
1 parent c9311d9 commit 6232735

File tree

4 files changed

+17
-25
lines changed

4 files changed

+17
-25
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "Nested App Auth: allow empty parameters for loginPopup (#6941)",
4+
"packageName": "@azure/msal-browser",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

lib/msal-browser/src/controllers/NestedAppAuthController.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ import { PopupRequest } from "../request/PopupRequest";
2626
import { RedirectRequest } from "../request/RedirectRequest";
2727
import { SilentRequest } from "../request/SilentRequest";
2828
import { SsoSilentRequest } from "../request/SsoSilentRequest";
29-
import { ApiId, WrapperSKU, InteractionType } from "../utils/BrowserConstants";
29+
import {
30+
ApiId,
31+
WrapperSKU,
32+
InteractionType,
33+
DEFAULT_REQUEST,
34+
} from "../utils/BrowserConstants";
3035
import { IController } from "./IController";
3136
import { TeamsAppOperatingContext } from "../operatingcontext/TeamsAppOperatingContext";
3237
import { IBridgeProxy } from "../naa/IBridgeProxy";
@@ -418,11 +423,7 @@ export class NestedAppAuthController implements IController {
418423
loginPopup(
419424
request?: PopupRequest | undefined // eslint-disable-line @typescript-eslint/no-unused-vars
420425
): Promise<AuthenticationResult> {
421-
if (request !== undefined) {
422-
return this.acquireTokenInteractive(request);
423-
} else {
424-
throw NestedAppAuthError.createUnsupportedError();
425-
}
426+
return this.acquireTokenInteractive(request || DEFAULT_REQUEST);
426427
}
427428
// eslint-disable-next-line @typescript-eslint/no-unused-vars
428429
loginRedirect(request?: RedirectRequest | undefined): Promise<void> {

lib/msal-browser/src/naa/BridgeProxy.ts

+3-12
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { BridgeStatusCode } from "./BridgeStatusCode";
1515
import { IBridgeProxy } from "./IBridgeProxy";
1616
import { InitContext } from "./InitContext";
1717
import { TokenRequest } from "./TokenRequest";
18+
import * as BrowserCrypto from "../crypto/BrowserCrypto";
1819

1920
declare global {
2021
interface Window {
@@ -29,7 +30,6 @@ declare global {
2930
*/
3031
export class BridgeProxy implements IBridgeProxy {
3132
static bridgeRequests: BridgeRequest[] = [];
32-
static crypto: Crypto;
3333
sdkName: string;
3434
sdkVersion: string;
3535
capabilities?: BridgeCapabilities;
@@ -47,13 +47,8 @@ export class BridgeProxy implements IBridgeProxy {
4747
if (window.nestedAppAuthBridge === undefined) {
4848
throw new Error("window.nestedAppAuthBridge is undefined");
4949
}
50-
if (window.crypto === undefined) {
51-
throw new Error("window.crypto is undefined");
52-
}
5350

5451
try {
55-
BridgeProxy.crypto = window.crypto;
56-
5752
window.nestedAppAuthBridge.addEventListener(
5853
"message",
5954
(response: AuthBridgeResponse) => {
@@ -84,7 +79,7 @@ export class BridgeProxy implements IBridgeProxy {
8479
const message: BridgeRequestEnvelope = {
8580
messageType: "NestedAppAuthRequest",
8681
method: "GetInitContext",
87-
requestId: BridgeProxy.getRandomId(),
82+
requestId: BrowserCrypto.createNewGuid(),
8883
};
8984
const request: BridgeRequest = {
9085
requestId: message.requestId,
@@ -108,10 +103,6 @@ export class BridgeProxy implements IBridgeProxy {
108103
}
109104
}
110105

111-
public static getRandomId(): string {
112-
return BridgeProxy.crypto.randomUUID();
113-
}
114-
115106
/**
116107
* getTokenInteractive - Attempts to get a token interactively from the bridge
117108
* @param request A token request
@@ -164,7 +155,7 @@ export class BridgeProxy implements IBridgeProxy {
164155
const message: BridgeRequestEnvelope = {
165156
messageType: "NestedAppAuthRequest",
166157
method: method,
167-
requestId: BridgeProxy.getRandomId(),
158+
requestId: BrowserCrypto.createNewGuid(),
168159
...requestParams,
169160
};
170161

lib/msal-browser/test/naa/BridgeProxy.spec.ts

-7
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,6 @@ describe("BridgeProxy tests", () => {
4646
"window.nestedAppAuthBridge is undefined"
4747
);
4848
});
49-
50-
it("should throw an error if window.crypto is undefined", () => {
51-
windowSpy.mockImplementation(() => ({ nestedAppAuthBridge: {} }));
52-
expect(() => BridgeProxy.create()).rejects.toThrow(
53-
"window.crypto is undefined"
54-
);
55-
});
5649
});
5750

5851
describe("get token silent tests", () => {

0 commit comments

Comments
 (0)