@azure/msal-react 2.0.21 → 2.1.0

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 (60) hide show
  1. package/dist/MsalContext.d.ts +10 -10
  2. package/dist/MsalContext.js +16 -16
  3. package/dist/MsalProvider.d.ts +9 -9
  4. package/dist/MsalProvider.js +136 -136
  5. package/dist/components/AuthenticatedTemplate.d.ts +8 -8
  6. package/dist/components/AuthenticatedTemplate.js +23 -23
  7. package/dist/components/MsalAuthenticationTemplate.d.ts +16 -16
  8. package/dist/components/MsalAuthenticationTemplate.js +33 -33
  9. package/dist/components/UnauthenticatedTemplate.d.ts +8 -8
  10. package/dist/components/UnauthenticatedTemplate.js +25 -25
  11. package/dist/components/withMsal.d.ts +11 -11
  12. package/dist/components/withMsal.js +17 -17
  13. package/dist/error/ReactAuthError.d.ts +16 -16
  14. package/dist/error/ReactAuthError.js +27 -27
  15. package/dist/hooks/useAccount.d.ts +7 -7
  16. package/dist/hooks/useAccount.js +33 -33
  17. package/dist/hooks/useIsAuthenticated.d.ts +6 -6
  18. package/dist/hooks/useIsAuthenticated.js +27 -27
  19. package/dist/hooks/useMsal.d.ts +5 -5
  20. package/dist/hooks/useMsal.js +8 -8
  21. package/dist/hooks/useMsalAuthentication.d.ts +18 -18
  22. package/dist/hooks/useMsalAuthentication.js +184 -184
  23. package/dist/index.d.ts +24 -24
  24. package/dist/index.js +1 -1
  25. package/dist/packageMetadata.d.ts +2 -2
  26. package/dist/packageMetadata.js +4 -4
  27. package/dist/types/AccountIdentifiers.d.ts +2 -2
  28. package/dist/utils/utilities.d.ts +17 -17
  29. package/dist/utils/utilities.js +60 -60
  30. package/lib/msal-react.cjs +644 -0
  31. package/lib/msal-react.cjs.map +1 -0
  32. package/lib/package.json +1 -0
  33. package/lib/types/MsalContext.d.ts +10 -0
  34. package/lib/types/MsalProvider.d.ts +9 -0
  35. package/lib/types/components/AuthenticatedTemplate.d.ts +8 -0
  36. package/lib/types/components/MsalAuthenticationTemplate.d.ts +16 -0
  37. package/lib/types/components/UnauthenticatedTemplate.d.ts +8 -0
  38. package/lib/types/components/withMsal.d.ts +11 -0
  39. package/lib/types/error/ReactAuthError.d.ts +16 -0
  40. package/lib/types/hooks/useAccount.d.ts +7 -0
  41. package/lib/types/hooks/useIsAuthenticated.d.ts +6 -0
  42. package/lib/types/hooks/useMsal.d.ts +5 -0
  43. package/lib/types/hooks/useMsalAuthentication.d.ts +18 -0
  44. package/lib/types/index.d.ts +24 -0
  45. package/lib/types/packageMetadata.d.ts +2 -0
  46. package/lib/types/types/AccountIdentifiers.d.ts +2 -0
  47. package/lib/types/utils/utilities.d.ts +17 -0
  48. package/package.json +14 -5
  49. package/src/MsalProvider.tsx +3 -3
  50. package/src/components/AuthenticatedTemplate.tsx +4 -4
  51. package/src/components/MsalAuthenticationTemplate.tsx +6 -6
  52. package/src/components/UnauthenticatedTemplate.tsx +4 -4
  53. package/src/components/withMsal.tsx +3 -3
  54. package/src/hooks/useAccount.ts +3 -3
  55. package/src/hooks/useIsAuthenticated.ts +3 -3
  56. package/src/hooks/useMsal.ts +1 -1
  57. package/src/hooks/useMsalAuthentication.ts +5 -5
  58. package/src/index.ts +20 -20
  59. package/src/packageMetadata.ts +1 -1
  60. package/src/utils/utilities.ts +1 -1
@@ -1,24 +1,24 @@
1
- /*! @azure/msal-react v2.0.21 2024-07-16 */
1
+ /*! @azure/msal-react v2.1.0 2024-09-20 */
2
2
  'use strict';
3
3
  import React__default from 'react';
4
4
  import { useMsal } from '../hooks/useMsal.js';
5
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;
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
22
  };
23
23
 
24
24
  export { withMsal };
