@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.
- package/dist/MsalContext.d.ts +10 -10
- package/dist/MsalContext.js +16 -16
- package/dist/MsalProvider.d.ts +9 -9
- package/dist/MsalProvider.js +136 -136
- package/dist/components/AuthenticatedTemplate.d.ts +8 -8
- package/dist/components/AuthenticatedTemplate.js +23 -23
- package/dist/components/MsalAuthenticationTemplate.d.ts +16 -16
- package/dist/components/MsalAuthenticationTemplate.js +33 -33
- package/dist/components/UnauthenticatedTemplate.d.ts +8 -8
- package/dist/components/UnauthenticatedTemplate.js +25 -25
- package/dist/components/withMsal.d.ts +11 -11
- package/dist/components/withMsal.js +17 -17
- package/dist/error/ReactAuthError.d.ts +16 -16
- package/dist/error/ReactAuthError.js +27 -27
- package/dist/hooks/useAccount.d.ts +7 -7
- package/dist/hooks/useAccount.js +33 -33
- package/dist/hooks/useIsAuthenticated.d.ts +6 -6
- package/dist/hooks/useIsAuthenticated.js +27 -27
- package/dist/hooks/useMsal.d.ts +5 -5
- package/dist/hooks/useMsal.js +8 -8
- package/dist/hooks/useMsalAuthentication.d.ts +18 -18
- package/dist/hooks/useMsalAuthentication.js +184 -184
- package/dist/index.d.ts +24 -24
- package/dist/index.js +1 -1
- package/dist/packageMetadata.d.ts +2 -2
- package/dist/packageMetadata.js +4 -4
- package/dist/types/AccountIdentifiers.d.ts +2 -2
- package/dist/utils/utilities.d.ts +17 -17
- package/dist/utils/utilities.js +60 -60
- package/lib/msal-react.cjs +644 -0
- package/lib/msal-react.cjs.map +1 -0
- package/lib/package.json +1 -0
- package/lib/types/MsalContext.d.ts +10 -0
- package/lib/types/MsalProvider.d.ts +9 -0
- package/lib/types/components/AuthenticatedTemplate.d.ts +8 -0
- package/lib/types/components/MsalAuthenticationTemplate.d.ts +16 -0
- package/lib/types/components/UnauthenticatedTemplate.d.ts +8 -0
- package/lib/types/components/withMsal.d.ts +11 -0
- package/lib/types/error/ReactAuthError.d.ts +16 -0
- package/lib/types/hooks/useAccount.d.ts +7 -0
- package/lib/types/hooks/useIsAuthenticated.d.ts +6 -0
- package/lib/types/hooks/useMsal.d.ts +5 -0
- package/lib/types/hooks/useMsalAuthentication.d.ts +18 -0
- package/lib/types/index.d.ts +24 -0
- package/lib/types/packageMetadata.d.ts +2 -0
- package/lib/types/types/AccountIdentifiers.d.ts +2 -0
- package/lib/types/utils/utilities.d.ts +17 -0
- package/package.json +14 -5
- package/src/MsalProvider.tsx +3 -3
- package/src/components/AuthenticatedTemplate.tsx +4 -4
- package/src/components/MsalAuthenticationTemplate.tsx +6 -6
- package/src/components/UnauthenticatedTemplate.tsx +4 -4
- package/src/components/withMsal.tsx +3 -3
- package/src/hooks/useAccount.ts +3 -3
- package/src/hooks/useIsAuthenticated.ts +3 -3
- package/src/hooks/useMsal.ts +1 -1
- package/src/hooks/useMsalAuthentication.ts +5 -5
- package/src/index.ts +20 -20
- package/src/packageMetadata.ts +1 -1
- package/src/utils/utilities.ts +1 -1
package/dist/MsalContext.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { IPublicClientApplication, Logger, InteractionStatus, AccountInfo } from "@azure/msal-browser";
|
|
3
|
-
export interface IMsalContext {
|
|
4
|
-
instance: IPublicClientApplication;
|
|
5
|
-
inProgress: InteractionStatus;
|
|
6
|
-
accounts: AccountInfo[];
|
|
7
|
-
logger: Logger;
|
|
8
|
-
}
|
|
9
|
-
export declare const MsalContext: React.Context<IMsalContext>;
|
|
10
|
-
export declare const MsalConsumer: React.Consumer<IMsalContext>;
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { IPublicClientApplication, Logger, InteractionStatus, AccountInfo } from "@azure/msal-browser";
|
|
3
|
+
export interface IMsalContext {
|
|
4
|
+
instance: IPublicClientApplication;
|
|
5
|
+
inProgress: InteractionStatus;
|
|
6
|
+
accounts: AccountInfo[];
|
|
7
|
+
logger: Logger;
|
|
8
|
+
}
|
|
9
|
+
export declare const MsalContext: React.Context<IMsalContext>;
|
|
10
|
+
export declare const MsalConsumer: React.Consumer<IMsalContext>;
|
package/dist/MsalContext.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
/*! @azure/msal-react v2.0
|
|
1
|
+
/*! @azure/msal-react v2.1.0 2024-09-20 */
|
|
2
2
|
'use strict';
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { stubbedPublicClientApplication, InteractionStatus, Logger } from '@azure/msal-browser';
|
|
5
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);
|
|
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
21
|
const MsalConsumer = MsalContext.Consumer;
|
|
22
22
|
|
|
23
23
|
export { MsalConsumer, MsalContext };
|
package/dist/MsalProvider.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import React, { PropsWithChildren } from "react";
|
|
2
|
-
import { IPublicClientApplication } from "@azure/msal-browser";
|
|
3
|
-
export type MsalProviderProps = PropsWithChildren<{
|
|
4
|
-
instance: IPublicClientApplication;
|
|
5
|
-
}>;
|
|
6
|
-
/**
|
|
7
|
-
* MSAL context provider component. This must be rendered above any other components that use MSAL.
|
|
8
|
-
*/
|
|
9
|
-
export declare function MsalProvider({ instance, children, }: MsalProviderProps): React.ReactElement;
|
|
1
|
+
import React, { PropsWithChildren } from "react";
|
|
2
|
+
import { IPublicClientApplication } from "@azure/msal-browser";
|
|
3
|
+
export type MsalProviderProps = PropsWithChildren<{
|
|
4
|
+
instance: IPublicClientApplication;
|
|
5
|
+
}>;
|
|
6
|
+
/**
|
|
7
|
+
* MSAL context provider component. This must be rendered above any other components that use MSAL.
|
|
8
|
+
*/
|
|
9
|
+
export declare function MsalProvider({ instance, children, }: MsalProviderProps): React.ReactElement;
|
package/dist/MsalProvider.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @azure/msal-react v2.0
|
|
1
|
+
/*! @azure/msal-react v2.1.0 2024-09-20 */
|
|
2
2
|
'use strict';
|
|
3
3
|
import React__default, { useEffect, useMemo, useReducer } from 'react';
|
|
4
4
|
import { WrapperSKU, InteractionStatus, EventMessageUtils } from '@azure/msal-browser';
|
|
@@ -6,141 +6,141 @@ import { MsalContext } from './MsalContext.js';
|
|
|
6
6
|
import { accountArraysAreEqual } from './utils/utilities.js';
|
|
7
7
|
import { version, name } from './packageMetadata.js';
|
|
8
8
|
|
|
9
|
-
/*
|
|
10
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
11
|
-
* Licensed under the MIT License.
|
|
12
|
-
*/
|
|
13
|
-
const MsalProviderActionType = {
|
|
14
|
-
UNBLOCK_INPROGRESS: "UNBLOCK_INPROGRESS",
|
|
15
|
-
EVENT: "EVENT",
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* Returns the next inProgress and accounts state based on event message
|
|
19
|
-
* @param previousState
|
|
20
|
-
* @param action
|
|
21
|
-
*/
|
|
22
|
-
const reducer = (previousState, action) => {
|
|
23
|
-
const { type, payload } = action;
|
|
24
|
-
let newInProgress = previousState.inProgress;
|
|
25
|
-
switch (type) {
|
|
26
|
-
case MsalProviderActionType.UNBLOCK_INPROGRESS:
|
|
27
|
-
if (previousState.inProgress === InteractionStatus.Startup) {
|
|
28
|
-
newInProgress = InteractionStatus.None;
|
|
29
|
-
payload.logger.info("MsalProvider - handleRedirectPromise resolved, setting inProgress to 'none'");
|
|
30
|
-
}
|
|
31
|
-
break;
|
|
32
|
-
case MsalProviderActionType.EVENT:
|
|
33
|
-
const message = payload.message;
|
|
34
|
-
const status = EventMessageUtils.getInteractionStatusFromEvent(message, previousState.inProgress);
|
|
35
|
-
if (status) {
|
|
36
|
-
payload.logger.info(`MsalProvider - ${message.eventType} results in setting inProgress from ${previousState.inProgress} to ${status}`);
|
|
37
|
-
newInProgress = status;
|
|
38
|
-
}
|
|
39
|
-
break;
|
|
40
|
-
default:
|
|
41
|
-
throw new Error(`Unknown action type: ${type}`);
|
|
42
|
-
}
|
|
43
|
-
const currentAccounts = payload.instance.getAllAccounts();
|
|
44
|
-
if (newInProgress !== previousState.inProgress &&
|
|
45
|
-
!accountArraysAreEqual(currentAccounts, previousState.accounts)) {
|
|
46
|
-
// Both inProgress and accounts changed
|
|
47
|
-
return {
|
|
48
|
-
...previousState,
|
|
49
|
-
inProgress: newInProgress,
|
|
50
|
-
accounts: currentAccounts,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
else if (newInProgress !== previousState.inProgress) {
|
|
54
|
-
// Only only inProgress changed
|
|
55
|
-
return {
|
|
56
|
-
...previousState,
|
|
57
|
-
inProgress: newInProgress,
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
else if (!accountArraysAreEqual(currentAccounts, previousState.accounts)) {
|
|
61
|
-
// Only accounts changed
|
|
62
|
-
return {
|
|
63
|
-
...previousState,
|
|
64
|
-
accounts: currentAccounts,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
// Nothing changed
|
|
69
|
-
return previousState;
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
/**
|
|
73
|
-
* MSAL context provider component. This must be rendered above any other components that use MSAL.
|
|
74
|
-
*/
|
|
75
|
-
function MsalProvider({ instance, children, }) {
|
|
76
|
-
useEffect(() => {
|
|
77
|
-
instance.initializeWrapperLibrary(WrapperSKU.React, version);
|
|
78
|
-
}, [instance]);
|
|
79
|
-
// Create a logger instance for msal-react with the same options as PublicClientApplication
|
|
80
|
-
const logger = useMemo(() => {
|
|
81
|
-
return instance.getLogger().clone(name, version);
|
|
82
|
-
}, [instance]);
|
|
83
|
-
const [state, updateState] = useReducer(reducer, undefined, () => {
|
|
84
|
-
// Lazy initialization of the initial state
|
|
85
|
-
return {
|
|
86
|
-
inProgress: InteractionStatus.Startup,
|
|
87
|
-
accounts: instance.getAllAccounts(),
|
|
88
|
-
};
|
|
89
|
-
});
|
|
90
|
-
useEffect(() => {
|
|
91
|
-
const callbackId = instance.addEventCallback((message) => {
|
|
92
|
-
updateState({
|
|
93
|
-
payload: {
|
|
94
|
-
instance,
|
|
95
|
-
logger,
|
|
96
|
-
message,
|
|
97
|
-
},
|
|
98
|
-
type: MsalProviderActionType.EVENT,
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
logger.verbose(`MsalProvider - Registered event callback with id: ${callbackId}`);
|
|
102
|
-
instance
|
|
103
|
-
.initialize()
|
|
104
|
-
.then(() => {
|
|
105
|
-
instance
|
|
106
|
-
.handleRedirectPromise()
|
|
107
|
-
.catch(() => {
|
|
108
|
-
// Errors should be handled by listening to the LOGIN_FAILURE event
|
|
109
|
-
return;
|
|
110
|
-
})
|
|
111
|
-
.finally(() => {
|
|
112
|
-
/*
|
|
113
|
-
* If handleRedirectPromise returns a cached promise the necessary events may not be fired
|
|
114
|
-
* This is a fallback to prevent inProgress from getting stuck in 'startup'
|
|
115
|
-
*/
|
|
116
|
-
updateState({
|
|
117
|
-
payload: {
|
|
118
|
-
instance,
|
|
119
|
-
logger,
|
|
120
|
-
},
|
|
121
|
-
type: MsalProviderActionType.UNBLOCK_INPROGRESS,
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
})
|
|
125
|
-
.catch(() => {
|
|
126
|
-
// Errors should be handled by listening to the LOGIN_FAILURE event
|
|
127
|
-
return;
|
|
128
|
-
});
|
|
129
|
-
return () => {
|
|
130
|
-
// Remove callback when component unmounts or accounts change
|
|
131
|
-
if (callbackId) {
|
|
132
|
-
logger.verbose(`MsalProvider - Removing event callback ${callbackId}`);
|
|
133
|
-
instance.removeEventCallback(callbackId);
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
}, [instance, logger]);
|
|
137
|
-
const contextValue = {
|
|
138
|
-
instance,
|
|
139
|
-
inProgress: state.inProgress,
|
|
140
|
-
accounts: state.accounts,
|
|
141
|
-
logger,
|
|
142
|
-
};
|
|
143
|
-
return (React__default.createElement(MsalContext.Provider, { value: contextValue }, children));
|
|
9
|
+
/*
|
|
10
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
11
|
+
* Licensed under the MIT License.
|
|
12
|
+
*/
|
|
13
|
+
const MsalProviderActionType = {
|
|
14
|
+
UNBLOCK_INPROGRESS: "UNBLOCK_INPROGRESS",
|
|
15
|
+
EVENT: "EVENT",
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Returns the next inProgress and accounts state based on event message
|
|
19
|
+
* @param previousState
|
|
20
|
+
* @param action
|
|
21
|
+
*/
|
|
22
|
+
const reducer = (previousState, action) => {
|
|
23
|
+
const { type, payload } = action;
|
|
24
|
+
let newInProgress = previousState.inProgress;
|
|
25
|
+
switch (type) {
|
|
26
|
+
case MsalProviderActionType.UNBLOCK_INPROGRESS:
|
|
27
|
+
if (previousState.inProgress === InteractionStatus.Startup) {
|
|
28
|
+
newInProgress = InteractionStatus.None;
|
|
29
|
+
payload.logger.info("MsalProvider - handleRedirectPromise resolved, setting inProgress to 'none'");
|
|
30
|
+
}
|
|
31
|
+
break;
|
|
32
|
+
case MsalProviderActionType.EVENT:
|
|
33
|
+
const message = payload.message;
|
|
34
|
+
const status = EventMessageUtils.getInteractionStatusFromEvent(message, previousState.inProgress);
|
|
35
|
+
if (status) {
|
|
36
|
+
payload.logger.info(`MsalProvider - ${message.eventType} results in setting inProgress from ${previousState.inProgress} to ${status}`);
|
|
37
|
+
newInProgress = status;
|
|
38
|
+
}
|
|
39
|
+
break;
|
|
40
|
+
default:
|
|
41
|
+
throw new Error(`Unknown action type: ${type}`);
|
|
42
|
+
}
|
|
43
|
+
const currentAccounts = payload.instance.getAllAccounts();
|
|
44
|
+
if (newInProgress !== previousState.inProgress &&
|
|
45
|
+
!accountArraysAreEqual(currentAccounts, previousState.accounts)) {
|
|
46
|
+
// Both inProgress and accounts changed
|
|
47
|
+
return {
|
|
48
|
+
...previousState,
|
|
49
|
+
inProgress: newInProgress,
|
|
50
|
+
accounts: currentAccounts,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
else if (newInProgress !== previousState.inProgress) {
|
|
54
|
+
// Only only inProgress changed
|
|
55
|
+
return {
|
|
56
|
+
...previousState,
|
|
57
|
+
inProgress: newInProgress,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
else if (!accountArraysAreEqual(currentAccounts, previousState.accounts)) {
|
|
61
|
+
// Only accounts changed
|
|
62
|
+
return {
|
|
63
|
+
...previousState,
|
|
64
|
+
accounts: currentAccounts,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
// Nothing changed
|
|
69
|
+
return previousState;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* MSAL context provider component. This must be rendered above any other components that use MSAL.
|
|
74
|
+
*/
|
|
75
|
+
function MsalProvider({ instance, children, }) {
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
instance.initializeWrapperLibrary(WrapperSKU.React, version);
|
|
78
|
+
}, [instance]);
|
|
79
|
+
// Create a logger instance for msal-react with the same options as PublicClientApplication
|
|
80
|
+
const logger = useMemo(() => {
|
|
81
|
+
return instance.getLogger().clone(name, version);
|
|
82
|
+
}, [instance]);
|
|
83
|
+
const [state, updateState] = useReducer(reducer, undefined, () => {
|
|
84
|
+
// Lazy initialization of the initial state
|
|
85
|
+
return {
|
|
86
|
+
inProgress: InteractionStatus.Startup,
|
|
87
|
+
accounts: instance.getAllAccounts(),
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
const callbackId = instance.addEventCallback((message) => {
|
|
92
|
+
updateState({
|
|
93
|
+
payload: {
|
|
94
|
+
instance,
|
|
95
|
+
logger,
|
|
96
|
+
message,
|
|
97
|
+
},
|
|
98
|
+
type: MsalProviderActionType.EVENT,
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
logger.verbose(`MsalProvider - Registered event callback with id: ${callbackId}`);
|
|
102
|
+
instance
|
|
103
|
+
.initialize()
|
|
104
|
+
.then(() => {
|
|
105
|
+
instance
|
|
106
|
+
.handleRedirectPromise()
|
|
107
|
+
.catch(() => {
|
|
108
|
+
// Errors should be handled by listening to the LOGIN_FAILURE event
|
|
109
|
+
return;
|
|
110
|
+
})
|
|
111
|
+
.finally(() => {
|
|
112
|
+
/*
|
|
113
|
+
* If handleRedirectPromise returns a cached promise the necessary events may not be fired
|
|
114
|
+
* This is a fallback to prevent inProgress from getting stuck in 'startup'
|
|
115
|
+
*/
|
|
116
|
+
updateState({
|
|
117
|
+
payload: {
|
|
118
|
+
instance,
|
|
119
|
+
logger,
|
|
120
|
+
},
|
|
121
|
+
type: MsalProviderActionType.UNBLOCK_INPROGRESS,
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
})
|
|
125
|
+
.catch(() => {
|
|
126
|
+
// Errors should be handled by listening to the LOGIN_FAILURE event
|
|
127
|
+
return;
|
|
128
|
+
});
|
|
129
|
+
return () => {
|
|
130
|
+
// Remove callback when component unmounts or accounts change
|
|
131
|
+
if (callbackId) {
|
|
132
|
+
logger.verbose(`MsalProvider - Removing event callback ${callbackId}`);
|
|
133
|
+
instance.removeEventCallback(callbackId);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}, [instance, logger]);
|
|
137
|
+
const contextValue = {
|
|
138
|
+
instance,
|
|
139
|
+
inProgress: state.inProgress,
|
|
140
|
+
accounts: state.accounts,
|
|
141
|
+
logger,
|
|
142
|
+
};
|
|
143
|
+
return (React__default.createElement(MsalContext.Provider, { value: contextValue }, children));
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
export { MsalProvider };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React, { PropsWithChildren } from "react";
|
|
2
|
-
import { AccountIdentifiers } from "../types/AccountIdentifiers";
|
|
3
|
-
export type AuthenticatedTemplateProps = PropsWithChildren<AccountIdentifiers>;
|
|
4
|
-
/**
|
|
5
|
-
* Renders child components if user is authenticated
|
|
6
|
-
* @param props
|
|
7
|
-
*/
|
|
8
|
-
export declare function AuthenticatedTemplate({ username, homeAccountId, localAccountId, children, }: AuthenticatedTemplateProps): React.ReactElement | null;
|
|
1
|
+
import React, { PropsWithChildren } from "react";
|
|
2
|
+
import { AccountIdentifiers } from "../types/AccountIdentifiers.js";
|
|
3
|
+
export type AuthenticatedTemplateProps = PropsWithChildren<AccountIdentifiers>;
|
|
4
|
+
/**
|
|
5
|
+
* Renders child components if user is authenticated
|
|
6
|
+
* @param props
|
|
7
|
+
*/
|
|
8
|
+
export declare function AuthenticatedTemplate({ username, homeAccountId, localAccountId, children, }: AuthenticatedTemplateProps): React.ReactElement | null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @azure/msal-react v2.0
|
|
1
|
+
/*! @azure/msal-react v2.1.0 2024-09-20 */
|
|
2
2
|
'use strict';
|
|
3
3
|
import React__default, { useMemo } from 'react';
|
|
4
4
|
import { getChildrenOrFunction } from '../utils/utilities.js';
|
|
@@ -6,28 +6,28 @@ import { useMsal } from '../hooks/useMsal.js';
|
|
|
6
6
|
import { useIsAuthenticated } from '../hooks/useIsAuthenticated.js';
|
|
7
7
|
import { InteractionStatus } from '@azure/msal-browser';
|
|
8
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;
|
|
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
31
|
}
|
|
32
32
|
|
|
33
33
|
export { AuthenticatedTemplate };
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import React, { PropsWithChildren } from "react";
|
|
2
|
-
import { AccountIdentifiers } from "../types/AccountIdentifiers";
|
|
3
|
-
import { MsalAuthenticationResult } from "../hooks/useMsalAuthentication";
|
|
4
|
-
import { InteractionType, PopupRequest, RedirectRequest, SsoSilentRequest } from "@azure/msal-browser";
|
|
5
|
-
import { IMsalContext } from "../MsalContext";
|
|
6
|
-
export type MsalAuthenticationProps = PropsWithChildren<AccountIdentifiers & {
|
|
7
|
-
interactionType: InteractionType;
|
|
8
|
-
authenticationRequest?: PopupRequest | RedirectRequest | SsoSilentRequest;
|
|
9
|
-
loadingComponent?: React.ElementType<IMsalContext>;
|
|
10
|
-
errorComponent?: React.ElementType<MsalAuthenticationResult>;
|
|
11
|
-
}>;
|
|
12
|
-
/**
|
|
13
|
-
* Attempts to authenticate user if not already authenticated, then renders child components
|
|
14
|
-
* @param props
|
|
15
|
-
*/
|
|
16
|
-
export declare function MsalAuthenticationTemplate({ interactionType, username, homeAccountId, localAccountId, authenticationRequest, loadingComponent: LoadingComponent, errorComponent: ErrorComponent, children, }: MsalAuthenticationProps): React.ReactElement | null;
|
|
1
|
+
import React, { PropsWithChildren } from "react";
|
|
2
|
+
import { AccountIdentifiers } from "../types/AccountIdentifiers.js";
|
|
3
|
+
import { MsalAuthenticationResult } from "../hooks/useMsalAuthentication.js";
|
|
4
|
+
import { InteractionType, PopupRequest, RedirectRequest, SsoSilentRequest } from "@azure/msal-browser";
|
|
5
|
+
import { IMsalContext } from "../MsalContext.js";
|
|
6
|
+
export type MsalAuthenticationProps = PropsWithChildren<AccountIdentifiers & {
|
|
7
|
+
interactionType: InteractionType;
|
|
8
|
+
authenticationRequest?: PopupRequest | RedirectRequest | SsoSilentRequest;
|
|
9
|
+
loadingComponent?: React.ElementType<IMsalContext>;
|
|
10
|
+
errorComponent?: React.ElementType<MsalAuthenticationResult>;
|
|
11
|
+
}>;
|
|
12
|
+
/**
|
|
13
|
+
* Attempts to authenticate user if not already authenticated, then renders child components
|
|
14
|
+
* @param props
|
|
15
|
+
*/
|
|
16
|
+
export declare function MsalAuthenticationTemplate({ interactionType, username, homeAccountId, localAccountId, authenticationRequest, loadingComponent: LoadingComponent, errorComponent: ErrorComponent, children, }: MsalAuthenticationProps): React.ReactElement | null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @azure/msal-react v2.0
|
|
1
|
+
/*! @azure/msal-react v2.1.0 2024-09-20 */
|
|
2
2
|
'use strict';
|
|
3
3
|
import React__default, { useMemo } from 'react';
|
|
4
4
|
import { getChildrenOrFunction } from '../utils/utilities.js';
|
|
@@ -7,38 +7,38 @@ import { useMsalAuthentication } from '../hooks/useMsalAuthentication.js';
|
|
|
7
7
|
import { useIsAuthenticated } from '../hooks/useIsAuthenticated.js';
|
|
8
8
|
import { InteractionStatus } from '@azure/msal-browser';
|
|
9
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;
|
|
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
42
|
}
|
|
43
43
|
|
|
44
44
|
export { MsalAuthenticationTemplate };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React, { PropsWithChildren } from "react";
|
|
2
|
-
import { AccountIdentifiers } from "../types/AccountIdentifiers";
|
|
3
|
-
export type UnauthenticatedTemplateProps = PropsWithChildren<AccountIdentifiers>;
|
|
4
|
-
/**
|
|
5
|
-
* Renders child components if user is unauthenticated
|
|
6
|
-
* @param props
|
|
7
|
-
*/
|
|
8
|
-
export declare function UnauthenticatedTemplate({ username, homeAccountId, localAccountId, children, }: UnauthenticatedTemplateProps): React.ReactElement | null;
|
|
1
|
+
import React, { PropsWithChildren } from "react";
|
|
2
|
+
import { AccountIdentifiers } from "../types/AccountIdentifiers.js";
|
|
3
|
+
export type UnauthenticatedTemplateProps = PropsWithChildren<AccountIdentifiers>;
|
|
4
|
+
/**
|
|
5
|
+
* Renders child components if user is unauthenticated
|
|
6
|
+
* @param props
|
|
7
|
+
*/
|
|
8
|
+
export declare function UnauthenticatedTemplate({ username, homeAccountId, localAccountId, children, }: UnauthenticatedTemplateProps): React.ReactElement | null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @azure/msal-react v2.0
|
|
1
|
+
/*! @azure/msal-react v2.1.0 2024-09-20 */
|
|
2
2
|
'use strict';
|
|
3
3
|
import React__default, { useMemo } from 'react';
|
|
4
4
|
import { useMsal } from '../hooks/useMsal.js';
|
|
@@ -6,30 +6,30 @@ import { useIsAuthenticated } from '../hooks/useIsAuthenticated.js';
|
|
|
6
6
|
import { getChildrenOrFunction } from '../utils/utilities.js';
|
|
7
7
|
import { InteractionStatus } from '@azure/msal-browser';
|
|
8
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;
|
|
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
33
|
}
|
|
34
34
|
|
|
35
35
|
export { UnauthenticatedTemplate };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { IMsalContext } from "../MsalContext";
|
|
3
|
-
import { Subtract } from "../utils/utilities";
|
|
4
|
-
export type WithMsalProps = {
|
|
5
|
-
msalContext: IMsalContext;
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* Higher order component wraps provided component with msal by injecting msal context values into the component's props
|
|
9
|
-
* @param Component
|
|
10
|
-
*/
|
|
11
|
-
export declare const withMsal: <P extends WithMsalProps>(Component: React.ComponentType<P>) => React.FunctionComponent<Subtract<P, WithMsalProps>>;
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { IMsalContext } from "../MsalContext.js";
|
|
3
|
+
import { Subtract } from "../utils/utilities.js";
|
|
4
|
+
export type WithMsalProps = {
|
|
5
|
+
msalContext: IMsalContext;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Higher order component wraps provided component with msal by injecting msal context values into the component's props
|
|
9
|
+
* @param Component
|
|
10
|
+
*/
|
|
11
|
+
export declare const withMsal: <P extends WithMsalProps>(Component: React.ComponentType<P>) => React.FunctionComponent<Subtract<P, WithMsalProps>>;
|