This commit is contained in:
RochesterX
2025-11-12 10:13:24 -05:00
parent d5b0f97adb
commit 6e820464d5
9761 changed files with 706938 additions and 0 deletions

View File

@@ -0,0 +1,366 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
import { AuthError } from "@azure/msal-common/browser";
import * as BrowserAuthErrorCodes from "./BrowserAuthErrorCodes.js";
export { BrowserAuthErrorCodes }; // Allow importing as "BrowserAuthErrorCodes"
const ErrorLink = "For more visit: aka.ms/msaljs/browser-errors";
/**
* BrowserAuthErrorMessage class containing string constants used by error codes and messages.
*/
export const BrowserAuthErrorMessages = {
[BrowserAuthErrorCodes.pkceNotCreated]:
"The PKCE code challenge and verifier could not be generated.",
[BrowserAuthErrorCodes.earJwkEmpty]:
"No EAR encryption key provided. This is unexpected.",
[BrowserAuthErrorCodes.earJweEmpty]:
"Server response does not contain ear_jwe property. This is unexpected.",
[BrowserAuthErrorCodes.cryptoNonExistent]:
"The crypto object or function is not available.",
[BrowserAuthErrorCodes.emptyNavigateUri]:
"Navigation URI is empty. Please check stack trace for more info.",
[BrowserAuthErrorCodes.hashEmptyError]: `Hash value cannot be processed because it is empty. Please verify that your redirectUri is not clearing the hash. ${ErrorLink}`,
[BrowserAuthErrorCodes.noStateInHash]:
"Hash does not contain state. Please verify that the request originated from msal.",
[BrowserAuthErrorCodes.hashDoesNotContainKnownProperties]: `Hash does not contain known properites. Please verify that your redirectUri is not changing the hash. ${ErrorLink}`,
[BrowserAuthErrorCodes.unableToParseState]:
"Unable to parse state. Please verify that the request originated from msal.",
[BrowserAuthErrorCodes.stateInteractionTypeMismatch]:
"Hash contains state but the interaction type does not match the caller.",
[BrowserAuthErrorCodes.interactionInProgress]: `Interaction is currently in progress. Please ensure that this interaction has been completed before calling an interactive API. ${ErrorLink}`,
[BrowserAuthErrorCodes.popupWindowError]:
"Error opening popup window. This can happen if you are using IE or if popups are blocked in the browser.",
[BrowserAuthErrorCodes.emptyWindowError]:
"window.open returned null or undefined window object.",
[BrowserAuthErrorCodes.userCancelled]: "User cancelled the flow.",
[BrowserAuthErrorCodes.monitorPopupTimeout]: `Token acquisition in popup failed due to timeout. ${ErrorLink}`,
[BrowserAuthErrorCodes.monitorWindowTimeout]: `Token acquisition in iframe failed due to timeout. ${ErrorLink}`,
[BrowserAuthErrorCodes.redirectInIframe]:
"Redirects are not supported for iframed or brokered applications. Please ensure you are using MSAL.js in a top frame of the window if using the redirect APIs, or use the popup APIs.",
[BrowserAuthErrorCodes.blockIframeReload]: `Request was blocked inside an iframe because MSAL detected an authentication response. ${ErrorLink}`,
[BrowserAuthErrorCodes.blockNestedPopups]:
"Request was blocked inside a popup because MSAL detected it was running in a popup.",
[BrowserAuthErrorCodes.iframeClosedPrematurely]:
"The iframe being monitored was closed prematurely.",
[BrowserAuthErrorCodes.silentLogoutUnsupported]:
"Silent logout not supported. Please call logoutRedirect or logoutPopup instead.",
[BrowserAuthErrorCodes.noAccountError]:
"No account object provided to acquireTokenSilent and no active account has been set. Please call setActiveAccount or provide an account on the request.",
[BrowserAuthErrorCodes.silentPromptValueError]:
"The value given for the prompt value is not valid for silent requests - must be set to 'none' or 'no_session'.",
[BrowserAuthErrorCodes.noTokenRequestCacheError]:
"No token request found in cache.",
[BrowserAuthErrorCodes.unableToParseTokenRequestCacheError]:
"The cached token request could not be parsed.",
[BrowserAuthErrorCodes.authRequestNotSetError]:
"Auth Request not set. Please ensure initiateAuthRequest was called from the InteractionHandler",
[BrowserAuthErrorCodes.invalidCacheType]: "Invalid cache type",
[BrowserAuthErrorCodes.nonBrowserEnvironment]:
"Login and token requests are not supported in non-browser environments.",
[BrowserAuthErrorCodes.databaseNotOpen]: "Database is not open!",
[BrowserAuthErrorCodes.noNetworkConnectivity]:
"No network connectivity. Check your internet connection.",
[BrowserAuthErrorCodes.postRequestFailed]:
"Network request failed: If the browser threw a CORS error, check that the redirectUri is registered in the Azure App Portal as type 'SPA'",
[BrowserAuthErrorCodes.getRequestFailed]:
"Network request failed. Please check the network trace to determine root cause.",
[BrowserAuthErrorCodes.failedToParseResponse]:
"Failed to parse network response. Check network trace.",
[BrowserAuthErrorCodes.unableToLoadToken]: "Error loading token to cache.",
[BrowserAuthErrorCodes.cryptoKeyNotFound]:
"Cryptographic Key or Keypair not found in browser storage.",
[BrowserAuthErrorCodes.authCodeRequired]:
"An authorization code must be provided (as the `code` property on the request) to this flow.",
[BrowserAuthErrorCodes.authCodeOrNativeAccountIdRequired]:
"An authorization code or nativeAccountId must be provided to this flow.",
[BrowserAuthErrorCodes.spaCodeAndNativeAccountIdPresent]:
"Request cannot contain both spa code and native account id.",
[BrowserAuthErrorCodes.databaseUnavailable]:
"IndexedDB, which is required for persistent cryptographic key storage, is unavailable. This may be caused by browser privacy features which block persistent storage in third-party contexts.",
[BrowserAuthErrorCodes.unableToAcquireTokenFromNativePlatform]: `Unable to acquire token from native platform. ${ErrorLink}`,
[BrowserAuthErrorCodes.nativeHandshakeTimeout]:
"Timed out while attempting to establish connection to browser extension",
[BrowserAuthErrorCodes.nativeExtensionNotInstalled]:
"Native extension is not installed. If you think this is a mistake call the initialize function.",
[BrowserAuthErrorCodes.nativeConnectionNotEstablished]: `Connection to native platform has not been established. Please install a compatible browser extension and run initialize(). ${ErrorLink}`,
[BrowserAuthErrorCodes.uninitializedPublicClientApplication]: `You must call and await the initialize function before attempting to call any other MSAL API. ${ErrorLink}`,
[BrowserAuthErrorCodes.nativePromptNotSupported]:
"The provided prompt is not supported by the native platform. This request should be routed to the web based flow.",
[BrowserAuthErrorCodes.invalidBase64String]:
"Invalid base64 encoded string.",
[BrowserAuthErrorCodes.invalidPopTokenRequest]:
"Invalid PoP token request. The request should not have both a popKid value and signPopToken set to true.",
[BrowserAuthErrorCodes.failedToBuildHeaders]:
"Failed to build request headers object.",
[BrowserAuthErrorCodes.failedToParseHeaders]:
"Failed to parse response headers",
[BrowserAuthErrorCodes.failedToDecryptEarResponse]:
"Failed to decrypt ear response",
[BrowserAuthErrorCodes.timedOut]: "The request timed out.",
};
/**
* BrowserAuthErrorMessage class containing string constants used by error codes and messages.
* @deprecated Use exported BrowserAuthErrorCodes instead.
* In your app you can do :
* ```
* import { BrowserAuthErrorCodes } from "@azure/msal-browser";
* ```
*/
export const BrowserAuthErrorMessage = {
pkceNotGenerated: {
code: BrowserAuthErrorCodes.pkceNotCreated,
desc: BrowserAuthErrorMessages[BrowserAuthErrorCodes.pkceNotCreated],
},
cryptoDoesNotExist: {
code: BrowserAuthErrorCodes.cryptoNonExistent,
desc: BrowserAuthErrorMessages[BrowserAuthErrorCodes.cryptoNonExistent],
},
emptyNavigateUriError: {
code: BrowserAuthErrorCodes.emptyNavigateUri,
desc: BrowserAuthErrorMessages[BrowserAuthErrorCodes.emptyNavigateUri],
},
hashEmptyError: {
code: BrowserAuthErrorCodes.hashEmptyError,
desc: BrowserAuthErrorMessages[BrowserAuthErrorCodes.hashEmptyError],
},
hashDoesNotContainStateError: {
code: BrowserAuthErrorCodes.noStateInHash,
desc: BrowserAuthErrorMessages[BrowserAuthErrorCodes.noStateInHash],
},
hashDoesNotContainKnownPropertiesError: {
code: BrowserAuthErrorCodes.hashDoesNotContainKnownProperties,
desc: BrowserAuthErrorMessages[
BrowserAuthErrorCodes.hashDoesNotContainKnownProperties
],
},
unableToParseStateError: {
code: BrowserAuthErrorCodes.unableToParseState,
desc: BrowserAuthErrorMessages[
BrowserAuthErrorCodes.unableToParseState
],
},
stateInteractionTypeMismatchError: {
code: BrowserAuthErrorCodes.stateInteractionTypeMismatch,
desc: BrowserAuthErrorMessages[
BrowserAuthErrorCodes.stateInteractionTypeMismatch
],
},
interactionInProgress: {
code: BrowserAuthErrorCodes.interactionInProgress,
desc: BrowserAuthErrorMessages[
BrowserAuthErrorCodes.interactionInProgress
],
},
popupWindowError: {
code: BrowserAuthErrorCodes.popupWindowError,
desc: BrowserAuthErrorMessages[BrowserAuthErrorCodes.popupWindowError],
},
emptyWindowError: {
code: BrowserAuthErrorCodes.emptyWindowError,
desc: BrowserAuthErrorMessages[BrowserAuthErrorCodes.emptyWindowError],
},
userCancelledError: {
code: BrowserAuthErrorCodes.userCancelled,
desc: BrowserAuthErrorMessages[BrowserAuthErrorCodes.userCancelled],
},
monitorPopupTimeoutError: {
code: BrowserAuthErrorCodes.monitorPopupTimeout,
desc: BrowserAuthErrorMessages[
BrowserAuthErrorCodes.monitorPopupTimeout
],
},
monitorIframeTimeoutError: {
code: BrowserAuthErrorCodes.monitorWindowTimeout,
desc: BrowserAuthErrorMessages[
BrowserAuthErrorCodes.monitorWindowTimeout
],
},
redirectInIframeError: {
code: BrowserAuthErrorCodes.redirectInIframe,
desc: BrowserAuthErrorMessages[BrowserAuthErrorCodes.redirectInIframe],
},
blockTokenRequestsInHiddenIframeError: {
code: BrowserAuthErrorCodes.blockIframeReload,
desc: BrowserAuthErrorMessages[BrowserAuthErrorCodes.blockIframeReload],
},
blockAcquireTokenInPopupsError: {
code: BrowserAuthErrorCodes.blockNestedPopups,
desc: BrowserAuthErrorMessages[BrowserAuthErrorCodes.blockNestedPopups],
},
iframeClosedPrematurelyError: {
code: BrowserAuthErrorCodes.iframeClosedPrematurely,
desc: BrowserAuthErrorMessages[
BrowserAuthErrorCodes.iframeClosedPrematurely
],
},
silentLogoutUnsupportedError: {
code: BrowserAuthErrorCodes.silentLogoutUnsupported,
desc: BrowserAuthErrorMessages[
BrowserAuthErrorCodes.silentLogoutUnsupported
],
},
noAccountError: {
code: BrowserAuthErrorCodes.noAccountError,
desc: BrowserAuthErrorMessages[BrowserAuthErrorCodes.noAccountError],
},
silentPromptValueError: {
code: BrowserAuthErrorCodes.silentPromptValueError,
desc: BrowserAuthErrorMessages[
BrowserAuthErrorCodes.silentPromptValueError
],
},
noTokenRequestCacheError: {
code: BrowserAuthErrorCodes.noTokenRequestCacheError,
desc: BrowserAuthErrorMessages[
BrowserAuthErrorCodes.noTokenRequestCacheError
],
},
unableToParseTokenRequestCacheError: {
code: BrowserAuthErrorCodes.unableToParseTokenRequestCacheError,
desc: BrowserAuthErrorMessages[
BrowserAuthErrorCodes.unableToParseTokenRequestCacheError
],
},
authRequestNotSet: {
code: BrowserAuthErrorCodes.authRequestNotSetError,
desc: BrowserAuthErrorMessages[
BrowserAuthErrorCodes.authRequestNotSetError
],
},
invalidCacheType: {
code: BrowserAuthErrorCodes.invalidCacheType,
desc: BrowserAuthErrorMessages[BrowserAuthErrorCodes.invalidCacheType],
},
notInBrowserEnvironment: {
code: BrowserAuthErrorCodes.nonBrowserEnvironment,
desc: BrowserAuthErrorMessages[
BrowserAuthErrorCodes.nonBrowserEnvironment
],
},
databaseNotOpen: {
code: BrowserAuthErrorCodes.databaseNotOpen,
desc: BrowserAuthErrorMessages[BrowserAuthErrorCodes.databaseNotOpen],
},
noNetworkConnectivity: {
code: BrowserAuthErrorCodes.noNetworkConnectivity,
desc: BrowserAuthErrorMessages[
BrowserAuthErrorCodes.noNetworkConnectivity
],
},
postRequestFailed: {
code: BrowserAuthErrorCodes.postRequestFailed,
desc: BrowserAuthErrorMessages[BrowserAuthErrorCodes.postRequestFailed],
},
getRequestFailed: {
code: BrowserAuthErrorCodes.getRequestFailed,
desc: BrowserAuthErrorMessages[BrowserAuthErrorCodes.getRequestFailed],
},
failedToParseNetworkResponse: {
code: BrowserAuthErrorCodes.failedToParseResponse,
desc: BrowserAuthErrorMessages[
BrowserAuthErrorCodes.failedToParseResponse
],
},
unableToLoadTokenError: {
code: BrowserAuthErrorCodes.unableToLoadToken,
desc: BrowserAuthErrorMessages[BrowserAuthErrorCodes.unableToLoadToken],
},
signingKeyNotFoundInStorage: {
code: BrowserAuthErrorCodes.cryptoKeyNotFound,
desc: BrowserAuthErrorMessages[BrowserAuthErrorCodes.cryptoKeyNotFound],
},
authCodeRequired: {
code: BrowserAuthErrorCodes.authCodeRequired,
desc: BrowserAuthErrorMessages[BrowserAuthErrorCodes.authCodeRequired],
},
authCodeOrNativeAccountRequired: {
code: BrowserAuthErrorCodes.authCodeOrNativeAccountIdRequired,
desc: BrowserAuthErrorMessages[
BrowserAuthErrorCodes.authCodeOrNativeAccountIdRequired
],
},
spaCodeAndNativeAccountPresent: {
code: BrowserAuthErrorCodes.spaCodeAndNativeAccountIdPresent,
desc: BrowserAuthErrorMessages[
BrowserAuthErrorCodes.spaCodeAndNativeAccountIdPresent
],
},
databaseUnavailable: {
code: BrowserAuthErrorCodes.databaseUnavailable,
desc: BrowserAuthErrorMessages[
BrowserAuthErrorCodes.databaseUnavailable
],
},
unableToAcquireTokenFromNativePlatform: {
code: BrowserAuthErrorCodes.unableToAcquireTokenFromNativePlatform,
desc: BrowserAuthErrorMessages[
BrowserAuthErrorCodes.unableToAcquireTokenFromNativePlatform
],
},
nativeHandshakeTimeout: {
code: BrowserAuthErrorCodes.nativeHandshakeTimeout,
desc: BrowserAuthErrorMessages[
BrowserAuthErrorCodes.nativeHandshakeTimeout
],
},
nativeExtensionNotInstalled: {
code: BrowserAuthErrorCodes.nativeExtensionNotInstalled,
desc: BrowserAuthErrorMessages[
BrowserAuthErrorCodes.nativeExtensionNotInstalled
],
},
nativeConnectionNotEstablished: {
code: BrowserAuthErrorCodes.nativeConnectionNotEstablished,
desc: BrowserAuthErrorMessages[
BrowserAuthErrorCodes.nativeConnectionNotEstablished
],
},
uninitializedPublicClientApplication: {
code: BrowserAuthErrorCodes.uninitializedPublicClientApplication,
desc: BrowserAuthErrorMessages[
BrowserAuthErrorCodes.uninitializedPublicClientApplication
],
},
nativePromptNotSupported: {
code: BrowserAuthErrorCodes.nativePromptNotSupported,
desc: BrowserAuthErrorMessages[
BrowserAuthErrorCodes.nativePromptNotSupported
],
},
invalidBase64StringError: {
code: BrowserAuthErrorCodes.invalidBase64String,
desc: BrowserAuthErrorMessages[
BrowserAuthErrorCodes.invalidBase64String
],
},
invalidPopTokenRequest: {
code: BrowserAuthErrorCodes.invalidPopTokenRequest,
desc: BrowserAuthErrorMessages[
BrowserAuthErrorCodes.invalidPopTokenRequest
],
},
};
/**
* Browser library error class thrown by the MSAL.js library for SPAs
*/
export class BrowserAuthError extends AuthError {
constructor(errorCode: string, subError?: string) {
super(errorCode, BrowserAuthErrorMessages[errorCode], subError);
Object.setPrototypeOf(this, BrowserAuthError.prototype);
this.name = "BrowserAuthError";
}
}
export function createBrowserAuthError(
errorCode: string,
subError?: string
): BrowserAuthError {
return new BrowserAuthError(errorCode, subError);
}

