{"version":3,"file":"msal-react.cjs.production.min.js","sources":["../src/MsalContext.ts","../src/utils/utilities.ts","../src/MsalProvider.tsx","../src/hooks/useMsal.ts","../src/hooks/useIsAuthenticated.ts","../src/hooks/useAccount.ts","../src/error/ReactAuthError.ts","../src/hooks/useMsalAuthentication.ts","../src/components/AuthenticatedTemplate.tsx","../src/components/MsalAuthenticationTemplate.tsx","../src/packageMetadata.ts","../src/components/UnauthenticatedTemplate.tsx","../src/components/withMsal.tsx"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport * as React from \"react\";\nimport { IPublicClientApplication, stubbedPublicClientApplication, Logger, InteractionStatus, AccountInfo } from \"@azure/msal-browser\";\n\nexport interface IMsalContext {\n instance: IPublicClientApplication;\n inProgress: InteractionStatus;\n accounts: AccountInfo[];\n logger: Logger;\n}\n\n/*\n * Stubbed context implementation\n * Only used when there is no provider, which is an unsupported scenario\n */\nconst defaultMsalContext: IMsalContext = {\n instance: stubbedPublicClientApplication,\n inProgress: InteractionStatus.None,\n accounts: [],\n logger: new Logger({})\n};\n\nexport const MsalContext = React.createContext(\n defaultMsalContext\n);\nexport const MsalConsumer = MsalContext.Consumer;\n","/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { AccountIdentifiers } from \"../types/AccountIdentifiers\";\nimport { AccountInfo } from \"@azure/msal-browser\";\n\ntype FaaCFunction = (args: T) => React.ReactNode;\n\nexport function getChildrenOrFunction(\n children: React.ReactNode | FaaCFunction,\n args: T\n): React.ReactNode {\n if (typeof children === \"function\") {\n return children(args);\n }\n return children;\n}\n\n/*\n * Utility types\n * Reference: https://github.com/piotrwitek/utility-types\n */\ntype SetDifference = A extends B ? never : A;\ntype SetComplement = SetDifference;\nexport type Subtract = Pick>;\n\n/**\n * Helper function to determine whether 2 arrays are equal\n * Used to avoid unnecessary state updates\n * @param arrayA \n * @param arrayB \n */\nexport function accountArraysAreEqual(arrayA: Array, arrayB: Array): boolean {\n if (arrayA.length !== arrayB.length) {\n return false;\n }\n\n const comparisonArray = [...arrayB];\n\n return arrayA.every((elementA) => {\n const elementB = comparisonArray.shift();\n if (!elementA || !elementB) {\n return false;\n }\n\n return (elementA.homeAccountId === elementB.homeAccountId) && \n (elementA.localAccountId === elementB.localAccountId) &&\n (elementA.username === elementB.username);\n });\n}\n\nexport function getAccountByIdentifiers(allAccounts: AccountInfo[], accountIdentifiers: AccountIdentifiers): AccountInfo | null {\n if (allAccounts.length > 0 && (accountIdentifiers.homeAccountId || accountIdentifiers.localAccountId || accountIdentifiers.username)) {\n const matchedAccounts = allAccounts.filter(accountObj => {\n if (accountIdentifiers.username && accountIdentifiers.username.toLowerCase() !== accountObj.username.toLowerCase()) {\n return false;\n }\n if (accountIdentifiers.homeAccountId && accountIdentifiers.homeAccountId.toLowerCase() !== accountObj.homeAccountId.toLowerCase()) {\n return false;\n }\n if (accountIdentifiers.localAccountId && accountIdentifiers.localAccountId.toLowerCase() !== accountObj.localAccountId.toLowerCase()) {\n return false;\n }\n\n return true;\n });\n\n return matchedAccounts[0] || null;\n } else {\n return null;\n }\n}\n","/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport React, { useEffect, useReducer, PropsWithChildren, useMemo} from \"react\";\nimport {\n IPublicClientApplication,\n EventMessage,\n EventMessageUtils,\n InteractionStatus,\n Logger,\n WrapperSKU,\n AccountInfo\n} from \"@azure/msal-browser\";\nimport { MsalContext, IMsalContext } from \"./MsalContext\";\nimport { accountArraysAreEqual } from \"./utils/utilities\";\nimport { name as SKU, version } from \"./packageMetadata\";\n\nexport type MsalProviderProps = PropsWithChildren<{\n instance: IPublicClientApplication;\n}>;\n\ntype MsalState = {\n inProgress: InteractionStatus;\n accounts: AccountInfo[];\n};\n\nenum MsalProviderActionType {\n UNBLOCK_INPROGRESS = \"UNBLOCK_INPROGRESS\",\n EVENT = \"EVENT\"\n}\n\ntype MsalProviderReducerAction = {\n type: MsalProviderActionType,\n payload: {\n logger: Logger;\n instance: IPublicClientApplication;\n message?: EventMessage;\n };\n};\n\n/**\n * Returns the next inProgress and accounts state based on event message\n * @param previousState \n * @param action \n */\nconst reducer = (previousState: MsalState, action: MsalProviderReducerAction): MsalState => {\n const { type, payload } = action;\n let newInProgress = previousState.inProgress;\n\n switch (type) {\n case MsalProviderActionType.UNBLOCK_INPROGRESS:\n if (previousState.inProgress === InteractionStatus.Startup){\n newInProgress = InteractionStatus.None;\n payload.logger.info(\"MsalProvider - handleRedirectPromise resolved, setting inProgress to 'none'\");\n }\n break;\n case MsalProviderActionType.EVENT:\n const message = payload.message as EventMessage;\n const status = EventMessageUtils.getInteractionStatusFromEvent(message, previousState.inProgress);\n if (status) {\n payload.logger.info(`MsalProvider - ${message.eventType} results in setting inProgress from ${previousState.inProgress} to ${status}`);\n newInProgress = status;\n }\n break;\n default:\n throw new Error(`Unknown action type: ${type}`);\n }\n \n const currentAccounts = payload.instance.getAllAccounts();\n if (newInProgress !== previousState.inProgress && \n !accountArraysAreEqual(currentAccounts, previousState.accounts)) {\n // Both inProgress and accounts changed\n return {\n ...previousState,\n inProgress: newInProgress,\n accounts: currentAccounts\n };\n } else if (newInProgress !== previousState.inProgress) {\n // Only only inProgress changed\n return {\n ...previousState,\n inProgress: newInProgress\n };\n } else if (!accountArraysAreEqual(currentAccounts, previousState.accounts)) {\n // Only accounts changed\n return {\n ...previousState,\n accounts: currentAccounts\n };\n } else {\n // Nothing changed\n return previousState;\n }\n};\n\n/**\n * MSAL context provider component. This must be rendered above any other components that use MSAL.\n */\nexport function MsalProvider({instance, children}: MsalProviderProps): React.ReactElement {\n useEffect(() => {\n instance.initializeWrapperLibrary(WrapperSKU.React, version);\n }, [instance]);\n // Create a logger instance for msal-react with the same options as PublicClientApplication\n const logger = useMemo(() => {\n return instance.getLogger().clone(SKU, version);\n }, [instance]);\n\n const [state, updateState] = useReducer(reducer, undefined, () => {\n // Lazy initialization of the initial state\n return {\n inProgress: InteractionStatus.Startup,\n accounts: instance.getAllAccounts()\n };\n });\n \n useEffect(() => {\n const callbackId = instance.addEventCallback((message: EventMessage) => {\n updateState({\n payload: {\n instance,\n logger,\n message\n }, \n type: MsalProviderActionType.EVENT\n });\n });\n logger.verbose(`MsalProvider - Registered event callback with id: ${callbackId}`);\n\n instance.initialize().then(() => {\n instance.handleRedirectPromise().catch(() => {\n // Errors should be handled by listening to the LOGIN_FAILURE event\n return;\n }).finally(() => {\n /*\n * If handleRedirectPromise returns a cached promise the necessary events may not be fired\n * This is a fallback to prevent inProgress from getting stuck in 'startup'\n */\n updateState({\n payload: {\n instance,\n logger\n },\n type: MsalProviderActionType.UNBLOCK_INPROGRESS \n });\n });\n });\n\n return () => {\n // Remove callback when component unmounts or accounts change\n if (callbackId) {\n logger.verbose(`MsalProvider - Removing event callback ${callbackId}`);\n instance.removeEventCallback(callbackId);\n }\n };\n }, [instance, logger]);\n\n const contextValue: IMsalContext = {\n instance,\n inProgress: state.inProgress,\n accounts: state.accounts,\n logger\n };\n\n return (\n \n {children}\n \n );\n}\n\n","/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { useContext } from \"react\";\nimport { IMsalContext, MsalContext } from \"../MsalContext\";\n\n/**\n * Returns Msal Context values\n */\nexport const useMsal = (): IMsalContext => useContext(MsalContext);\n","/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { useState, useEffect } from \"react\";\nimport { useMsal } from \"./useMsal\";\nimport { AccountIdentifiers } from \"../types/AccountIdentifiers\";\nimport { AccountInfo, InteractionStatus } from \"@azure/msal-browser\";\nimport { getAccountByIdentifiers } from \"../utils/utilities\";\n\nfunction isAuthenticated(allAccounts: AccountInfo[], matchAccount?: AccountIdentifiers): boolean {\n if(matchAccount && (matchAccount.username || matchAccount.homeAccountId || matchAccount.localAccountId)) {\n return !!getAccountByIdentifiers(allAccounts, matchAccount);\n } \n\n return allAccounts.length > 0;\n}\n\n/**\n * Returns whether or not a user is currently signed-in. Optionally provide 1 or more accountIdentifiers to determine if a specific user is signed-in\n * @param matchAccount \n */\nexport function useIsAuthenticated(matchAccount?: AccountIdentifiers): boolean {\n const { accounts: allAccounts, inProgress } = useMsal();\n\n const [hasAuthenticated, setHasAuthenticated] = useState(() => {\n if (inProgress === InteractionStatus.Startup) {\n return false;\n }\n return isAuthenticated(allAccounts, matchAccount);\n });\n\n useEffect(() => {\n setHasAuthenticated(isAuthenticated(allAccounts, matchAccount));\n }, [allAccounts, matchAccount]);\n\n return hasAuthenticated;\n}\n","/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { useState, useEffect } from \"react\";\nimport { AccountInfo, IPublicClientApplication, AccountEntity } from \"@azure/msal-browser\";\nimport { useMsal } from \"./useMsal\";\nimport { AccountIdentifiers } from \"../types/AccountIdentifiers\";\nimport { getAccountByIdentifiers } from \"../utils/utilities\";\n\nfunction getAccount(instance: IPublicClientApplication, accountIdentifiers?: AccountIdentifiers): AccountInfo | null {\n if (!accountIdentifiers || (!accountIdentifiers.homeAccountId && !accountIdentifiers.localAccountId && !accountIdentifiers.username)) {\n // If no account identifiers are provided, return active account\n return instance.getActiveAccount();\n }\n\n return getAccountByIdentifiers(instance.getAllAccounts(), accountIdentifiers);\n}\n\n/**\n * Given 1 or more accountIdentifiers, returns the Account object if the user is signed-in\n * @param accountIdentifiers \n */\nexport function useAccount(accountIdentifiers?: AccountIdentifiers): AccountInfo | null {\n const { instance, inProgress, logger } = useMsal();\n\n const [account, setAccount] = useState(() => getAccount(instance, accountIdentifiers));\n\n useEffect(() => {\n setAccount((currentAccount: AccountInfo | null) => {\n const nextAccount = getAccount(instance, accountIdentifiers);\n if (!AccountEntity.accountInfoIsEqual(currentAccount, nextAccount, true)) {\n logger.info(\"useAccount - Updating account\");\n return nextAccount;\n }\n\n return currentAccount;\n });\n }, [inProgress, accountIdentifiers, instance, logger]);\n\n return account;\n}\n","/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { AuthError } from \"@azure/msal-browser\";\n\nexport const ReactAuthErrorMessage = {\n invalidInteractionType: {\n code: \"invalid_interaction_type\",\n desc: \"The provided interaction type is invalid.\"\n },\n unableToFallbackToInteraction: {\n code: \"unable_to_fallback_to_interaction\",\n desc: \"Interaction is required but another interaction is already in progress. Please try again when the current interaction is complete.\"\n }\n};\n\nexport class ReactAuthError extends AuthError {\n constructor(errorCode: string, errorMessage?: string) {\n super(errorCode, errorMessage);\n\n Object.setPrototypeOf(this, ReactAuthError.prototype);\n this.name = \"ReactAuthError\";\n }\n\n static createInvalidInteractionTypeError(): ReactAuthError {\n return new ReactAuthError(ReactAuthErrorMessage.invalidInteractionType.code, ReactAuthErrorMessage.invalidInteractionType.desc);\n }\n\n static createUnableToFallbackToInteractionError(): ReactAuthError {\n return new ReactAuthError(ReactAuthErrorMessage.unableToFallbackToInteraction.code, ReactAuthErrorMessage.unableToFallbackToInteraction.desc);\n }\n}\n","/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { useCallback, useEffect, useState, useRef } from \"react\";\nimport { PopupRequest, RedirectRequest, SsoSilentRequest, InteractionType, AuthenticationResult, AuthError, EventMessage, EventType, InteractionStatus, SilentRequest, InteractionRequiredAuthError, OIDC_DEFAULT_SCOPES } from \"@azure/msal-browser\";\nimport { useIsAuthenticated } from \"./useIsAuthenticated\";\nimport { AccountIdentifiers } from \"../types/AccountIdentifiers\";\nimport { useMsal } from \"./useMsal\";\nimport { useAccount } from \"./useAccount\";\nimport { ReactAuthError } from \"../error/ReactAuthError\";\n\nexport type MsalAuthenticationResult = {\n login: (callbackInteractionType?: InteractionType | undefined, callbackRequest?: PopupRequest | RedirectRequest | SilentRequest) => Promise; \n acquireToken: (callbackInteractionType?: InteractionType | undefined, callbackRequest?: SilentRequest | undefined) => Promise;\n result: AuthenticationResult|null;\n error: AuthError|null;\n};\n\n/**\n * If a user is not currently signed in this hook invokes a login. Failed logins can be retried using the login callback returned.\n * If a user is currently signed in this hook attempts to acquire a token. Subsequent token requests can use the acquireToken callback returned.\n * Optionally provide a request object to be used in the login/acquireToken call.\n * Optionally provide a specific user that should be logged in.\n * @param interactionType \n * @param authenticationRequest \n * @param accountIdentifiers \n */\nexport function useMsalAuthentication(\n interactionType: InteractionType, \n authenticationRequest?: PopupRequest|RedirectRequest|SsoSilentRequest, \n accountIdentifiers?: AccountIdentifiers\n): MsalAuthenticationResult {\n const { instance, inProgress, logger } = useMsal();\n const isAuthenticated = useIsAuthenticated(accountIdentifiers);\n const account = useAccount(accountIdentifiers);\n const [[result, error], setResponse] = useState<[AuthenticationResult|null, AuthError|null]>([null, null]);\n\n // Used to prevent state updates after unmount\n const mounted = useRef(true);\n useEffect(() => {\n return () => {\n mounted.current = false;\n };\n },[]);\n\n // Boolean used to check if interaction is in progress in acquireTokenSilent fallback. Use Ref instead of state to prevent acquireToken function from being regenerated on each change to interactionInProgress value\n const interactionInProgress = useRef(inProgress !== InteractionStatus.None);\n useEffect(() => {\n interactionInProgress.current = inProgress !== InteractionStatus.None;\n }, [inProgress]);\n\n // Flag used to control when the hook calls login/acquireToken\n const shouldAcquireToken = useRef(true);\n useEffect(() => {\n if (!!error) {\n // Errors should be handled by consuming component\n shouldAcquireToken.current = false;\n return;\n }\n\n if (!!result) {\n // Token has already been acquired, consuming component/application is responsible for renewing\n shouldAcquireToken.current = false;\n return;\n }\n }, [error, result]);\n\n const login = useCallback(async (callbackInteractionType?: InteractionType, callbackRequest?: PopupRequest|RedirectRequest|SsoSilentRequest): Promise => {\n const loginType = callbackInteractionType || interactionType;\n const loginRequest = callbackRequest || authenticationRequest;\n switch (loginType) {\n case InteractionType.Popup:\n logger.verbose(\"useMsalAuthentication - Calling loginPopup\");\n return instance.loginPopup(loginRequest as PopupRequest);\n case InteractionType.Redirect:\n // This promise is not expected to resolve due to full frame redirect\n logger.verbose(\"useMsalAuthentication - Calling loginRedirect\");\n return instance.loginRedirect(loginRequest as RedirectRequest).then(null);\n case InteractionType.Silent:\n logger.verbose(\"useMsalAuthentication - Calling ssoSilent\");\n return instance.ssoSilent(loginRequest as SsoSilentRequest);\n default:\n throw ReactAuthError.createInvalidInteractionTypeError();\n }\n }, [instance, interactionType, authenticationRequest, logger]);\n\n const acquireToken = useCallback(async (callbackInteractionType?: InteractionType, callbackRequest?: SilentRequest): Promise => {\n const fallbackInteractionType = callbackInteractionType || interactionType;\n\n let tokenRequest: SilentRequest;\n\n if (callbackRequest) {\n logger.trace(\"useMsalAuthentication - acquireToken - Using request provided in the callback\");\n tokenRequest = {\n ...callbackRequest\n };\n } else if (authenticationRequest) {\n logger.trace(\"useMsalAuthentication - acquireToken - Using request provided in the hook\");\n tokenRequest = {\n ...authenticationRequest,\n scopes: authenticationRequest.scopes || OIDC_DEFAULT_SCOPES\n };\n } else {\n logger.trace(\"useMsalAuthentication - acquireToken - No request object provided, using default request.\");\n tokenRequest = {\n scopes: OIDC_DEFAULT_SCOPES\n };\n }\n \n if (!tokenRequest.account && account) {\n logger.trace(\"useMsalAuthentication - acquireToken - Attaching account to request\");\n tokenRequest.account = account;\n }\n\n const getToken = async (): Promise => {\n logger.verbose(\"useMsalAuthentication - Calling acquireTokenSilent\");\n return instance.acquireTokenSilent(tokenRequest).catch(async (e: AuthError) => {\n if (e instanceof InteractionRequiredAuthError) {\n if (!interactionInProgress.current) {\n logger.error(\"useMsalAuthentication - Interaction required, falling back to interaction\");\n return login(fallbackInteractionType, tokenRequest);\n } else {\n logger.error(\"useMsalAuthentication - Interaction required but is already in progress. Please try again, if needed, after interaction completes.\");\n throw ReactAuthError.createUnableToFallbackToInteractionError();\n }\n }\n\n throw e;\n });\n };\n\n return getToken().then((response: AuthenticationResult|null) => {\n if (mounted.current) {\n setResponse([response, null]);\n }\n return response;\n }).catch((e: AuthError) => {\n if (mounted.current) {\n setResponse([null, e]);\n }\n throw e;\n });\n }, [instance, interactionType, authenticationRequest, logger, account, login]);\n\n useEffect(() => {\n const callbackId = instance.addEventCallback((message: EventMessage) => {\n switch(message.eventType) {\n case EventType.LOGIN_SUCCESS:\n case EventType.SSO_SILENT_SUCCESS:\n if (message.payload) {\n setResponse([message.payload as AuthenticationResult, null]);\n }\n break;\n case EventType.LOGIN_FAILURE:\n case EventType.SSO_SILENT_FAILURE:\n if (message.error) {\n setResponse([null, message.error as AuthError]);\n }\n break;\n }\n });\n logger.verbose(`useMsalAuthentication - Registered event callback with id: ${callbackId}`);\n\n return () => {\n if (callbackId) {\n logger.verbose(`useMsalAuthentication - Removing event callback ${callbackId}`);\n instance.removeEventCallback(callbackId);\n }\n };\n }, [instance, logger]);\n\n useEffect(() => {\n if (shouldAcquireToken.current && inProgress === InteractionStatus.None) {\n shouldAcquireToken.current = false;\n if (!isAuthenticated) {\n logger.info(\"useMsalAuthentication - No user is authenticated, attempting to login\");\n login().catch(() => {\n // Errors are saved in state above\n return;\n });\n } else if (account) {\n logger.info(\"useMsalAuthentication - User is authenticated, attempting to acquire token\");\n acquireToken().catch(() => {\n // Errors are saved in state above\n return;\n });\n }\n }\n }, [isAuthenticated, account, inProgress, login, acquireToken, logger]);\n\n return { \n login, \n acquireToken, \n result, \n error\n };\n}\n","/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport React, { PropsWithChildren, useMemo } from \"react\";\nimport { AccountIdentifiers } from \"../types/AccountIdentifiers\";\nimport { getChildrenOrFunction } from \"../utils/utilities\";\nimport { useMsal } from \"../hooks/useMsal\";\nimport { useIsAuthenticated } from \"../hooks/useIsAuthenticated\";\nimport { InteractionStatus } from \"@azure/msal-browser\";\n\nexport type AuthenticatedTemplateProps = PropsWithChildren;\n\n/**\n * Renders child components if user is authenticated\n * @param props \n */\nexport function AuthenticatedTemplate({ username, homeAccountId, localAccountId, children }: AuthenticatedTemplateProps): React.ReactElement|null {\n const context = useMsal();\n const accountIdentifier: AccountIdentifiers = useMemo(() => {\n return {\n username,\n homeAccountId,\n localAccountId\n };\n }, [username, homeAccountId, localAccountId]);\n const isAuthenticated = useIsAuthenticated(accountIdentifier);\n\n if (isAuthenticated && context.inProgress !== InteractionStatus.Startup) {\n return (\n \n {getChildrenOrFunction(children, context)}\n \n );\n }\n return null;\n}\n","/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport React, { PropsWithChildren, useMemo } from \"react\";\nimport { AccountIdentifiers } from \"../types/AccountIdentifiers\";\nimport { getChildrenOrFunction } from \"../utils/utilities\";\nimport { useMsal } from \"../hooks/useMsal\";\nimport { MsalAuthenticationResult, useMsalAuthentication } from \"../hooks/useMsalAuthentication\";\nimport { useIsAuthenticated } from \"../hooks/useIsAuthenticated\";\nimport { InteractionType, PopupRequest, RedirectRequest, SsoSilentRequest, InteractionStatus } from \"@azure/msal-browser\";\nimport { IMsalContext } from \"../MsalContext\";\n\nexport type MsalAuthenticationProps = PropsWithChildren;\n errorComponent?: React.ElementType;\n}>;\n\n/**\n * Attempts to authenticate user if not already authenticated, then renders child components\n * @param props\n */\nexport function MsalAuthenticationTemplate({ \n interactionType, \n username, \n homeAccountId, \n localAccountId,\n authenticationRequest, \n loadingComponent: LoadingComponent,\n errorComponent: ErrorComponent,\n children \n}: MsalAuthenticationProps): React.ReactElement|null {\n const accountIdentifier: AccountIdentifiers = useMemo(() => {\n return {\n username,\n homeAccountId,\n localAccountId\n };\n }, [username, homeAccountId, localAccountId]);\n const context = useMsal();\n const msalAuthResult = useMsalAuthentication(interactionType, authenticationRequest, accountIdentifier);\n const isAuthenticated = useIsAuthenticated(accountIdentifier);\n\n if (msalAuthResult.error && context.inProgress === InteractionStatus.None) {\n if (!!ErrorComponent) {\n return ;\n }\n\n throw msalAuthResult.error;\n }\n \n if (isAuthenticated) {\n return (\n \n {getChildrenOrFunction(children, msalAuthResult)}\n \n );\n } \n \n if (!!LoadingComponent && context.inProgress !== InteractionStatus.None) {\n return ;\n }\n\n return null;\n}\n","/* eslint-disable header/header */\nexport const name = \"@azure/msal-react\";\nexport const version = \"1.5.2\";\n","/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport React, { PropsWithChildren, useMemo } from \"react\";\nimport { useMsal } from \"../hooks/useMsal\";\nimport { useIsAuthenticated } from \"../hooks/useIsAuthenticated\";\nimport { getChildrenOrFunction } from \"../utils/utilities\";\nimport { AccountIdentifiers } from \"../types/AccountIdentifiers\";\nimport { InteractionStatus } from \"@azure/msal-browser\";\n\nexport type UnauthenticatedTemplateProps = PropsWithChildren;\n\n/**\n * Renders child components if user is unauthenticated\n * @param props \n */\nexport function UnauthenticatedTemplate({ username, homeAccountId, localAccountId, children }: UnauthenticatedTemplateProps): React.ReactElement|null {\n const context = useMsal();\n const accountIdentifier: AccountIdentifiers = useMemo(() => {\n return {\n username,\n homeAccountId,\n localAccountId\n };\n }, [username, homeAccountId, localAccountId]);\n const isAuthenticated = useIsAuthenticated(accountIdentifier);\n\n if (!isAuthenticated && context.inProgress !== InteractionStatus.Startup && context.inProgress !== InteractionStatus.HandleRedirect) {\n return (\n \n {getChildrenOrFunction(children, context)}\n \n );\n }\n return null;\n}\n","/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport React from \"react\";\nimport { IMsalContext } from \"../MsalContext\";\nimport { useMsal } from \"../hooks/useMsal\";\nimport { Subtract } from \"../utils/utilities\";\n\nexport type WithMsalProps = {\n msalContext: IMsalContext;\n};\n\n/**\n * Higher order component wraps provided component with msal by injecting msal context values into the component's props \n * @param Component \n */\nexport const withMsal =

(Component: React.ComponentType

): React.FunctionComponent> => {\n const ComponentWithMsal: React.FunctionComponent> = props => {\n const msal = useMsal();\n return ;\n };\n\n const componentName =\n Component.displayName || Component.name || \"Component\";\n ComponentWithMsal.displayName = `withMsal(${componentName})`;\n\n return ComponentWithMsal;\n};\n"],"names":["MsalContext","React","instance","stubbedPublicClientApplication","inProgress","InteractionStatus","None","accounts","logger","Logger","MsalConsumer","Consumer","getChildrenOrFunction","children","args","accountArraysAreEqual","arrayA","arrayB","length","comparisonArray","every","elementA","elementB","shift","homeAccountId","localAccountId","username","getAccountByIdentifiers","allAccounts","accountIdentifiers","filter","accountObj","toLowerCase","MsalProviderActionType","reducer","previousState","action","type","payload","newInProgress","UNBLOCK_INPROGRESS","Startup","info","EVENT","message","status","EventMessageUtils","getInteractionStatusFromEvent","eventType","Error","currentAccounts","getAllAccounts","useMsal","useContext","isAuthenticated","matchAccount","useIsAuthenticated","hasAuthenticated","setHasAuthenticated","useState","useEffect","getAccount","getActiveAccount","useAccount","account","setAccount","currentAccount","nextAccount","AccountEntity","accountInfoIsEqual","ReactAuthError","AuthError","constructor","errorCode","errorMessage","Object","setPrototypeOf","this","prototype","name","useMsalAuthentication","interactionType","authenticationRequest","result","error","setResponse","mounted","useRef","current","interactionInProgress","shouldAcquireToken","login","useCallback","async","callbackInteractionType","callbackRequest","loginRequest","InteractionType","Popup","verbose","loginPopup","Redirect","loginRedirect","then","Silent","ssoSilent","createInvalidInteractionTypeError","acquireToken","fallbackInteractionType","tokenRequest","trace","scopes","OIDC_DEFAULT_SCOPES","acquireTokenSilent","catch","e","InteractionRequiredAuthError","createUnableToFallbackToInteractionError","getToken","response","callbackId","addEventCallback","EventType","LOGIN_SUCCESS","SSO_SILENT_SUCCESS","LOGIN_FAILURE","SSO_SILENT_FAILURE","removeEventCallback","context","useMemo","Fragment","loadingComponent","LoadingComponent","errorComponent","ErrorComponent","accountIdentifier","msalAuthResult","initializeWrapperLibrary","WrapperSKU","getLogger","clone","state","updateState","useReducer","undefined","initialize","handleRedirectPromise","finally","Provider","value","HandleRedirect","Component","ComponentWithMsal","props","msal","msalContext","displayName"],"mappings":"qLAmBA,MAOaA,EAAcC,gBAPc,CACrCC,SAAUC,iCACVC,WAAYC,oBAAkBC,KAC9BC,SAAU,GACVC,OAAQ,IAAIC,SAAO,MAMVC,E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