@evoke-platform/context 1.5.0-testing.2 → 1.5.0-testing.4
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.
|
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
-
import { createContext, useCallback, useContext, useMemo } from 'react';
|
|
11
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useRef } from 'react';
|
|
12
12
|
const Context = createContext(undefined);
|
|
13
13
|
Context.displayName = 'AuthenticationContext';
|
|
14
14
|
function AuthenticationContextProvider(props) {
|
|
@@ -64,10 +64,14 @@ function MsalProvider({ msal, authRequest, children }) {
|
|
|
64
64
|
return _jsx(Context.Provider, { value: context, children: children });
|
|
65
65
|
}
|
|
66
66
|
function OidcProvider({ oidcInstance, authRequest, children }) {
|
|
67
|
-
var _a, _b;
|
|
67
|
+
var _a, _b, _c;
|
|
68
68
|
if (!oidcInstance) {
|
|
69
69
|
throw new Error('OIDC instance is required for OidcProvider');
|
|
70
70
|
}
|
|
71
|
+
const userRef = useRef(oidcInstance.user);
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
userRef.current = oidcInstance.user;
|
|
74
|
+
}, [oidcInstance.user]);
|
|
71
75
|
// The authRequest for react-oidc is formatted slightly differently than msal.
|
|
72
76
|
const oidcAuthRequest = {
|
|
73
77
|
scope: (_b = (_a = authRequest.scopes) === null || _a === void 0 ? void 0 : _a.join(' ')) !== null && _b !== void 0 ? _b : 'openid profile email',
|
|
@@ -75,14 +79,14 @@ function OidcProvider({ oidcInstance, authRequest, children }) {
|
|
|
75
79
|
state: authRequest.state,
|
|
76
80
|
};
|
|
77
81
|
const getAccessToken = useCallback(function () {
|
|
78
|
-
var _a
|
|
82
|
+
var _a;
|
|
79
83
|
return __awaiter(this, void 0, void 0, function* () {
|
|
80
84
|
try {
|
|
81
85
|
// With automaticSilentRenew: true, oidc-client-ts will attempt to renew the token in the background before it expires.
|
|
82
86
|
// However, this is not guaranteed to be perfectly in sync with your API calls. Always check for expiration here and call signinSilent if needed
|
|
83
87
|
// to ensure you get a valid token on demand.
|
|
84
|
-
if (((_a =
|
|
85
|
-
return
|
|
88
|
+
if (((_a = userRef.current) === null || _a === void 0 ? void 0 : _a.access_token) && !userRef.current.expired) {
|
|
89
|
+
return userRef.current.access_token;
|
|
86
90
|
}
|
|
87
91
|
// Token is either missing or expired - attempt silent refresh.
|
|
88
92
|
const user = yield oidcInstance.signinSilent(oidcAuthRequest);
|
|
@@ -92,7 +96,7 @@ function OidcProvider({ oidcInstance, authRequest, children }) {
|
|
|
92
96
|
oidcInstance.signinRedirect(oidcAuthRequest);
|
|
93
97
|
return '';
|
|
94
98
|
}
|
|
95
|
-
return
|
|
99
|
+
return user.access_token;
|
|
96
100
|
}
|
|
97
101
|
catch (error) {
|
|
98
102
|
console.error('Failed to get access token:', error);
|
|
@@ -102,17 +106,17 @@ function OidcProvider({ oidcInstance, authRequest, children }) {
|
|
|
102
106
|
return '';
|
|
103
107
|
}
|
|
104
108
|
});
|
|
105
|
-
}, [oidcInstance, authRequest]);
|
|
109
|
+
}, [oidcInstance.signinSilent, oidcInstance.signinRedirect, authRequest]);
|
|
106
110
|
const context = useMemo(() => {
|
|
107
111
|
var _a, _b, _c, _d;
|
|
108
|
-
return oidcInstance.isAuthenticated &&
|
|
112
|
+
return oidcInstance.isAuthenticated && userRef.current
|
|
109
113
|
? {
|
|
110
114
|
account: {
|
|
111
|
-
id:
|
|
112
|
-
name: (_a =
|
|
115
|
+
id: userRef.current.profile.sub,
|
|
116
|
+
name: (_a = userRef.current.profile.name) !== null && _a !== void 0 ? _a : (`${(_b = userRef.current.profile.given_name) !== null && _b !== void 0 ? _b : ''} ${(_c = userRef.current.profile.family_name) !== null && _c !== void 0 ? _c : ''}` ||
|
|
113
117
|
undefined),
|
|
114
|
-
username: (_d =
|
|
115
|
-
lastLoginTime:
|
|
118
|
+
username: (_d = userRef.current.profile.preferred_username) !== null && _d !== void 0 ? _d : userRef.current.profile.email,
|
|
119
|
+
lastLoginTime: userRef.current.profile.lastLoginTime,
|
|
116
120
|
},
|
|
117
121
|
logout: () => {
|
|
118
122
|
oidcInstance.signoutRedirect({
|
|
@@ -123,7 +127,13 @@ function OidcProvider({ oidcInstance, authRequest, children }) {
|
|
|
123
127
|
getAccessToken,
|
|
124
128
|
}
|
|
125
129
|
: undefined;
|
|
126
|
-
}, [
|
|
130
|
+
}, [
|
|
131
|
+
// Make sure to update authentication context if the logged-in user changes.
|
|
132
|
+
(_c = userRef.current) === null || _c === void 0 ? void 0 : _c.profile.sub,
|
|
133
|
+
oidcInstance.isAuthenticated,
|
|
134
|
+
oidcInstance.signoutRedirect,
|
|
135
|
+
getAccessToken,
|
|
136
|
+
]);
|
|
127
137
|
return _jsx(Context.Provider, { value: context, children: children });
|
|
128
138
|
}
|
|
129
139
|
export function useAuthenticationContext() {
|
|
@@ -193,6 +193,12 @@ export type DisplayConfiguration = {
|
|
|
193
193
|
charCount?: boolean;
|
|
194
194
|
mode?: 'default' | 'existingOnly';
|
|
195
195
|
relatedObjectDisplay?: 'dropdown' | 'dialogBox';
|
|
196
|
+
/**
|
|
197
|
+
* The ID of the related object for parameters of type 'object'.
|
|
198
|
+
* When a parameter is of type 'object' whose objectId is not configured,
|
|
199
|
+
* this specifies which object it relates to when the field entry is rendered.
|
|
200
|
+
*/
|
|
201
|
+
relatedObjectId?: string;
|
|
196
202
|
visibility?: VisibilityConfiguration | JsonLogic;
|
|
197
203
|
viewLayout?: ViewLayoutEntityReference;
|
|
198
204
|
choicesDisplay?: {
|