View File

@@ -0,0 +1,63 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
export const pkceNotCreated = "pkce_not_created";
export const earJwkEmpty = "ear_jwk_empty";
export const earJweEmpty = "ear_jwe_empty";
export const cryptoNonExistent = "crypto_nonexistent";
export const emptyNavigateUri = "empty_navigate_uri";
export const hashEmptyError = "hash_empty_error";
export const noStateInHash = "no_state_in_hash";
export const hashDoesNotContainKnownProperties =
"hash_does_not_contain_known_properties";
export const unableToParseState = "unable_to_parse_state";
export const stateInteractionTypeMismatch = "state_interaction_type_mismatch";
export const interactionInProgress = "interaction_in_progress";
export const popupWindowError = "popup_window_error";
export const emptyWindowError = "empty_window_error";
export const userCancelled = "user_cancelled";
export const monitorPopupTimeout = "monitor_popup_timeout";
export const monitorWindowTimeout = "monitor_window_timeout";
export const redirectInIframe = "redirect_in_iframe";
export const blockIframeReload = "block_iframe_reload";
export const blockNestedPopups = "block_nested_popups";
export const iframeClosedPrematurely = "iframe_closed_prematurely";
export const silentLogoutUnsupported = "silent_logout_unsupported";
export const noAccountError = "no_account_error";
export const silentPromptValueError = "silent_prompt_value_error";
export const noTokenRequestCacheError = "no_token_request_cache_error";
export const unableToParseTokenRequestCacheError =
"unable_to_parse_token_request_cache_error";
export const authRequestNotSetError = "auth_request_not_set_error";
export const invalidCacheType = "invalid_cache_type";
export const nonBrowserEnvironment = "non_browser_environment";
export const databaseNotOpen = "database_not_open";
export const noNetworkConnectivity = "no_network_connectivity";
export const postRequestFailed = "post_request_failed";
export const getRequestFailed = "get_request_failed";
export const failedToParseResponse = "failed_to_parse_response";
export const unableToLoadToken = "unable_to_load_token";
export const cryptoKeyNotFound = "crypto_key_not_found";
export const authCodeRequired = "auth_code_required";
export const authCodeOrNativeAccountIdRequired =
"auth_code_or_nativeAccountId_required";
export const spaCodeAndNativeAccountIdPresent =
"spa_code_and_nativeAccountId_present";
export const databaseUnavailable = "database_unavailable";
export const unableToAcquireTokenFromNativePlatform =
"unable_to_acquire_token_from_native_platform";
export const nativeHandshakeTimeout = "native_handshake_timeout";
export const nativeExtensionNotInstalled = "native_extension_not_installed";
export const nativeConnectionNotEstablished =
"native_connection_not_established";
export const uninitializedPublicClientApplication =
"uninitialized_public_client_application";
export const nativePromptNotSupported = "native_prompt_not_supported";
export const invalidBase64String = "invalid_base64_string";
export const invalidPopTokenRequest = "invalid_pop_token_request";
export const failedToBuildHeaders = "failed_to_build_headers";
export const failedToParseHeaders = "failed_to_parse_headers";
export const failedToDecryptEarResponse = "failed_to_decrypt_ear_response";
export const timedOut = "timed_out";