@@ -1,16 +1,16 @@
1
- import { AuthError } from "@azure/msal-browser";
2
- export declare const ReactAuthErrorMessage: {
3
- invalidInteractionType: {
4
- code: string;
5
- desc: string;
6
- };
7
- unableToFallbackToInteraction: {
8
- code: string;
9
- desc: string;
10
- };
11
- };
12
- export declare class ReactAuthError extends AuthError {
13
- constructor(errorCode: string, errorMessage?: string);
14
- static createInvalidInteractionTypeError(): ReactAuthError;
15
- static createUnableToFallbackToInteractionError(): ReactAuthError;
16
- }
1
+ import { AuthError } from "@azure/msal-browser";
2
+ export declare const ReactAuthErrorMessage: {
3
+ invalidInteractionType: {
4
+ code: string;
5
+ desc: string;
6
+ };
7
+ unableToFallbackToInteraction: {
8
+ code: string;
9
+ desc: string;
10
+ };
11
+ };
12
+ export declare class ReactAuthError extends AuthError {
13
+ constructor(errorCode: string, errorMessage?: string);
14
+ static createInvalidInteractionTypeError(): ReactAuthError;
15
+ static createUnableToFallbackToInteractionError(): ReactAuthError;
16
+ }
@@ -1,33 +1,33 @@
1
- /*! @azure/msal-react v2.0.21 2024-07-16 */
1
+ /*! @azure/msal-react v2.1.0 2024-09-20 */
2
2
  'use strict';
3
3
  import { AuthError } from '@azure/msal-browser';
4
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
- }
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
31
  }
32
32
 
33
33
  export { ReactAuthError, ReactAuthErrorMessage };
@@ -1,7 +1,7 @@
1
- import { AccountInfo } from "@azure/msal-browser";
2
- import { AccountIdentifiers } from "../types/AccountIdentifiers";
3
- /**
4
- * Given 1 or more accountIdentifiers, returns the Account object if the user is signed-in
5
- * @param accountIdentifiers
6
- */
7
- export declare function useAccount(accountIdentifiers?: AccountIdentifiers): AccountInfo | null;
1
+ import { AccountInfo } from "@azure/msal-browser";
2
+ import { AccountIdentifiers } from "../types/AccountIdentifiers.js";
3
+ /**
4
+ * Given 1 or more accountIdentifiers, returns the Account object if the user is signed-in
5
+ * @param accountIdentifiers
6
+ */
7
+ export declare function useAccount(accountIdentifiers?: AccountIdentifiers): AccountInfo | null;
@@ -1,42 +1,42 @@
1
- /*! @azure/msal-react v2.0.21 2024-07-16 */
1
+ /*! @azure/msal-react v2.1.0 2024-09-20 */
2
2
  'use strict';
3
3
  import { useState, useEffect } from 'react';
4
4
  import { AccountEntity } from '@azure/msal-browser';
5
5
  import { useMsal } from './useMsal.js';
6
6
  import { getAccountByIdentifiers } from '../utils/utilities.js';
7
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;
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
40
  }
41
41
 
42
42
  export { useAccount };
@@ -1,6 +1,6 @@
1
- import { AccountIdentifiers } from "../types/AccountIdentifiers";
2
- /**
3
- * 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
4
- * @param matchAccount
5
- */
6
- export declare function useIsAuthenticated(matchAccount?: AccountIdentifiers): boolean;
1
+ import { AccountIdentifiers } from "../types/AccountIdentifiers.js";
2
+ /**
3
+ * 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
4
+ * @param matchAccount
5
+ */
6
+ export declare function useIsAuthenticated(matchAccount?: AccountIdentifiers): boolean;
@@ -1,36 +1,36 @@
1
- /*! @azure/msal-react v2.0.21 2024-07-16 */
1
+ /*! @azure/msal-react v2.1.0 2024-09-20 */
2
2
  'use strict';
3
3
  import { useMemo } from 'react';
4
4
  import { useMsal } from './useMsal.js';
5
5
  import { InteractionStatus } from '@azure/msal-browser';
6
6
  import { getAccountByIdentifiers } from '../utils/utilities.js';
7
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 isUserAuthenticated = useMemo(() => {
28
- if (inProgress === InteractionStatus.Startup) {
29
- return false;
30
- }
31
- return isAuthenticated(allAccounts, matchAccount);
32
- }, [allAccounts, inProgress, matchAccount]);
33
- return isUserAuthenticated;
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 isUserAuthenticated = useMemo(() => {
28
+ if (inProgress === InteractionStatus.Startup) {
29
+ return false;
30
+ }
31
+ return isAuthenticated(allAccounts, matchAccount);
32
+ }, [allAccounts, inProgress, matchAccount]);
33
+ return isUserAuthenticated;
34
34
  }
