@azure/msal-react 1.5.7 → 2.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/MsalContext.js +24 -0
  2. package/dist/MsalContext.js.map +1 -0
  3. package/dist/MsalProvider.d.ts +2 -2
  4. package/dist/MsalProvider.js +142 -0
  5. package/dist/MsalProvider.js.map +1 -0
  6. package/dist/components/AuthenticatedTemplate.d.ts +2 -2
  7. package/dist/components/AuthenticatedTemplate.js +34 -0
  8. package/dist/components/AuthenticatedTemplate.js.map +1 -0
  9. package/dist/components/MsalAuthenticationTemplate.d.ts +2 -2
  10. package/dist/components/MsalAuthenticationTemplate.js +45 -0
  11. package/dist/components/MsalAuthenticationTemplate.js.map +1 -0
  12. package/dist/components/UnauthenticatedTemplate.d.ts +2 -2
  13. package/dist/components/UnauthenticatedTemplate.js +36 -0
  14. package/dist/components/UnauthenticatedTemplate.js.map +1 -0
  15. package/dist/components/withMsal.d.ts +2 -2
  16. package/dist/components/withMsal.js +25 -0
  17. package/dist/components/withMsal.js.map +1 -0
  18. package/dist/error/ReactAuthError.js +34 -0
  19. package/dist/error/ReactAuthError.js.map +1 -0
  20. package/dist/hooks/useAccount.js +43 -0
  21. package/dist/hooks/useAccount.js.map +1 -0
  22. package/dist/hooks/useIsAuthenticated.js +40 -0
  23. package/dist/hooks/useIsAuthenticated.js.map +1 -0
  24. package/dist/hooks/useMsal.js +16 -0
  25. package/dist/hooks/useMsal.js.map +1 -0
  26. package/dist/hooks/useMsalAuthentication.d.ts +1 -1
  27. package/dist/hooks/useMsalAuthentication.js +196 -0
  28. package/dist/hooks/useMsalAuthentication.js.map +1 -0
  29. package/dist/index.js +14 -8
  30. package/dist/index.js.map +1 -0
  31. package/dist/packageMetadata.d.ts +1 -1
  32. package/dist/packageMetadata.js +8 -0
  33. package/dist/packageMetadata.js.map +1 -0
  34. package/dist/types/AccountIdentifiers.d.ts +1 -1
  35. package/dist/utils/utilities.d.ts +4 -4
  36. package/dist/utils/utilities.js +65 -0
  37. package/dist/utils/utilities.js.map +1 -0
  38. package/package.json +17 -16
@@ -0,0 +1,24 @@
1
+ /*! @azure/msal-react v2.0.0-alpha.1 2023-05-08 */
2
+ 'use strict';
3
+ import * as React from 'react';
4
+ import { stubbedPublicClientApplication, InteractionStatus, Logger } from '@azure/msal-browser';
5
+
6
+ /*
7
+ * Copyright (c) Microsoft Corporation. All rights reserved.
8
+ * Licensed under the MIT License.
9
+ */
10
+ /*
11
+ * Stubbed context implementation
12
+ * Only used when there is no provider, which is an unsupported scenario
13
+ */
14
+ const defaultMsalContext = {
15
+ instance: stubbedPublicClientApplication,
16
+ inProgress: InteractionStatus.None,
17
+ accounts: [],
18
+ logger: new Logger({}),
19
+ };
20
+ const MsalContext = React.createContext(defaultMsalContext);
21
+ const MsalConsumer = MsalContext.Consumer;
22
+
23
+ export { MsalConsumer, MsalContext };
24
+ //# sourceMappingURL=MsalContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MsalContext.js","sources":["../src/MsalContext.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAAA;;;AAGG;AAkBH;;;AAGG;AACH,MAAM,kBAAkB,GAAiB;AACrC,IAAA,QAAQ,EAAE,8BAA8B;IACxC,UAAU,EAAE,iBAAiB,CAAC,IAAI;AAClC,IAAA,QAAQ,EAAE,EAAE;AACZ,IAAA,MAAM,EAAE,IAAI,MAAM,CAAC,EAAE,CAAC;CACzB,CAAC;AAEW,MAAA,WAAW,GACpB,KAAK,CAAC,aAAa,CAAe,kBAAkB,EAAE;AAC7C,MAAA,YAAY,GAAG,WAAW,CAAC;;;;"}
@@ -1,9 +1,9 @@
1
1
  import React, { PropsWithChildren } from "react";
2
2
  import { IPublicClientApplication } from "@azure/msal-browser";