View File

@@ -0,0 +1,64 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
import { AuthError } from "@azure/msal-common/browser";
import * as BrowserConfigurationAuthErrorCodes from "./BrowserConfigurationAuthErrorCodes.js";
export { BrowserConfigurationAuthErrorCodes };
export const BrowserConfigurationAuthErrorMessages = {
[BrowserConfigurationAuthErrorCodes.storageNotSupported]:
"Given storage configuration option was not supported.",
[BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled]:
"Stub instance of Public Client Application was called. If using msal-react, please ensure context is not used without a provider. For more visit: aka.ms/msaljs/browser-errors",
[BrowserConfigurationAuthErrorCodes.inMemRedirectUnavailable]:
"Redirect cannot be supported. In-memory storage was selected and storeAuthStateInCookie=false, which would cause the library to be unable to handle the incoming hash. If you would like to use the redirect API, please use session/localStorage or set storeAuthStateInCookie=true.",
};
/**
* BrowserAuthErrorMessage class containing string constants used by error codes and messages.
* @deprecated Use BrowserAuthErrorCodes instead
*/
export const BrowserConfigurationAuthErrorMessage = {
storageNotSupportedError: {
code: BrowserConfigurationAuthErrorCodes.storageNotSupported,
desc: BrowserConfigurationAuthErrorMessages[
BrowserConfigurationAuthErrorCodes.storageNotSupported
],
},
stubPcaInstanceCalled: {
code: BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled,
desc: BrowserConfigurationAuthErrorMessages[
BrowserConfigurationAuthErrorCodes
.stubbedPublicClientApplicationCalled
],
},
inMemRedirectUnavailable: {
code: BrowserConfigurationAuthErrorCodes.inMemRedirectUnavailable,
desc: BrowserConfigurationAuthErrorMessages[
BrowserConfigurationAuthErrorCodes.inMemRedirectUnavailable
],
},
};
/**
* Browser library error class thrown by the MSAL.js library for SPAs
*/
export class BrowserConfigurationAuthError extends AuthError {
constructor(errorCode: string, errorMessage?: string) {
super(errorCode, errorMessage);
this.name = "BrowserConfigurationAuthError";
Object.setPrototypeOf(this, BrowserConfigurationAuthError.prototype);
}
}
export function createBrowserConfigurationAuthError(
errorCode: string
): BrowserConfigurationAuthError {
return new BrowserConfigurationAuthError(
errorCode,
BrowserConfigurationAuthErrorMessages[errorCode]
);
}