35
35
 
36
36
  export { useIsAuthenticated };
@@ -1,5 +1,5 @@
1
- import { IMsalContext } from "../MsalContext";
2
- /**
3
- * Returns Msal Context values
4
- */
5
- export declare const useMsal: () => IMsalContext;
1
+ import { IMsalContext } from "../MsalContext.js";
2
+ /**
3
+ * Returns Msal Context values
4
+ */
5
+ export declare const useMsal: () => IMsalContext;
@@ -1,15 +1,15 @@
1
- /*! @azure/msal-react v2.0.21 2024-07-16 */
1
+ /*! @azure/msal-react v2.1.0 2024-09-20 */
2
2
  'use strict';
3
3
  import { useContext } from 'react';
4
4
  import { MsalContext } from '../MsalContext.js';
5
5
 
6
- /*
7
- * Copyright (c) Microsoft Corporation. All rights reserved.
8
- * Licensed under the MIT License.
9
- */
10
- /**
11
- * Returns Msal Context values
12
- */
6
+ /*
7
+ * Copyright (c) Microsoft Corporation. All rights reserved.
8
+ * Licensed under the MIT License.
9
+ */
10
+ /**
11
+ * Returns Msal Context values
12
+ */
13
13
  const useMsal = () => useContext(MsalContext);
14
14
 
15
15
  export { useMsal };
@@ -1,18 +1,18 @@
1
- import { PopupRequest, RedirectRequest, SsoSilentRequest, InteractionType, AuthenticationResult, AuthError, SilentRequest } from "@azure/msal-browser";
2
- import { AccountIdentifiers } from "../types/AccountIdentifiers";
3
- export type MsalAuthenticationResult = {
4
- login: (callbackInteractionType?: InteractionType | undefined, callbackRequest?: PopupRequest | RedirectRequest | SilentRequest) => Promise<AuthenticationResult | null>;
5
- acquireToken: (callbackInteractionType?: InteractionType | undefined, callbackRequest?: SilentRequest | undefined) => Promise<AuthenticationResult | null>;
6
- result: AuthenticationResult | null;
7
- error: AuthError | null;
8
- };
9
- /**
10
- * If a user is not currently signed in this hook invokes a login. Failed logins can be retried using the login callback returned.
11
- * If a user is currently signed in this hook attempts to acquire a token. Subsequent token requests can use the acquireToken callback returned.
12
- * Optionally provide a request object to be used in the login/acquireToken call.
13
- * Optionally provide a specific user that should be logged in.
14
- * @param interactionType
15
- * @param authenticationRequest
16
- * @param accountIdentifiers
17
- */
18
- export declare function useMsalAuthentication(interactionType: InteractionType, authenticationRequest?: PopupRequest | RedirectRequest | SsoSilentRequest, accountIdentifiers?: AccountIdentifiers): MsalAuthenticationResult;
1
+ import { PopupRequest, RedirectRequest, SsoSilentRequest, InteractionType, AuthenticationResult, AuthError, SilentRequest } from "@azure/msal-browser";
2
+ import { AccountIdentifiers } from "../types/AccountIdentifiers.js";
3
+ export type MsalAuthenticationResult = {
4
+ login: (callbackInteractionType?: InteractionType | undefined, callbackRequest?: PopupRequest | RedirectRequest | SilentRequest) => Promise<AuthenticationResult | null>;
5
+ acquireToken: (callbackInteractionType?: InteractionType | undefined, callbackRequest?: SilentRequest | undefined) => Promise<AuthenticationResult | null>;
6
+ result: AuthenticationResult | null;
7
+ error: AuthError | null;
8
+ };
9
+ /**
10
+ * If a user is not currently signed in this hook invokes a login. Failed logins can be retried using the login callback returned.
11
+ * If a user is currently signed in this hook attempts to acquire a token. Subsequent token requests can use the acquireToken callback returned.
12
+ * Optionally provide a request object to be used in the login/acquireToken call.
13
+ * Optionally provide a specific user that should be logged in.
14
+ * @param interactionType
15
+ * @param authenticationRequest
16
+ * @param accountIdentifiers
17
+ */
18
+ export declare function useMsalAuthentication(interactionType: InteractionType, authenticationRequest?: PopupRequest | RedirectRequest | SsoSilentRequest, accountIdentifiers?: AccountIdentifiers): MsalAuthenticationResult;