Skip to content

Commit 585ed9e

Browse files
codexeonhectormmg
andauthored
Fix unhandled exception in NAA JS Runtime scenario (AzureAD#7475)
There were regressions to the NAA JS Runtime scenario by the following commits, adding new platform API dependencies in the NAA critical path. This change is tested to get JS Runtime back into a working state. - AzureAD@df26209 - AzureAD@09066cc --------- Co-authored-by: Hector Morales <hemoral@microsoft.com>
1 parent d03cccc commit 585ed9e

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
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": "Fix unhandled exception in NAA JS Runtime scenario (#7475)",
4+
"packageName": "@azure/msal-browser",
5+
"email": "dasau@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export class NestedAppAuthController implements IController {
102102

103103
// Initialize the crypto class.
104104
this.browserCrypto = operatingContext.isBrowserEnvironment()
105-
? new CryptoOps(this.logger, this.performanceClient)
105+
? new CryptoOps(this.logger, this.performanceClient, true)
106106
: DEFAULT_CRYPTO_IMPLEMENTATION;
107107

108108
// Initialize the browser storage class.

lib/msal-browser/src/crypto/BrowserCrypto.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ const keygenAlgorithmOptions: RsaHashedKeyGenParams = {
4747
/**
4848
* Check whether browser crypto is available.
4949
*/
50-
export function validateCryptoAvailable(): void {
50+
export function validateCryptoAvailable(
51+
skipValidateSubtleCrypto: boolean
52+
): void {
5153
if (!window) {
5254
throw createBrowserAuthError(
5355
BrowserAuthErrorCodes.nonBrowserEnvironment
@@ -56,7 +58,7 @@ export function validateCryptoAvailable(): void {
5658
if (!window.crypto) {
5759
throw createBrowserAuthError(BrowserAuthErrorCodes.cryptoNonExistent);
5860
}
59-
if (!window.crypto.subtle) {
61+
if (!skipValidateSubtleCrypto && !window.crypto.subtle) {
6062
throw createBrowserAuthError(
6163
BrowserAuthErrorCodes.cryptoNonExistent,
6264
SUBTLE_SUBERROR

lib/msal-browser/src/crypto/CryptoOps.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,16 @@ export class CryptoOps implements ICrypto {
5050
private static EXTRACTABLE: boolean = true;
5151
private cache: AsyncMemoryStorage<CachedKeyPair>;
5252

53-
constructor(logger: Logger, performanceClient?: IPerformanceClient) {
53+
constructor(
54+
logger: Logger,
55+
performanceClient?: IPerformanceClient,
56+
skipValidateSubtleCrypto?: boolean
57+
) {
5458
this.logger = logger;
5559
// Browser crypto needs to be validated first before any other classes can be set.
56-
BrowserCrypto.validateCryptoAvailable();
60+
BrowserCrypto.validateCryptoAvailable(
61+
skipValidateSubtleCrypto ?? false
62+
);
5763
this.cache = new AsyncMemoryStorage<CachedKeyPair>(this.logger);
5864
this.performanceClient = performanceClient;
5965
}

lib/msal-browser/src/utils/BrowserUtils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ export function isInPopup(): boolean {
6767
* Returns current window URL as redirect uri
6868
*/
6969
export function getCurrentUri(): string {
70-
return window.location.href.split("?")[0].split("#")[0];
70+
return typeof window !== "undefined" && window.location
71+
? window.location.href.split("?")[0].split("#")[0]
72+
: "";
7173
}
7274

7375
/**

0 commit comments

Comments
 (0)