3
- export declare type MsalProviderProps = PropsWithChildren<{
3
+ export type MsalProviderProps = PropsWithChildren<{
4
4
  instance: IPublicClientApplication;
5
5
  }>;
6
6
  /**
7
7
  * MSAL context provider component. This must be rendered above any other components that use MSAL.
8
8
  */
9
- export declare function MsalProvider({ instance, children }: MsalProviderProps): React.ReactElement;
9
+ export declare function MsalProvider({ instance, children, }: MsalProviderProps): React.ReactElement;
@@ -0,0 +1,142 @@
1
+ /*! @azure/msal-react v2.0.0-alpha.1 2023-05-08 */
2
+ 'use strict';
3
+ import React__default, { useEffect, useMemo, useReducer } from 'react';
4
+ import { WrapperSKU, InteractionStatus, EventMessageUtils } from '@azure/msal-browser';
5
+ import { MsalContext } from './MsalContext.js';
6
+ import { accountArraysAreEqual } from './utils/utilities.js';
7
+ import { version, name } from './packageMetadata.js';
8
+
9
+ /*
10
+ * Copyright (c) Microsoft Corporation. All rights reserved.
11
+ * Licensed under the MIT License.
12
+ */
13
+ var MsalProviderActionType;
14
+ (function (MsalProviderActionType) {
15
+ MsalProviderActionType["UNBLOCK_INPROGRESS"] = "UNBLOCK_INPROGRESS";
16
+ MsalProviderActionType["EVENT"] = "EVENT";
17
+ })(MsalProviderActionType || (MsalProviderActionType = {}));
18
+ /**
19
+ * Returns the next inProgress and accounts state based on event message
20
+ * @param previousState
21
+ * @param action
22
+ */
23
+ const reducer = (previousState, action) => {
24
+ const { type, payload } = action;
25
+ let newInProgress = previousState.inProgress;
26
+ switch (type) {
27
+ case MsalProviderActionType.UNBLOCK_INPROGRESS:
28
+ if (previousState.inProgress === InteractionStatus.Startup) {
29
+ newInProgress = InteractionStatus.None;
30
+ payload.logger.info("MsalProvider - handleRedirectPromise resolved, setting inProgress to 'none'");
31
+ }
32
+ break;
33
+ case MsalProviderActionType.EVENT:
34
+ const message = payload.message;
35
+ const status = EventMessageUtils.getInteractionStatusFromEvent(message, previousState.inProgress);
36
+ if (status) {
37
+ payload.logger.info(`MsalProvider - ${message.eventType} results in setting inProgress from ${previousState.inProgress} to ${status}`);
38
+ newInProgress = status;
39
+ }
40
+ break;
41
+ default:
42
+ throw new Error(`Unknown action type: ${type}`);
43
+ }
44
+ const currentAccounts = payload.instance.getAllAccounts();
45
+ if (newInProgress !== previousState.inProgress &&
46
+ !accountArraysAreEqual(currentAccounts, previousState.accounts)) {
47
+ // Both inProgress and accounts changed
48
+ return {
49
+ ...previousState,
50
+ inProgress: newInProgress,
51
+ accounts: currentAccounts,
52
+ };
53
+ }
54
+ else if (newInProgress !== previousState.inProgress) {
55
+ // Only only inProgress changed
56
+ return {
57
+ ...previousState,
58
+ inProgress: newInProgress,
59
+ };
60
+ }
61
+ else if (!accountArraysAreEqual(currentAccounts, previousState.accounts)) {
62
+ // Only accounts changed
63
+ return {
64
+ ...previousState,
65
+ accounts: currentAccounts,
66
+ };
67
+ }
68
+ else {
69
+ // Nothing changed
70
+ return previousState;
71
+ }
72
+ };
73
+ /**
74
+ * MSAL context provider component. This must be rendered above any other components that use MSAL.
75
+ */
76
+ function MsalProvider({ instance, children, }) {
77
+ useEffect(() => {
78
+ instance.initializeWrapperLibrary(WrapperSKU.React, version);
79
+ }, [instance]);
80
+ // Create a logger instance for msal-react with the same options as PublicClientApplication
81
+ const logger = useMemo(() => {
82
+ return instance.getLogger().clone(name, version);
83
+ }, [instance]);
84
+ const [state, updateState] = useReducer(reducer, undefined, () => {
85
+ // Lazy initialization of the initial state
86
+ return {
87
+ inProgress: InteractionStatus.Startup,
88
+ accounts: instance.getAllAccounts(),
89
+ };
90
+ });
91
+ useEffect(() => {
92
+ const callbackId = instance.addEventCallback((message) => {
93
+ updateState({
94
+ payload: {
95
+ instance,
96
+ logger,
97
+ message,
98
+ },
99
+ type: MsalProviderActionType.EVENT,
100
+ });
101
+ });
102
+ logger.verbose(`MsalProvider - Registered event callback with id: ${callbackId}`);
103
+ instance.initialize().then(() => {
104
+ instance
105
+ .handleRedirectPromise()
106
+ .catch(() => {
107
+ // Errors should be handled by listening to the LOGIN_FAILURE event
108
+ return;
109
+ })
110
+ .finally(() => {
111
+ /*
112
+ * If handleRedirectPromise returns a cached promise the necessary events may not be fired
113
+ * This is a fallback to prevent inProgress from getting stuck in 'startup'
114
+ */
115
+ updateState({
116
+ payload: {
117
+ instance,
118
+ logger,
119
+ },
120
+ type: MsalProviderActionType.UNBLOCK_INPROGRESS,
121
+ });
122
+ });
123
+ });
124
+ return () => {
125
+ // Remove callback when component unmounts or accounts change
126
+ if (callbackId) {
127
+ logger.verbose(`MsalProvider - Removing event callback ${callbackId}`);
128
+ instance.removeEventCallback(callbackId);
129
+ }
130
+ };
131
+ }, [instance, logger]);
132
+ const contextValue = {
133
+ instance,
134
+ inProgress: state.inProgress,
135
+ accounts: state.accounts,
136
+ logger,
137
+ };
138
+ return (React__default.createElement(MsalContext.Provider, { value: contextValue }, children));
139
+ }
140
+
141
+ export { MsalProvider };
142
+ //# sourceMappingURL=MsalProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MsalProvider.js","sources":["../src/MsalProvider.tsx"],"sourcesContent":[null],"names":["SKU","React"],"mappings":";;;;;;;;AAAA;;;AAGG;AA8BH,IAAK,sBAGJ,CAAA;AAHD,CAAA,UAAK,sBAAsB,EAAA;AACvB,IAAA,sBAAA,CAAA,oBAAA,CAAA,GAAA,oBAAyC,CAAA;AACzC,IAAA,sBAAA,CAAA,OAAA,CAAA,GAAA,OAAe,CAAA;AACnB,CAAC,EAHI,sBAAsB,KAAtB,sBAAsB,GAG1B,EAAA,CAAA,CAAA,CAAA;AAWD;;;;AAIG;AACH,MAAM,OAAO,GAAG,CACZ,aAAwB,EACxB,MAAiC,KACtB;AACX,IAAA,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;AACjC,IAAA,IAAI,aAAa,GAAG,aAAa,CAAC,UAAU,CAAC;AAE7C,IAAA,QAAQ,IAAI;QACR,KAAK,sBAAsB,CAAC,kBAAkB;AAC1C,YAAA,IAAI,aAAa,CAAC,UAAU,KAAK,iBAAiB,CAAC,OAAO,EAAE;AACxD,gBAAA,aAAa,GAAG,iBAAiB,CAAC,IAAI,CAAC;AACvC,gBAAA,OAAO,CAAC,MAAM,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AC;AACR,oBAAA,OAAO,EAAE;wBACL,QAAQ;wBACR,MAAM;AACT,qBAAA;oBACD,IAAI,EAAE,sBAAsB,CAAC,kBAAkB;AAClD,iBAAA,CAAC,CAAC;AACP,aAAC,CAAC,CAAC;AACX,SAAC,CAAC,CAAC;AAEH,QAAA,OAAO,MAAK;;AAER,YAAA,IAAI,UAAU,EAAE;AACZ,gBAAA,MAAM,CAAC,OAAO,CACV,0CAA0C,UAAU,CAAA,CAAE,CACzD,CAAC;AACF,gBAAA,QAAQ,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC;AAC5C,aAAA;AACL,SAAC,CAAC;AACN,KAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;AAEvB,IAAA,MAAM,YAAY,GAAiB;QAC/B,QAAQ;QACR,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,MAAM;KACT,CAAC;AAEF,IAAA,QACIC,cAAA,CAAA,aAAA,CAAC,WAAW,CAAC,QAAQ,EAAA,EAAC,KAAK,EAAE,YAAY,EAAA,EACpC,QAAQ,CACU,EACzB;AACN;;;;"}
@@ -1,8 +1,8 @@
1
1
  import React, { PropsWithChildren } from "react";
2
2
  import { AccountIdentifiers } from "../types/AccountIdentifiers";
3
- export declare type AuthenticatedTemplateProps = PropsWithChildren<AccountIdentifiers>;
3
+ export type AuthenticatedTemplateProps = PropsWithChildren<AccountIdentifiers>;
4
4
  /**
5
5
  * Renders child components if user is authenticated
6
6
  * @param props
7
7
  */
8
- export declare function AuthenticatedTemplate({ username, homeAccountId, localAccountId, children }: AuthenticatedTemplateProps): React.ReactElement | null;
8
+ export declare function AuthenticatedTemplate({ username, homeAccountId, localAccountId, children, }: AuthenticatedTemplateProps): React.ReactElement | null;
@@ -0,0 +1,34 @@
1
+ /*! @azure/msal-react v2.0.0-alpha.1 2023-05-08 */
2
+ 'use strict';
3
+ import React__default, { useMemo } from 'react';
4
+ import { getChildrenOrFunction } from '../utils/utilities.js';
5
+ import { useMsal } from '../hooks/useMsal.js';
6
+ import { useIsAuthenticated } from '../hooks/useIsAuthenticated.js';
7
+ import { InteractionStatus } from '@azure/msal-browser';
8
+
9
+ /*
10
+ * Copyright (c) Microsoft Corporation. All rights reserved.
11
+ * Licensed under the MIT License.
12
+ */
13
+ /**
14
+ * Renders child components if user is authenticated
15
+ * @param props
16
+ */
17
+ function AuthenticatedTemplate({ username, homeAccountId, localAccountId, children, }) {
18
+ const context = useMsal();
19
+ const accountIdentifier = useMemo(() => {
20
+ return {
21
+ username,
22
+ homeAccountId,
23
+ localAccountId,
24
+ };
25
+ }, [username, homeAccountId, localAccountId]);
26
+ const isAuthenticated = useIsAuthenticated(accountIdentifier);
27
+ if (isAuthenticated && context.inProgress !== InteractionStatus.Startup) {
28
+ return (React__default.createElement(React__default.Fragment, null, getChildrenOrFunction(children, context)));
29
+ }
30
+ return null;
31
+ }
32
+
33
+ export { AuthenticatedTemplate };
34
+ //# sourceMappingURL=AuthenticatedTemplate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuthenticatedTemplate.js","sources":["../../src/components/AuthenticatedTemplate.tsx"],"sourcesContent":[null],"names":["React"],"mappings":";;;;;;;;AAAA;;;AAGG;AAWH;;;AAGG;AACG,SAAU,qBAAqB,CAAC,EAClC,QAAQ,EACR,aAAa,EACb,cAAc,EACd,QAAQ,GACiB,EAAA;AACzB,IAAA,MAAM,OAAO,GAAG,OAAO,EAAE,CAAC;AAC1B,IAAA,MAAM,iBAAiB,GAAuB,OAAO,CAAC,MAAK;QACvD,OAAO;YACH,QAAQ;YACR,aAAa;YACb,cAAc;SACjB,CAAC;KACL,EAAE,CAAC,QAAQ,EAAE,aAAa,EAAE,cAAc,CAAC,CAAC,CAAC;AAC9C,IAAA,MAAM,eAAe,GAAG,kBAAkB,CAAC,iBAAiB,CAAC,CAAC;IAE9D,IAAI,eAAe,IAAI,OAAO,CAAC,UAAU,KAAK,iBAAiB,CAAC,OAAO,EAAE;AACrE,QAAA,QACIA,cAAA,CAAA,aAAA,CAACA,cAAK,CAAC,QAAQ,EACV,IAAA,EAAA,qBAAqB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAC5B,EACnB;AACL,KAAA;AACD,IAAA,OAAO,IAAI,CAAC;AAChB;;;;"}
@@ -3,7 +3,7 @@ import { AccountIdentifiers } from "../types/AccountIdentifiers";
3
3
  import { MsalAuthenticationResult } from "../hooks/useMsalAuthentication";
4
4
  import { InteractionType, PopupRequest, RedirectRequest, SsoSilentRequest } from "@azure/msal-browser";
5
5
  import { IMsalContext } from "../MsalContext";
6
- export declare type MsalAuthenticationProps = PropsWithChildren<AccountIdentifiers & {
6
+ export type MsalAuthenticationProps = PropsWithChildren<AccountIdentifiers & {
7
7
  interactionType: InteractionType;
8
8
  authenticationRequest?: PopupRequest | RedirectRequest | SsoSilentRequest;
9
9
  loadingComponent?: React.ElementType<IMsalContext>;
@@ -13,4 +13,4 @@ export declare type MsalAuthenticationProps = PropsWithChildren<AccountIdentifie
13
13
  * Attempts to authenticate user if not already authenticated, then renders child components
14
14
  * @param props
15
15
  */
16
- export declare function MsalAuthenticationTemplate({ interactionType, username, homeAccountId, localAccountId, authenticationRequest, loadingComponent: LoadingComponent, errorComponent: ErrorComponent, children }: MsalAuthenticationProps): React.ReactElement | null;
16
+ export declare function MsalAuthenticationTemplate({ interactionType, username, homeAccountId, localAccountId, authenticationRequest, loadingComponent: LoadingComponent, errorComponent: ErrorComponent, children, }: MsalAuthenticationProps): React.ReactElement | null;
@@ -0,0 +1,45 @@
1
+ /*! @azure/msal-react v2.0.0-alpha.1 2023-05-08 */
2
+ 'use strict';
3
+ import React__default, { useMemo } from 'react';
4
+ import { getChildrenOrFunction } from '../utils/utilities.js';
5
+ import { useMsal } from '../hooks/useMsal.js';
6
+ import { useMsalAuthentication } from '../hooks/useMsalAuthentication.js';
7
+ import { useIsAuthenticated } from '../hooks/useIsAuthenticated.js';
8
+ import { InteractionStatus } from '@azure/msal-browser';
9
+
10
+ /*
11
+ * Copyright (c) Microsoft Corporation. All rights reserved.
12
+ * Licensed under the MIT License.
13
+ */
14
+ /**
15
+ * Attempts to authenticate user if not already authenticated, then renders child components
16
+ * @param props
17
+ */
18
+ function MsalAuthenticationTemplate({ interactionType, username, homeAccountId, localAccountId, authenticationRequest, loadingComponent: LoadingComponent, errorComponent: ErrorComponent, children, }) {
19
+ const accountIdentifier = useMemo(() => {
20
+ return {
21
+ username,
22
+ homeAccountId,
23
+ localAccountId,
24
+ };
25
+ }, [username, homeAccountId, localAccountId]);
26
+ const context = useMsal();
27
+ const msalAuthResult = useMsalAuthentication(interactionType, authenticationRequest, accountIdentifier);
28
+ const isAuthenticated = useIsAuthenticated(accountIdentifier);
29
+ if (msalAuthResult.error && context.inProgress === InteractionStatus.None) {
30
+ if (!!ErrorComponent) {
31
+ return React__default.createElement(ErrorComponent, { ...msalAuthResult });
32
+ }
33
+ throw msalAuthResult.error;
34
+ }
35
+ if (isAuthenticated) {
36
+ return (React__default.createElement(React__default.Fragment, null, getChildrenOrFunction(children, msalAuthResult)));
37
+ }
38
+ if (!!LoadingComponent && context.inProgress !== InteractionStatus.None) {
39
+ return React__default.createElement(LoadingComponent, { ...context });
40
+ }
41
+ return null;
42
+ }
43
+
44
+ export { MsalAuthenticationTemplate };
45
+ //# sourceMappingURL=MsalAuthenticationTemplate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MsalAuthenticationTemplate.js","sources":["../../src/components/MsalAuthenticationTemplate.tsx"],"sourcesContent":[null],"names":["React"],"mappings":";;;;;;;;;AAAA;;;AAGG;AAgCH;;;AAGG;AACG,SAAU,0BAA0B,CAAC,EACvC,eAAe,EACf,QAAQ,EACR,aAAa,EACb,cAAc,EACd,qBAAqB,EACrB,gBAAgB,EAAE,gBAAgB,EAClC,cAAc,EAAE,cAAc,EAC9B,QAAQ,GACc,EAAA;AACtB,IAAA,MAAM,iBAAiB,GAAuB,OAAO,CAAC,MAAK;QACvD,OAAO;YACH,QAAQ;YACR,aAAa;YACb,cAAc;SACjB,CAAC;KACL,EAAE,CAAC,QAAQ,EAAE,aAAa,EAAE,cAAc,CAAC,CAAC,CAAC;AAC9C,IAAA,MAAM,OAAO,GAAG,OAAO,EAAE,CAAC;IAC1B,MAAM,cAAc,GAAG,qBAAqB,CACxC,eAAe,EACf,qBAAqB,EACrB,iBAAiB,CACpB,CAAC;AACF,IAAA,MAAM,eAAe,GAAG,kBAAkB,CAAC,iBAAiB,CAAC,CAAC;IAE9D,IAAI,cAAc,CAAC,KAAK,IAAI,OAAO,CAAC,UAAU,KAAK,iBAAiB,CAAC,IAAI,EAAE;QACvE,IAAI,CAAC,CAAC,cAAc,EAAE;AAClB,YAAA,OAAOA,cAAC,CAAA,aAAA,CAAA,cAAc,EAAK,EAAA,GAAA,cAAc,GAAI,CAAC;AACjD,SAAA;QAED,MAAM,cAAc,CAAC,KAAK,CAAC;AAC9B,KAAA;AAED,IAAA,IAAI,eAAe,EAAE;AACjB,QAAA,QACIA,cAAA,CAAA,aAAA,CAACA,cAAK,CAAC,QAAQ,EACV,IAAA,EAAA,qBAAqB,CAAC,QAAQ,EAAE,cAAc,CAAC,CACnC,EACnB;AACL,KAAA;IAED,IAAI,CAAC,CAAC,gBAAgB,IAAI,OAAO,CAAC,UAAU,KAAK,iBAAiB,CAAC,IAAI,EAAE;AACrE,QAAA,OAAOA,cAAC,CAAA,aAAA,CAAA,gBAAgB,EAAK,EAAA,GAAA,OAAO,GAAI,CAAC;AAC5C,KAAA;AAED,IAAA,OAAO,IAAI,CAAC;AAChB;;;;"}
@@ -1,8 +1,8 @@
1
1
  import React, { PropsWithChildren } from "react";
2
2
  import { AccountIdentifiers } from "../types/AccountIdentifiers";
3
- export declare type UnauthenticatedTemplateProps = PropsWithChildren<AccountIdentifiers>;
3
+ export type UnauthenticatedTemplateProps = PropsWithChildren<AccountIdentifiers>;
4
4
  /**
5
5
  * Renders child components if user is unauthenticated
6
6
  * @param props
7
7
  */
8
- export declare function UnauthenticatedTemplate({ username, homeAccountId, localAccountId, children }: UnauthenticatedTemplateProps): React.ReactElement | null;
8
+ export declare function UnauthenticatedTemplate({ username, homeAccountId, localAccountId, children, }: UnauthenticatedTemplateProps): React.ReactElement | null;
@@ -0,0 +1,36 @@
1
+ /*! @azure/msal-react v2.0.0-alpha.1 2023-05-08 */
2
+ 'use strict';
3
+ import React__default, { useMemo } from 'react';
4
+ import { useMsal } from '../hooks/useMsal.js';
5
+ import { useIsAuthenticated } from '../hooks/useIsAuthenticated.js';
6
+ import { getChildrenOrFunction } from '../utils/utilities.js';
7
+ import { InteractionStatus } from '@azure/msal-browser';
8
+
9
+ /*
10
+ * Copyright (c) Microsoft Corporation. All rights reserved.
11
+ * Licensed under the MIT License.
12
+ */
13
+ /**
14
+ * Renders child components if user is unauthenticated
15
+ * @param props
16
+ */
17
+ function UnauthenticatedTemplate({ username, homeAccountId, localAccountId, children, }) {
18
+ const context = useMsal();
19
+ const accountIdentifier = useMemo(() => {
20
+ return {
21
+ username,
22
+ homeAccountId,
23
+ localAccountId,
24
+ };
25
+ }, [username, homeAccountId, localAccountId]);
26
+ const isAuthenticated = useIsAuthenticated(accountIdentifier);
27
+ if (!isAuthenticated &&
28
+ context.inProgress !== InteractionStatus.Startup &&
29
+ context.inProgress !== InteractionStatus.HandleRedirect) {
30
+ return (React__default.createElement(React__default.Fragment, null, getChildrenOrFunction(children, context)));
31
+ }
32
+ return null;
33
+ }
34
+
35
+ export { UnauthenticatedTemplate };
36
+ //# sourceMappingURL=UnauthenticatedTemplate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UnauthenticatedTemplate.js","sources":["../../src/components/UnauthenticatedTemplate.tsx"],"sourcesContent":[null],"names":["React"],"mappings":";;;;;;;;AAAA;;;AAGG;AAYH;;;AAGG;AACG,SAAU,uBAAuB,CAAC,EACpC,QAAQ,EACR,aAAa,EACb,cAAc,EACd,QAAQ,GACmB,EAAA;AAC3B,IAAA,MAAM,OAAO,GAAG,OAAO,EAAE,CAAC;AAC1B,IAAA,MAAM,iBAAiB,GAAuB,OAAO,CAAC,MAAK;QACvD,OAAO;YACH,QAAQ;YACR,aAAa;YACb,cAAc;SACjB,CAAC;KACL,EAAE,CAAC,QAAQ,EAAE,aAAa,EAAE,cAAc,CAAC,CAAC,CAAC;AAC9C,IAAA,MAAM,eAAe,GAAG,kBAAkB,CAAC,iBAAiB,CAAC,CAAC;AAE9D,IAAA,IACI,CAAC,eAAe;AAChB,QAAA,OAAO,CAAC,UAAU,KAAK,iBAAiB,CAAC,OAAO;AAChD,QAAA,OAAO,CAAC,UAAU,KAAK,iBAAiB,CAAC,cAAc,EACzD;AACE,QAAA,QACIA,cAAA,CAAA,aAAA,CAACA,cAAK,CAAC,QAAQ,EACV,IAAA,EAAA,qBAAqB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAC5B,EACnB;AACL,KAAA;AACD,IAAA,OAAO,IAAI,CAAC;AAChB;;;;"}
@@ -1,11 +1,11 @@
1
1
  import React from "react";
2
2
  import { IMsalContext } from "../MsalContext";
3
3
  import { Subtract } from "../utils/utilities";
4
- export declare type WithMsalProps = {
4
+ export type WithMsalProps = {
5
5
  msalContext: IMsalContext;
6
6
  };
7
7
  /**
8
8
  * Higher order component wraps provided component with msal by injecting msal context values into the component's props
9
9
  * @param Component
10
10
  */
11
- export declare const withMsal: <P extends WithMsalProps>(Component: React.ComponentType<P>) => React.FunctionComponent<Pick<P, keyof P extends "msalContext" ? never : keyof P>>;
11
+ export declare const withMsal: <P extends WithMsalProps>(Component: React.ComponentType<P>) => React.FunctionComponent<Subtract<P, WithMsalProps>>;
@@ -0,0 +1,25 @@
1
+ /*! @azure/msal-react v2.0.0-alpha.1 2023-05-08 */
2
+ 'use strict';
3
+ import React__default from 'react';
4
+ import { useMsal } from '../hooks/useMsal.js';
5
+
6
+ /*
7
+ * Copyright (c) Microsoft Corporation. All rights reserved.
8
+ * Licensed under the MIT License.
9
+ */
10
+ /**
11
+ * Higher order component wraps provided component with msal by injecting msal context values into the component's props
12
+ * @param Component
13
+ */
14
+ const withMsal = (Component) => {
15
+ const ComponentWithMsal = (props) => {
16
+ const msal = useMsal();
17
+ return React__default.createElement(Component, { ...props, msalContext: msal });
18
+ };
19
+ const componentName = Component.displayName || Component.name || "Component";
20
+ ComponentWithMsal.displayName = `withMsal(${componentName})`;
21
+ return ComponentWithMsal;
22
+ };
23
+
24
+ export { withMsal };
25
+ //# sourceMappingURL=withMsal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withMsal.js","sources":["../../src/components/withMsal.tsx"],"sourcesContent":[null],"names":["React"],"mappings":";;;;;AAAA;;;AAGG;AAWH;;;AAGG;AACU,MAAA,QAAQ,GAAG,CACpB,SAAiC,KACoB;AACrD,IAAA,MAAM,iBAAiB,GAEnB,CAAC,KAAK,KAAI;AACV,QAAA,MAAM,IAAI,GAAG,OAAO,EAAE,CAAC;QACvB,OAAOA,cAAA,CAAA,aAAA,CAAC,SAAS,EAAM,EAAA,GAAA,KAAW,EAAE,WAAW,EAAE,IAAI,EAAA,CAAI,CAAC;AAC9D,KAAC,CAAC;IAEF,MAAM,aAAa,GACf,SAAS,CAAC,WAAW,IAAI,SAAS,CAAC,IAAI,IAAI,WAAW,CAAC;AAC3D,IAAA,iBAAiB,CAAC,WAAW,GAAG,CAAY,SAAA,EAAA,aAAa,GAAG,CAAC;AAE7D,IAAA,OAAO,iBAAiB,CAAC;AAC7B;;;;"}
@@ -0,0 +1,34 @@
1
+ /*! @azure/msal-react v2.0.0-alpha.1 2023-05-08 */
2
+ 'use strict';
3
+ import { AuthError } from '@azure/msal-browser';
4
+
5
+ /*
6
+ * Copyright (c) Microsoft Corporation. All rights reserved.
7
+ * Licensed under the MIT License.
8
+ */
9
+ const ReactAuthErrorMessage = {
10
+ invalidInteractionType: {
11
+ code: "invalid_interaction_type",
12
+ desc: "The provided interaction type is invalid.",
13
+ },
14
+ unableToFallbackToInteraction: {
15
+ code: "unable_to_fallback_to_interaction",
16
+ desc: "Interaction is required but another interaction is already in progress. Please try again when the current interaction is complete.",
17
+ },
18
+ };
19
+ class ReactAuthError extends AuthError {
20
+ constructor(errorCode, errorMessage) {
21
+ super(errorCode, errorMessage);
22
+ Object.setPrototypeOf(this, ReactAuthError.prototype);
23
+ this.name = "ReactAuthError";
24
+ }
25
+ static createInvalidInteractionTypeError() {
26
+ return new ReactAuthError(ReactAuthErrorMessage.invalidInteractionType.code, ReactAuthErrorMessage.invalidInteractionType.desc);
27
+ }
28
+ static createUnableToFallbackToInteractionError() {
29
+ return new ReactAuthError(ReactAuthErrorMessage.unableToFallbackToInteraction.code, ReactAuthErrorMessage.unableToFallbackToInteraction.desc);
30
+ }
31
+ }
32
+
33
+ export { ReactAuthError, ReactAuthErrorMessage };
34
+ //# sourceMappingURL=ReactAuthError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReactAuthError.js","sources":["../../src/error/ReactAuthError.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAAA;;;AAGG;AAIU,MAAA,qBAAqB,GAAG;AACjC,IAAA,sBAAsB,EAAE;AACpB,QAAA,IAAI,EAAE,0BAA0B;AAChC,QAAA,IAAI,EAAE,2CAA2C;AACpD,KAAA;AACD,IAAA,6BAA6B,EAAE;AAC3B,QAAA,IAAI,EAAE,mCAAmC;AACzC,QAAA,IAAI,EAAE,oIAAoI;AAC7I,KAAA;EACH;AAEI,MAAO,cAAe,SAAQ,SAAS,CAAA;IACzC,WAAY,CAAA,SAAiB,EAAE,YAAqB,EAAA;AAChD,QAAA,KAAK,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;QAE/B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,cAAc,CAAC,SAAS,CAAC,CAAC;AACtD,QAAA,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;KAChC;AAED,IAAA,OAAO,iCAAiC,GAAA;AACpC,QAAA,OAAO,IAAI,cAAc,CACrB,qBAAqB,CAAC,sBAAsB,CAAC,IAAI,EACjD,qBAAqB,CAAC,sBAAsB,CAAC,IAAI,CACpD,CAAC;KACL;AAED,IAAA,OAAO,wCAAwC,GAAA;AAC3C,QAAA,OAAO,IAAI,cAAc,CACrB,qBAAqB,CAAC,6BAA6B,CAAC,IAAI,EACxD,qBAAqB,CAAC,6BAA6B,CAAC,IAAI,CAC3D,CAAC;KACL;AACJ;;;;"}
@@ -0,0 +1,43 @@
1
+ /*! @azure/msal-react v2.0.0-alpha.1 2023-05-08 */
2
+ 'use strict';
3
+ import { useState, useEffect } from 'react';
4
+ import { AccountEntity } from '@azure/msal-browser';
5
+ import { useMsal } from './useMsal.js';
6
+ import { getAccountByIdentifiers } from '../utils/utilities.js';
7
+
8
+ /*
9
+ * Copyright (c) Microsoft Corporation. All rights reserved.
10
+ * Licensed under the MIT License.
11
+ */
12
+ function getAccount(instance, accountIdentifiers) {
13
+ if (!accountIdentifiers ||
14
+ (!accountIdentifiers.homeAccountId &&
15
+ !accountIdentifiers.localAccountId &&
16
+ !accountIdentifiers.username)) {
17
+ // If no account identifiers are provided, return active account
18
+ return instance.getActiveAccount();
19
+ }
20
+ return getAccountByIdentifiers(instance.getAllAccounts(), accountIdentifiers);
21
+ }
22
+ /**
23
+ * Given 1 or more accountIdentifiers, returns the Account object if the user is signed-in
24
+ * @param accountIdentifiers
25
+ */
26
+ function useAccount(accountIdentifiers) {
27
+ const { instance, inProgress, logger } = useMsal();
28
+ const [account, setAccount] = useState(() => getAccount(instance, accountIdentifiers));
29
+ useEffect(() => {
30
+ setAccount((currentAccount) => {
31
+ const nextAccount = getAccount(instance, accountIdentifiers);
32
+ if (!AccountEntity.accountInfoIsEqual(currentAccount, nextAccount, true)) {
33
+ logger.info("useAccount - Updating account");
34
+ return nextAccount;
35
+ }
36
+ return currentAccount;
37
+ });
38
+ }, [inProgress, accountIdentifiers, instance, logger]);
39
+ return account;
40
+ }
41
+
42
+ export { useAccount };
43
+ //# sourceMappingURL=useAccount.js.map
@@ -0,0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+1,40 @@
1
+ /*! @azure/msal-react v2.0.0-alpha.1 2023-05-08 */
2
+ 'use strict';
3
+ import { useState, useEffect } from 'react';
4
+ import { useMsal } from './useMsal.js';
5
+ import { InteractionStatus } from '@azure/msal-browser';
6
+ import { getAccountByIdentifiers } from '../utils/utilities.js';
7
+
8
+ /*
9
+ * Copyright (c) Microsoft Corporation. All rights reserved.
10
+ * Licensed under the MIT License.
11
+ */
12
+ function isAuthenticated(allAccounts, matchAccount) {
13
+ if (matchAccount &&
14
+ (matchAccount.username ||
15
+ matchAccount.homeAccountId ||
16
+ matchAccount.localAccountId)) {
17
+ return !!getAccountByIdentifiers(allAccounts, matchAccount);
18
+ }
19
+ return allAccounts.length > 0;
20
+ }
21
+ /**
22
+ * 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
23
+ * @param matchAccount
24
+ */
25
+ function useIsAuthenticated(matchAccount) {
26
+ const { accounts: allAccounts, inProgress } = useMsal();
27
+ const [hasAuthenticated, setHasAuthenticated] = useState(() => {
28
+ if (inProgress === InteractionStatus.Startup) {
29
+ return false;
30
+ }
31
+ return isAuthenticated(allAccounts, matchAccount);
32
+ });
33
+ useEffect(() => {
34
+ setHasAuthenticated(isAuthenticated(allAccounts, matchAccount));
35
+ }, [allAccounts, matchAccount]);
36
+ return hasAuthenticated;
37
+ }
38
+
39
+ export { useIsAuthenticated };
40
+ //# sourceMappingURL=useIsAuthenticated.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useIsAuthenticated.js","sources":["../../src/hooks/useIsAuthenticated.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;AAAA;;;AAGG;AAQH,SAAS,eAAe,CACpB,WAA0B,EAC1B,YAAiC,EAAA;AAEjC,IAAA,IACI,YAAY;SACX,YAAY,CAAC,QAAQ;AAClB,YAAA,YAAY,CAAC,aAAa;YAC1B,YAAY,CAAC,cAAc,CAAC,EAClC;QACE,OAAO,CAAC,CAAC,uBAAuB,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;AAC/D,KAAA;AAED,IAAA,OAAO,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC;AAClC,CAAC;AAED;;;AAGG;AACG,SAAU,kBAAkB,CAAC,YAAiC,EAAA;IAChE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,OAAO,EAAE,CAAC;IAExD,MAAM,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,GAAG,QAAQ,CAAU,MAAK;AACnE,QAAA,IAAI,UAAU,KAAK,iBAAiB,CAAC,OAAO,EAAE;AAC1C,YAAA,OAAO,KAAK,CAAC;AAChB,SAAA;AACD,QAAA,OAAO,eAAe,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;AACtD,KAAC,CAAC,CAAC;IAEH,SAAS,CAAC,MAAK;QACX,mBAAmB,CAAC,eAAe,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC,CAAC;AACpE,KAAC,EAAE,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC,CAAC;AAEhC,IAAA,OAAO,gBAAgB,CAAC;AAC5B;;;;"}
@@ -0,0 +1,16 @@
1
+ /*! @azure/msal-react v2.0.0-alpha.1 2023-05-08 */
2
+ 'use strict';
3
+ import { useContext } from 'react';
4
+ import { MsalContext } from '../MsalContext.js';
5
+
6
+ /*
7
+ * Copyright (c) Microsoft Corporation. All rights reserved.
8
+ * Licensed under the MIT License.
9
+ */
10
+ /**
11
+ * Returns Msal Context values
12
+ */
13
+ const useMsal = () => useContext(MsalContext);
14
+
15
+ export { useMsal };
16
+ //# sourceMappingURL=useMsal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useMsal.js","sources":["../../src/hooks/useMsal.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAAA;;;AAGG;AAKH;;AAEG;AACU,MAAA,OAAO,GAAG,MAAoB,UAAU,CAAC,WAAW;;;;"}
@@ -1,6 +1,6 @@
1
1
  import { PopupRequest, RedirectRequest, SsoSilentRequest, InteractionType, AuthenticationResult, AuthError, SilentRequest } from "@azure/msal-browser";
2
2
  import { AccountIdentifiers } from "../types/AccountIdentifiers";
3
- export declare type MsalAuthenticationResult = {
3
+ export type MsalAuthenticationResult = {
4
4
  login: (callbackInteractionType?: InteractionType | undefined, callbackRequest?: PopupRequest | RedirectRequest | SilentRequest) => Promise<AuthenticationResult | null>;
5
5
  acquireToken: (callbackInteractionType?: InteractionType | undefined, callbackRequest?: SilentRequest | undefined) => Promise<AuthenticationResult | null>;
6
6
  result: AuthenticationResult | null;
@@ -0,0 +1,196 @@
1
+ /*! @azure/msal-react v2.0.0-alpha.1 2023-05-08 */
2
+ 'use strict';
3
+ import { useState, useRef, useEffect, useCallback } from 'react';
4
+ import { InteractionStatus, InteractionType, EventType, OIDC_DEFAULT_SCOPES, InteractionRequiredAuthError } from '@azure/msal-browser';
5
+ import { useIsAuthenticated } from './useIsAuthenticated.js';
6
+ import { useMsal } from './useMsal.js';
7
+ import { useAccount } from './useAccount.js';
8
+ import { ReactAuthError } from '../error/ReactAuthError.js';
9
+
10
+ /*
11
+ * Copyright (c) Microsoft Corporation. All rights reserved.
12
+ * Licensed under the MIT License.
13
+ */
14
+ /**
15
+ * If a user is not currently signed in this hook invokes a login. Failed logins can be retried using the login callback returned.
16
+ * If a user is currently signed in this hook attempts to acquire a token. Subsequent token requests can use the acquireToken callback returned.
17
+ * Optionally provide a request object to be used in the login/acquireToken call.
18
+ * Optionally provide a specific user that should be logged in.
19
+ * @param interactionType
20
+ * @param authenticationRequest
21
+ * @param accountIdentifiers
22
+ */
23
+ function useMsalAuthentication(interactionType, authenticationRequest, accountIdentifiers) {
24
+ const { instance, inProgress, logger } = useMsal();
25
+ const isAuthenticated = useIsAuthenticated(accountIdentifiers);
26
+ const account = useAccount(accountIdentifiers);
27
+ const [[result, error], setResponse] = useState([null, null]);
28
+ // Used to prevent state updates after unmount
29
+ const mounted = useRef(true);
30
+ useEffect(() => {
31
+ return () => {
32
+ mounted.current = false;
33
+ };
34
+ }, []);
35
+ // 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
36
+ const interactionInProgress = useRef(inProgress !== InteractionStatus.None);
37
+ useEffect(() => {
38
+ interactionInProgress.current = inProgress !== InteractionStatus.None;
39
+ }, [inProgress]);
40
+ // Flag used to control when the hook calls login/acquireToken
41
+ const shouldAcquireToken = useRef(true);
42
+ useEffect(() => {
43
+ if (!!error) {
44
+ // Errors should be handled by consuming component
45
+ shouldAcquireToken.current = false;
46
+ return;
47
+ }
48
+ if (!!result) {
49
+ // Token has already been acquired, consuming component/application is responsible for renewing
50
+ shouldAcquireToken.current = false;
51
+ return;
52
+ }
53
+ }, [error, result]);
54
+ const login = useCallback(async (callbackInteractionType, callbackRequest) => {
55
+ const loginType = callbackInteractionType || interactionType;
56
+ const loginRequest = callbackRequest || authenticationRequest;
57
+ switch (loginType) {
58
+ case InteractionType.Popup:
59
+ logger.verbose("useMsalAuthentication - Calling loginPopup");
60
+ return instance.loginPopup(loginRequest);
61
+ case InteractionType.Redirect:
62
+ // This promise is not expected to resolve due to full frame redirect
63
+ logger.verbose("useMsalAuthentication - Calling loginRedirect");
64
+ return instance
65
+ .loginRedirect(loginRequest)
66
+ .then(null);
67
+ case InteractionType.Silent:
68
+ logger.verbose("useMsalAuthentication - Calling ssoSilent");
69
+ return instance.ssoSilent(loginRequest);
70
+ default:
71
+ throw ReactAuthError.createInvalidInteractionTypeError();
72
+ }
73
+ }, [instance, interactionType, authenticationRequest, logger]);
74
+ const acquireToken = useCallback(async (callbackInteractionType, callbackRequest) => {
75
+ const fallbackInteractionType = callbackInteractionType || interactionType;
76
+ let tokenRequest;
77
+ if (callbackRequest) {
78
+ logger.trace("useMsalAuthentication - acquireToken - Using request provided in the callback");
79
+ tokenRequest = {
80
+ ...callbackRequest,
81
+ };
82
+ }
83
+ else if (authenticationRequest) {
84
+ logger.trace("useMsalAuthentication - acquireToken - Using request provided in the hook");
85
+ tokenRequest = {
86
+ ...authenticationRequest,
87
+ scopes: authenticationRequest.scopes || OIDC_DEFAULT_SCOPES,
88
+ };
89
+ }
90
+ else {
91
+ logger.trace("useMsalAuthentication - acquireToken - No request object provided, using default request.");
92
+ tokenRequest = {
93
+ scopes: OIDC_DEFAULT_SCOPES,
94
+ };
95
+ }
96
+ if (!tokenRequest.account && account) {
97
+ logger.trace("useMsalAuthentication - acquireToken - Attaching account to request");
98
+ tokenRequest.account = account;
99
+ }
100
+ const getToken = async () => {
101
+ logger.verbose("useMsalAuthentication - Calling acquireTokenSilent");
102
+ return instance
103
+ .acquireTokenSilent(tokenRequest)
104
+ .catch(async (e) => {
105
+ if (e instanceof InteractionRequiredAuthError) {
106
+ if (!interactionInProgress.current) {
107
+ logger.error("useMsalAuthentication - Interaction required, falling back to interaction");
108
+ return login(fallbackInteractionType, tokenRequest);
109
+ }
110
+ else {
111
+ logger.error("useMsalAuthentication - Interaction required but is already in progress. Please try again, if needed, after interaction completes.");
112
+ throw ReactAuthError.createUnableToFallbackToInteractionError();
113
+ }
114
+ }
115
+ throw e;
116
+ });
117
+ };
118
+ return getToken()
119
+ .then((response) => {
120
+ if (mounted.current) {
121
+ setResponse([response, null]);
122
+ }
123
+ return response;
124
+ })
125
+ .catch((e) => {
126
+ if (mounted.current) {
127
+ setResponse([null, e]);
128
+ }
129
+ throw e;
130
+ });
131
+ }, [
132
+ instance,
133
+ interactionType,
134
+ authenticationRequest,
135
+ logger,
136
+ account,
137
+ login,
138
+ ]);
139
+ useEffect(() => {
140
+ const callbackId = instance.addEventCallback((message) => {
141
+ switch (message.eventType) {
142
+ case EventType.LOGIN_SUCCESS:
143
+ case EventType.SSO_SILENT_SUCCESS:
144
+ if (message.payload) {
145
+ setResponse([
146
+ message.payload,
147
+ null,
148
+ ]);
149
+ }
150
+ break;
151
+ case EventType.LOGIN_FAILURE:
152
+ case EventType.SSO_SILENT_FAILURE:
153
+ if (message.error) {
154
+ setResponse([null, message.error]);
155
+ }
156
+ break;
157
+ }
158
+ });
159
+ logger.verbose(`useMsalAuthentication - Registered event callback with id: ${callbackId}`);
160
+ return () => {
161
+ if (callbackId) {
162
+ logger.verbose(`useMsalAuthentication - Removing event callback ${callbackId}`);
163
+ instance.removeEventCallback(callbackId);
164
+ }
165
+ };
166
+ }, [instance, logger]);
167
+ useEffect(() => {
168
+ if (shouldAcquireToken.current &&
169
+ inProgress === InteractionStatus.None) {
170
+ shouldAcquireToken.current = false;
171
+ if (!isAuthenticated) {
172
+ logger.info("useMsalAuthentication - No user is authenticated, attempting to login");
173
+ login().catch(() => {
174
+ // Errors are saved in state above
175
+ return;
176
+ });
177
+ }
178
+ else if (account) {
179
+ logger.info("useMsalAuthentication - User is authenticated, attempting to acquire token");
180
+ acquireToken().catch(() => {
181
+ // Errors are saved in state above
182
+ return;
183
+ });
184
+ }
185
+ }
186
+ }, [isAuthenticated, account, inProgress, login, acquireToken, logger]);
187
+ return {
188
+ login,
189
+ acquireToken,
190
+ result,
191
+ error,
192
+ };
193
+ }
194
+
195
+ export { useMsalAuthentication };
196
+ //# sourceMappingURL=useMsalAuthentication.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useMsalAuthentication.js","sources":["../../src/hooks/useMsalAuthentication.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;AAAA;;;AAGG;AAoCH;;;;;;;;AAQG;SACa,qBAAqB,CACjC,eAAgC,EAChC,qBAAyE,EACzE,kBAAuC,EAAA;IAEvC,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,CAAC;AACnD,IAAA,MAAM,eAAe,GAAG,kBAAkB,CAAC,kBAAkB,CAAC,CAAC;AAC/D,IAAA,MAAM,OAAO,GAAG,UAAU,CAAC,kBAAkB,CAAC,CAAC;AAC/C,IAAA,MAAM,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,WAAW,CAAC,GAAG,QAAQ,CAE7C,CA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C1E,CAAC;AACF,gBAAA,KAAK,EAAE,CAAC,KAAK,CAAC,MAAK;;oBAEf,OAAO;AACX,iBAAC,CAAC,CAAC;AACN,aAAA;AAAM,iBAAA,IAAI,OAAO,EAAE;AAChB,gBAAA,MAAM,CAAC,IAAI,CACP,4EAA4E,CAC/E,CAAC;AACF,gBAAA,YAAY,EAAE,CAAC,KAAK,CAAC,MAAK;;oBAEtB,OAAO;AACX,iBAAC,CAAC,CAAC;AACN,aAAA;AACJ,SAAA;AACL,KAAC,EAAE,CAAC,eAAe,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC;IAExE,OAAO;QACH,KAAK;QACL,YAAY;QACZ,MAAM;QACN,KAAK;KACR,CAAC;AACN;;;;"}
package/dist/index.js CHANGED
@@ -1,8 +1,14 @@
1
-
2
- 'use strict'
3
-
4
- if (process.env.NODE_ENV === 'production') {
5
- module.exports = require('./msal-react.cjs.production.min.js')
6
- } else {
7
- module.exports = require('./msal-react.cjs.development.js')
8
- }
1
+ /*! @azure/msal-react v2.0.0-alpha.1 2023-05-08 */
2
+ 'use strict';
3
+ export { MsalConsumer, MsalContext } from './MsalContext.js';
4
+ export { MsalProvider } from './MsalProvider.js';
5
+ export { AuthenticatedTemplate } from './components/AuthenticatedTemplate.js';
6
+ export { UnauthenticatedTemplate } from './components/UnauthenticatedTemplate.js';
7
+ export { MsalAuthenticationTemplate } from './components/MsalAuthenticationTemplate.js';
8
+ export { withMsal } from './components/withMsal.js';
9
+ export { useMsal } from './hooks/useMsal.js';
10
+ export { useAccount } from './hooks/useAccount.js';
11
+ export { useIsAuthenticated } from './hooks/useIsAuthenticated.js';
12
+ export { useMsalAuthentication } from './hooks/useMsalAuthentication.js';
13
+ export { version } from './packageMetadata.js';
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;"}
@@ -1,2 +1,2 @@
1
1
  export declare const name = "@azure/msal-react";
2
- export declare const version = "1.5.7";
2
+ export declare const version = "2.0.0-alpha.1";
@@ -0,0 +1,8 @@
1
+ /*! @azure/msal-react v2.0.0-alpha.1 2023-05-08 */
2
+ 'use strict';
3
+ /* eslint-disable header/header */
4
+ const name = "@azure/msal-react";
5
+ const version = "2.0.0-alpha.1";
6
+
7
+ export { name, version };
8
+ //# sourceMappingURL=packageMetadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"packageMetadata.js","sources":["../src/packageMetadata.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAAA;AACO,MAAM,IAAI,GAAG,oBAAoB;AACjC,MAAM,OAAO,GAAG;;;;"}
@@ -1,2 +1,2 @@
1
1
  import { AccountInfo } from "@azure/msal-browser";
2
- export declare type AccountIdentifiers = Partial<Pick<AccountInfo, "homeAccountId" | "localAccountId" | "username">>;
2
+ export type AccountIdentifiers = Partial<Pick<AccountInfo, "homeAccountId" | "localAccountId" | "username">>;
@@ -1,11 +1,11 @@
1
1
  /// <reference types="react" />
2
2
  import { AccountIdentifiers } from "../types/AccountIdentifiers";
3
3
  import { AccountInfo } from "@azure/msal-browser";
4
- declare type FaaCFunction = <T>(args: T) => React.ReactNode;
4
+ type FaaCFunction = <T>(args: T) => React.ReactNode;
5
5
  export declare function getChildrenOrFunction<T>(children: React.ReactNode | FaaCFunction, args: T): React.ReactNode;
6
- declare type SetDifference<A, B> = A extends B ? never : A;
7
- declare type SetComplement<A, A1 extends A> = SetDifference<A, A1>;
8
- export declare type Subtract<T extends T1, T1 extends object> = Pick<T, SetComplement<keyof T, keyof T1>>;
6
+ type SetDifference<A, B> = A extends B ? never : A;
7
+ type SetComplement<A, A1 extends A> = SetDifference<A, A1>;
8
+ export type Subtract<T extends T1, T1 extends object> = Pick<T, SetComplement<keyof T, keyof T1>>;
9
9
  /**
10
10
  * Helper function to determine whether 2 arrays are equal
11
11
  * Used to avoid unnecessary state updates
@@ -0,0 +1,65 @@
1
+ /*! @azure/msal-react v2.0.0-alpha.1 2023-05-08 */
2
+ 'use strict';
3
+ /*
4
+ * Copyright (c) Microsoft Corporation. All rights reserved.
5
+ * Licensed under the MIT License.
6
+ */
7
+ function getChildrenOrFunction(children, args) {
8
+ if (typeof children === "function") {
9
+ return children(args);
10
+ }
11
+ return children;
12
+ }
13
+ /**
14
+ * Helper function to determine whether 2 arrays are equal
15
+ * Used to avoid unnecessary state updates
16
+ * @param arrayA
17
+ * @param arrayB
18
+ */
19
+ function accountArraysAreEqual(arrayA, arrayB) {
20
+ if (arrayA.length !== arrayB.length) {
21
+ return false;
22
+ }
23
+ const comparisonArray = [...arrayB];
24
+ return arrayA.every((elementA) => {
25
+ const elementB = comparisonArray.shift();
26
+ if (!elementA || !elementB) {
27
+ return false;
28
+ }
29
+ return (elementA.homeAccountId === elementB.homeAccountId &&
30
+ elementA.localAccountId === elementB.localAccountId &&
31
+ elementA.username === elementB.username);
32
+ });
33
+ }
34
+ function getAccountByIdentifiers(allAccounts, accountIdentifiers) {
35
+ if (allAccounts.length > 0 &&
36
+ (accountIdentifiers.homeAccountId ||
37
+ accountIdentifiers.localAccountId ||
38
+ accountIdentifiers.username)) {
39
+ const matchedAccounts = allAccounts.filter((accountObj) => {
40
+ if (accountIdentifiers.username &&
41
+ accountIdentifiers.username.toLowerCase() !==
42
+ accountObj.username.toLowerCase()) {
43
+ return false;
44
+ }
45
+ if (accountIdentifiers.homeAccountId &&
46
+ accountIdentifiers.homeAccountId.toLowerCase() !==
47
+ accountObj.homeAccountId.toLowerCase()) {
48
+ return false;
49
+ }
50
+ if (accountIdentifiers.localAccountId &&
51
+ accountIdentifiers.localAccountId.toLowerCase() !==
52
+ accountObj.localAccountId.toLowerCase()) {
53
+ return false;
54
+ }
55
+ return true;
56
+ });
57
+ return matchedAccounts[0] || null;
58
+ }
59
+ else {
60
+ return null;
61
+ }
62
+ }
63
+
64
+ export { accountArraysAreEqual, getAccountByIdentifiers, getChildrenOrFunction };
65
+ //# sourceMappingURL=utilities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utilities.js","sources":["../../src/utils/utilities.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAAA;;;AAGG;AAOa,SAAA,qBAAqB,CACjC,QAAwC,EACxC,IAAO,EAAA;AAEP,IAAA,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;AAChC,QAAA,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;AACzB,KAAA;AACD,IAAA,OAAO,QAAQ,CAAC;AACpB,CAAC;AAaD;;;;;AAKG;AACa,SAAA,qBAAqB,CACjC,MAAiC,EACjC,MAAiC,EAAA;AAEjC,IAAA,IAAI,MAAM,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,EAAE;AACjC,QAAA,OAAO,KAAK,CAAC;AAChB,KAAA;AAED,IAAA,MAAM,eAAe,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC;AAEpC,IAAA,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,QAAQ,KAAI;AAC7B,QAAA,MAAM,QAAQ,GAAG,eAAe,CAAC,KAAK,EAAE,CAAC;AACzC,QAAA,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ,EAAE;AACxB,YAAA,OAAO,KAAK,CAAC;AAChB,SAAA;AAED,QAAA,QACI,QAAQ,CAAC,aAAa,KAAK,QAAQ,CAAC,aAAa;AACjD,YAAA,QAAQ,CAAC,cAAc,KAAK,QAAQ,CAAC,cAAc;AACnD,YAAA,QAAQ,CAAC,QAAQ,KAAK,QAAQ,CAAC,QAAQ,EACzC;AACN,KAAC,CAAC,CAAC;AACP,CAAC;AAEe,SAAA,uBAAuB,CACnC,WAA0B,EAC1B,kBAAsC,EAAA;AAEtC,IAAA,IACI,WAAW,CAAC,MAAM,GAAG,CAAC;SACrB,kBAAkB,CAAC,aAAa;AAC7B,YAAA,kBAAkB,CAAC,cAAc;YACjC,kBAAkB,CAAC,QAAQ,CAAC,EAClC;QACE,MAAM,eAAe,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,UAAU,KAAI;YACtD,IACI,kBAAkB,CAAC,QAAQ;AAC3B,gBAAA,kBAAkB,CAAC,QAAQ,CAAC,WAAW,EAAE;AACrC,oBAAA,UAAU,CAAC,QAAQ,CAAC,WAAW,EAAE,EACvC;AACE,gBAAA,OAAO,KAAK,CAAC;AAChB,aAAA;YACD,IACI,kBAAkB,CAAC,aAAa;AAChC,gBAAA,kBAAkB,CAAC,aAAa,CAAC,WAAW,EAAE;AAC1C,oBAAA,UAAU,CAAC,aAAa,CAAC,WAAW,EAAE,EAC5C;AACE,gBAAA,OAAO,KAAK,CAAC;AAChB,aAAA;YACD,IACI,kBAAkB,CAAC,cAAc;AACjC,gBAAA,kBAAkB,CAAC,cAAc,CAAC,WAAW,EAAE;AAC3C,oBAAA,UAAU,CAAC,cAAc,CAAC,WAAW,EAAE,EAC7C;AACE,gBAAA,OAAO,KAAK,CAAC;AAChB,aAAA;AAED,YAAA,OAAO,IAAI,CAAC;AAChB,SAAC,CAAC,CAAC;AAEH,QAAA,OAAO,eAAe,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;AACrC,KAAA;AAAM,SAAA;AACH,QAAA,OAAO,IAAI,CAAC;AACf,KAAA;AACL;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azure/msal-react",
3
- "version": "1.5.7",
3
+ "version": "2.0.0-alpha.1",
4
4
  "author": {
5
5
  "name": "Microsoft",
6
6
  "email": "nugetaad@microsoft.com",
@@ -21,44 +21,45 @@
21
21
  "node": ">=10"
22
22
  },
23
23
  "beachball": {
24
- "disallowedChangeTypes": [
25
- "major"
26
- ]
24
+ "disallowedChangeTypes": []
27
25
  },
28
26
  "scripts": {
29
- "start": "tsdx watch",
30
- "build": "tsdx build --tsconfig ./tsconfig.build.json",
31
- "build:modules:watch": "tsdx watch --verbose --tsconfig ./tsconfig.build.json",
32
- "test": "tsdx test .*MsalAuthenticationTemplate.spec.*",
33
- "test:watch": "tsdx test .*.spec.* --watch",
34
- "test:coverage": "tsdx test .*.spec.* --coverage",
27
+ "build": "rollup -c --strictDeprecations --bundleConfigAsCjs",
28
+ "build:modules:watch": "rollup -cw --bundleConfigAsCjs",
29
+ "test": "jest",
30
+ "test:coverage": "jest --coverage",
35
31
  "lint": "cd ../../ && npm run lint:react",
36
32
  "lint:fix": "npm run lint -- -- --fix",
37
33
  "build:all": "npm run build:common && npm run build:browser && npm run build",
38
34
  "build:browser": "cd ../msal-browser && npm run build",
39
35
  "build:common": "cd ../msal-common && npm run build",
40
36
  "link:localDeps": "npx lerna bootstrap --scope @azure/msal-common --scope @azure/msal-browser --scope @azure/msal-react",
41
- "prepack": "npm run build:all"
37
+ "prepack": "npm run build:all",
38
+ "format:check": "npx prettier --ignore-path .gitignore --check src test",
39
+ "format:fix": "npx prettier --ignore-path .gitignore --write src test"
42
40
  },
43
41
  "peerDependencies": {
44
- "@azure/msal-browser": "^2.36.0",
42
+ "@azure/msal-browser": "^3.0.0-alpha.1",
45
43
  "react": "^16.8.0 || ^17 || ^18"
46
44
  },
47
45
  "module": "dist/msal-react.esm.js",
48
46
  "devDependencies": {
49
- "@azure/msal-browser": "^2.37.0",
47
+ "@azure/msal-browser": "^3.0.0-alpha.1",
50
48
  "@testing-library/jest-dom": "^5.11.5",
51
49
  "@testing-library/react": "^13.4.0",
52
50
  "@types/jest": "^27.0.0",
53
51
  "@types/react": "^17.0.2",
54
52
  "@types/react-dom": "^17.0.2",
55
53
  "jest": "^27.0.4",
56
- "jest-environment-jsdom-fifteen": "^1.0.2",
54
+ "prettier": "2.8.7",
57
55
  "react": "^18.2.0",
58
56
  "react-dom": "^18.2.0",
59
57
  "ts-jest": "^27.0.2",
60
- "tsdx": "^0.14.1",
61
58
  "tslib": "^2.0.0",
62
- "typescript": "^3.9.7"
59
+ "typescript": "^4.9.5"
60
+ },
61
+ "dependencies": {
62
+ "@rollup/plugin-typescript": "^11.1.0",
63
+ "rollup": "^3.20.2"
63
64
  }
64
65
  }