View File

@@ -0,0 +1,9 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
export const storageNotSupported = "storage_not_supported";
export const stubbedPublicClientApplicationCalled =
"stubbed_public_client_application_called";
export const inMemRedirectUnavailable = "in_mem_redirect_unavailable";

View File

@@ -0,0 +1,117 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
import {
AuthError,
InteractionRequiredAuthError,
InteractionRequiredAuthErrorCodes,
createInteractionRequiredAuthError,
} from "@azure/msal-common/browser";
import {
createBrowserAuthError,
BrowserAuthErrorCodes,
} from "./BrowserAuthError.js";
import * as NativeAuthErrorCodes from "./NativeAuthErrorCodes.js";
import * as NativeStatusCodes from "../broker/nativeBroker/NativeStatusCodes.js";
export { NativeAuthErrorCodes };
export type OSError = {
error?: number;
protocol_error?: string;
properties?: object;
status?: string;
retryable?: boolean;
};
const INVALID_METHOD_ERROR = -2147186943;
export const NativeAuthErrorMessages = {
[NativeAuthErrorCodes.userSwitch]:
"User attempted to switch accounts in the native broker, which is not allowed. All new accounts must sign-in through the standard web flow first, please try again.",
};
export class NativeAuthError extends AuthError {
ext: OSError | undefined;
constructor(errorCode: string, description?: string, ext?: OSError) {
super(errorCode, description);
Object.setPrototypeOf(this, NativeAuthError.prototype);
this.name = "NativeAuthError";
this.ext = ext;
}
}
/**
* These errors should result in a fallback to the 'standard' browser based auth flow.
*/
export function isFatalNativeAuthError(error: NativeAuthError): boolean {
if (
error.ext &&
error.ext.status &&
error.ext.status === NativeStatusCodes.DISABLED
) {
return true;
}
if (
error.ext &&
error.ext.error &&
error.ext.error === INVALID_METHOD_ERROR
) {
return true;
}
switch (error.errorCode) {
case NativeAuthErrorCodes.contentError:
case NativeAuthErrorCodes.pageException:
return true;
default:
return false;
}
}
/**
* Create the appropriate error object based on the WAM status code.
* @param code
* @param description
* @param ext
* @returns
*/
export function createNativeAuthError(
code: string,
description?: string,
ext?: OSError
): AuthError {
if (ext && ext.status) {
switch (ext.status) {
case NativeStatusCodes.ACCOUNT_UNAVAILABLE:
return createInteractionRequiredAuthError(
InteractionRequiredAuthErrorCodes.nativeAccountUnavailable
);
case NativeStatusCodes.USER_INTERACTION_REQUIRED:
return new InteractionRequiredAuthError(code, description);
case NativeStatusCodes.USER_CANCEL:
return createBrowserAuthError(
BrowserAuthErrorCodes.userCancelled
);
case NativeStatusCodes.NO_NETWORK:
return createBrowserAuthError(
BrowserAuthErrorCodes.noNetworkConnectivity
);
case NativeStatusCodes.UX_NOT_ALLOWED:
return createInteractionRequiredAuthError(
InteractionRequiredAuthErrorCodes.uxNotAllowed
);
}
}
return new NativeAuthError(
code,
NativeAuthErrorMessages[code] || description,
ext
);
}

View File

@@ -0,0 +1,8 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
export const contentError = "ContentError";
export const pageException = "PageException";
export const userSwitch = "user_switch";

View File

@@ -0,0 +1,32 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
import { AuthError } from "@azure/msal-common/browser";
/**
* NestedAppAuthErrorMessage class containing string constants used by error codes and messages.
*/
export const NestedAppAuthErrorMessage = {
unsupportedMethod: {
code: "unsupported_method",
desc: "This method is not supported in nested app environment.",
},
};
export class NestedAppAuthError extends AuthError {
constructor(errorCode: string, errorMessage?: string) {
super(errorCode, errorMessage);
Object.setPrototypeOf(this, NestedAppAuthError.prototype);
this.name = "NestedAppAuthError";
}
public static createUnsupportedError(): NestedAppAuthError {
return new NestedAppAuthError(
NestedAppAuthErrorMessage.unsupportedMethod.code,
NestedAppAuthErrorMessage.unsupportedMethod.desc
);
}
}