@azure/msal-react 2.0.22 → 2.1.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.
- 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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @azure/msal-react v2.
|
|
1
|
+
/*! @azure/msal-react v2.1.1 2024-10-03 */
|
|
2
2
|
'use strict';
|
|
3
3
|
import { useState, useRef, useEffect, useCallback } from 'react';
|
|
4
4
|
import { InteractionStatus, InteractionType, EventType, OIDC_DEFAULT_SCOPES, InteractionRequiredAuthError } from '@azure/msal-browser';
|
|
@@ -7,189 +7,189 @@ import { useMsal } from './useMsal.js';
|
|
|
7
7
|
import { useAccount } from './useAccount.js';
|
|
8
8
|
import { ReactAuthError } from '../error/ReactAuthError.js';
|
|
9
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
|
-
};
|
|
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
193
|
}
|
|
194
194
|
|
|
195
195
|
export { useMsalAuthentication };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @packageDocumentation
|
|
3
|
-
* @module @azure/msal-react
|
|
4
|
-
*/
|
|
5
|
-
export type { IMsalContext } from "./MsalContext";
|
|
6
|
-
export type { MsalProviderProps } from "./MsalProvider";
|
|
7
|
-
export type { MsalAuthenticationResult } from "./hooks/useMsalAuthentication";
|
|
8
|
-
export type { MsalAuthenticationProps } from "./components/MsalAuthenticationTemplate";
|
|
9
|
-
export type { AuthenticatedTemplateProps } from "./components/AuthenticatedTemplate";
|
|
10
|
-
export type { UnauthenticatedTemplateProps } from "./components/UnauthenticatedTemplate";
|
|
11
|
-
export type { WithMsalProps } from "./components/withMsal";
|
|
12
|
-
export type { AccountIdentifiers } from "./types/AccountIdentifiers";
|
|
13
|
-
export { MsalContext, MsalConsumer } from "./MsalContext";
|
|
14
|
-
export { MsalProvider } from "./MsalProvider";
|
|
15
|
-
export { AuthenticatedTemplate } from "./components/AuthenticatedTemplate";
|
|
16
|
-
export { UnauthenticatedTemplate } from "./components/UnauthenticatedTemplate";
|
|
17
|
-
export { MsalAuthenticationTemplate } from "./components/MsalAuthenticationTemplate";
|
|
18
|
-
export { withMsal } from "./components/withMsal";
|
|
19
|
-
export { Subtract, SetComplement, SetDifference } from "./utils/utilities";
|
|
20
|
-
export { useMsal } from "./hooks/useMsal";
|
|
21
|
-
export { useAccount } from "./hooks/useAccount";
|
|
22
|
-
export { useIsAuthenticated } from "./hooks/useIsAuthenticated";
|
|
23
|
-
export { useMsalAuthentication } from "./hooks/useMsalAuthentication";
|
|
24
|
-
export { version } from "./packageMetadata";
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* @module @azure/msal-react
|
|
4
|
+
*/
|
|
5
|
+
export type { IMsalContext } from "./MsalContext.js";
|
|
6
|
+
export type { MsalProviderProps } from "./MsalProvider.js";
|
|
7
|
+
export type { MsalAuthenticationResult } from "./hooks/useMsalAuthentication.js";
|
|
8
|
+
export type { MsalAuthenticationProps } from "./components/MsalAuthenticationTemplate.js";
|
|
9
|
+
export type { AuthenticatedTemplateProps } from "./components/AuthenticatedTemplate.js";
|
|
10
|
+
export type { UnauthenticatedTemplateProps } from "./components/UnauthenticatedTemplate.js";
|
|
11
|
+
export type { WithMsalProps } from "./components/withMsal.js";
|
|
12
|
+
export type { AccountIdentifiers } from "./types/AccountIdentifiers.js";
|
|
13
|
+
export { MsalContext, MsalConsumer } from "./MsalContext.js";
|
|
14
|
+
export { MsalProvider } from "./MsalProvider.js";
|
|
15
|
+
export { AuthenticatedTemplate } from "./components/AuthenticatedTemplate.js";
|
|
16
|
+
export { UnauthenticatedTemplate } from "./components/UnauthenticatedTemplate.js";
|
|
17
|
+
export { MsalAuthenticationTemplate } from "./components/MsalAuthenticationTemplate.js";
|
|
18
|
+
export { withMsal } from "./components/withMsal.js";
|
|
19
|
+
export { Subtract, SetComplement, SetDifference } from "./utils/utilities.js";
|
|
20
|
+
export { useMsal } from "./hooks/useMsal.js";
|
|
21
|
+
export { useAccount } from "./hooks/useAccount.js";
|
|
22
|
+
export { useIsAuthenticated } from "./hooks/useIsAuthenticated.js";
|
|
23
|
+
export { useMsalAuthentication } from "./hooks/useMsalAuthentication.js";
|
|
24
|
+
export { version } from "./packageMetadata.js";
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const name = "@azure/msal-react";
|
|
2
|
-
export declare const version = "2.
|
|
1
|
+
export declare const name = "@azure/msal-react";
|
|
2
|
+
export declare const version = "2.1.1";
|
package/dist/packageMetadata.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/*! @azure/msal-react v2.
|
|
1
|
+
/*! @azure/msal-react v2.1.1 2024-10-03 */
|
|
2
2
|
'use strict';
|
|
3
|
-
/* eslint-disable header/header */
|
|
4
|
-
const name = "@azure/msal-react";
|
|
5
|
-
const version = "2.
|
|
3
|
+
/* eslint-disable header/header */
|
|
4
|
+
const name = "@azure/msal-react";
|
|
5
|
+
const version = "2.1.1";
|
|
6
6
|
|
|
7
7
|
export { name, version };
|
|
8
8
|
//# sourceMappingURL=packageMetadata.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { AccountInfo } from "@azure/msal-browser";
|
|
2
|
-
export type AccountIdentifiers = Partial<Pick<AccountInfo, "homeAccountId" | "localAccountId" | "username">>;
|
|
1
|
+
import { AccountInfo } from "@azure/msal-browser";
|
|
2
|
+
export type AccountIdentifiers = Partial<Pick<AccountInfo, "homeAccountId" | "localAccountId" | "username">>;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { AccountIdentifiers } from "../types/AccountIdentifiers";
|
|
3
|
-
import { AccountInfo } from "@azure/msal-browser";
|
|
4
|
-
type FaaCFunction = <T>(args: T) => React.ReactNode;
|
|
5
|
-
export declare function getChildrenOrFunction<T>(children: React.ReactNode | FaaCFunction, args: T): React.ReactNode;
|
|
6
|
-
export type SetDifference<A, B> = A extends B ? never : A;
|
|
7
|
-
export 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
|
-
/**
|
|
10
|
-
* Helper function to determine whether 2 arrays are equal
|
|
11
|
-
* Used to avoid unnecessary state updates
|
|
12
|
-
* @param arrayA
|
|
13
|
-
* @param arrayB
|
|
14
|
-
*/
|
|
15
|
-
export declare function accountArraysAreEqual(arrayA: Array<AccountIdentifiers>, arrayB: Array<AccountIdentifiers>): boolean;
|
|
16
|
-
export declare function getAccountByIdentifiers(allAccounts: AccountInfo[], accountIdentifiers: AccountIdentifiers): AccountInfo | null;
|
|
17
|
-
export {};
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { AccountIdentifiers } from "../types/AccountIdentifiers.js";
|
|
3
|
+
import { AccountInfo } from "@azure/msal-browser";
|
|
4
|
+
type FaaCFunction = <T>(args: T) => React.ReactNode;
|
|
5
|
+
export declare function getChildrenOrFunction<T>(children: React.ReactNode | FaaCFunction, args: T): React.ReactNode;
|
|
6
|
+
export type SetDifference<A, B> = A extends B ? never : A;
|
|
7
|
+
export 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
|
+
/**
|
|
10
|
+
* Helper function to determine whether 2 arrays are equal
|
|
11
|
+
* Used to avoid unnecessary state updates
|
|
12
|
+
* @param arrayA
|
|
13
|
+
* @param arrayB
|
|
14
|
+
*/
|
|
15
|
+
export declare function accountArraysAreEqual(arrayA: Array<AccountIdentifiers>, arrayB: Array<AccountIdentifiers>): boolean;
|
|
16
|
+
export declare function getAccountByIdentifiers(allAccounts: AccountInfo[], accountIdentifiers: AccountIdentifiers): AccountInfo | null;
|
|
17
|
+
export {};
|
package/dist/utils/utilities.js
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
/*! @azure/msal-react v2.
|
|
1
|
+
/*! @azure/msal-react v2.1.1 2024-10-03 */
|
|
2
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
|
-
}
|
|
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
62
|
}
|
|
63
63
|
|
|
64
64
|
export { accountArraysAreEqual, getAccountByIdentifiers, getChildrenOrFunction };
|