@arkitektbedriftene/fe-lib 7.3.0 → 7.3.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/oidc.es.js +41 -40
- package/package.json +1 -1
package/dist/oidc.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var E = Object.defineProperty;
|
|
2
|
-
var v = (t, e,
|
|
3
|
-
var f = (t, e,
|
|
2
|
+
var v = (t, e, n) => e in t ? E(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
|
|
3
|
+
var f = (t, e, n) => v(t, typeof e != "symbol" ? e + "" : e, n);
|
|
4
4
|
import { jsx as w } from "react/jsx-runtime";
|
|
5
5
|
import { createContext as I, useContext as U, useMemo as k, useEffect as h, useState as R, useRef as x, useCallback as m } from "react";
|
|
6
6
|
import { UserManager as L } from "oidc-client-ts";
|
|
@@ -19,20 +19,20 @@ const y = I(
|
|
|
19
19
|
}, q = ({
|
|
20
20
|
children: t
|
|
21
21
|
}) => {
|
|
22
|
-
const [e,
|
|
22
|
+
const [e, n] = P("impersonationState", {
|
|
23
23
|
defaultValue: {}
|
|
24
24
|
}), s = k(() => ({
|
|
25
25
|
accessToken: e == null ? void 0 : e.accessToken,
|
|
26
26
|
userInfo: e == null ? void 0 : e.userInfo,
|
|
27
27
|
setImpersonation: (o, i) => {
|
|
28
|
-
|
|
28
|
+
n({ accessToken: o, userInfo: i });
|
|
29
29
|
}
|
|
30
30
|
}), []);
|
|
31
31
|
return /* @__PURE__ */ w(y.Provider, { value: s, children: t });
|
|
32
32
|
}, V = (t) => {
|
|
33
33
|
const { setImpersonation: e } = b();
|
|
34
34
|
h(() => {
|
|
35
|
-
const { search:
|
|
35
|
+
const { search: n } = window.location, s = new URLSearchParams(n).get(
|
|
36
36
|
"impersonateAccessToken"
|
|
37
37
|
);
|
|
38
38
|
if (s && e) {
|
|
@@ -70,11 +70,11 @@ const $ = [
|
|
|
70
70
|
"0"
|
|
71
71
|
];
|
|
72
72
|
class Q {
|
|
73
|
-
constructor(e,
|
|
73
|
+
constructor(e, n) {
|
|
74
74
|
f(this, "userManager");
|
|
75
75
|
f(this, "storageKey", "impersonationState");
|
|
76
76
|
f(this, "meEndpoint");
|
|
77
|
-
this.userManager = new L(e), this.meEndpoint =
|
|
77
|
+
this.userManager = new L(e), this.meEndpoint = n;
|
|
78
78
|
}
|
|
79
79
|
/**
|
|
80
80
|
* Get impersonation user from localStorage
|
|
@@ -83,11 +83,11 @@ class Q {
|
|
|
83
83
|
try {
|
|
84
84
|
const e = localStorage.getItem(this.storageKey);
|
|
85
85
|
if (e) {
|
|
86
|
-
const
|
|
87
|
-
if (
|
|
88
|
-
if (Math.floor(Date.now() / 1e3) >=
|
|
86
|
+
const n = JSON.parse(e);
|
|
87
|
+
if (n.impersonationToken && n.impersonatedUser) {
|
|
88
|
+
if (Math.floor(Date.now() / 1e3) >= n.impersonatedUser.exp)
|
|
89
89
|
throw new Error("Impersonation token has expired");
|
|
90
|
-
return
|
|
90
|
+
return n;
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
} catch (e) {
|
|
@@ -106,10 +106,10 @@ class Q {
|
|
|
106
106
|
profile: e.impersonatedUser,
|
|
107
107
|
impersonating: !0
|
|
108
108
|
};
|
|
109
|
-
const
|
|
110
|
-
return !
|
|
111
|
-
access_token:
|
|
112
|
-
profile:
|
|
109
|
+
const n = await this.userManager.getUser();
|
|
110
|
+
return !n || n.expired ? null : {
|
|
111
|
+
access_token: n.access_token,
|
|
112
|
+
profile: n.profile,
|
|
113
113
|
impersonating: !1
|
|
114
114
|
};
|
|
115
115
|
}
|
|
@@ -138,14 +138,15 @@ class Q {
|
|
|
138
138
|
const o = {
|
|
139
139
|
impersonatedUser: await (await fetch(this.meEndpoint, {
|
|
140
140
|
headers: {
|
|
141
|
+
"Content-Type": "application/json",
|
|
141
142
|
Authorization: `Bearer ${e}`
|
|
142
143
|
}
|
|
143
144
|
})).json(),
|
|
144
145
|
impersonationToken: e
|
|
145
146
|
};
|
|
146
147
|
localStorage.setItem(this.storageKey, JSON.stringify(o));
|
|
147
|
-
} catch (
|
|
148
|
-
console.error("Failed to set impersonation token:",
|
|
148
|
+
} catch (n) {
|
|
149
|
+
console.error("Failed to set impersonation token:", n);
|
|
149
150
|
}
|
|
150
151
|
}
|
|
151
152
|
/**
|
|
@@ -167,7 +168,7 @@ class Q {
|
|
|
167
168
|
const O = ({
|
|
168
169
|
userManager: t,
|
|
169
170
|
context: e,
|
|
170
|
-
children:
|
|
171
|
+
children: n
|
|
171
172
|
}) => {
|
|
172
173
|
const [s, o] = R({
|
|
173
174
|
user: null,
|
|
@@ -179,26 +180,26 @@ const O = ({
|
|
|
179
180
|
h(() => {
|
|
180
181
|
i.current || (i.current = !0, (async () => {
|
|
181
182
|
try {
|
|
182
|
-
const
|
|
183
|
+
const r = await t.getUser();
|
|
183
184
|
o({
|
|
184
|
-
user:
|
|
185
|
+
user: r,
|
|
185
186
|
isLoading: !1,
|
|
186
|
-
isAuthenticated:
|
|
187
|
+
isAuthenticated: r ? !r.expired : !1,
|
|
187
188
|
isError: !1,
|
|
188
189
|
error: null
|
|
189
190
|
});
|
|
190
|
-
} catch (
|
|
191
|
+
} catch (r) {
|
|
191
192
|
o({
|
|
192
193
|
user: null,
|
|
193
194
|
isLoading: !1,
|
|
194
195
|
isAuthenticated: !1,
|
|
195
196
|
isError: !0,
|
|
196
|
-
error:
|
|
197
|
+
error: r instanceof Error ? r : new Error("Unknown error during auth")
|
|
197
198
|
});
|
|
198
199
|
}
|
|
199
200
|
})());
|
|
200
201
|
}, [t]), h(() => {
|
|
201
|
-
const
|
|
202
|
+
const r = (p) => {
|
|
202
203
|
o({
|
|
203
204
|
user: p,
|
|
204
205
|
isLoading: !1,
|
|
@@ -207,7 +208,7 @@ const O = ({
|
|
|
207
208
|
error: null
|
|
208
209
|
});
|
|
209
210
|
};
|
|
210
|
-
t.events.addUserLoaded(
|
|
211
|
+
t.events.addUserLoaded(r);
|
|
211
212
|
const c = () => {
|
|
212
213
|
o({
|
|
213
214
|
...s,
|
|
@@ -225,34 +226,34 @@ const O = ({
|
|
|
225
226
|
});
|
|
226
227
|
};
|
|
227
228
|
return t.events.addSilentRenewError(S), () => {
|
|
228
|
-
t.events.removeUserLoaded(
|
|
229
|
+
t.events.removeUserLoaded(r), t.events.removeUserUnloaded(c), t.events.removeSilentRenewError(S);
|
|
229
230
|
};
|
|
230
231
|
}, [t]);
|
|
231
232
|
const u = m(async () => {
|
|
232
|
-
const
|
|
233
|
+
const r = await t.signinCallback();
|
|
233
234
|
return o({
|
|
234
|
-
user:
|
|
235
|
+
user: r ?? null,
|
|
235
236
|
isLoading: !1,
|
|
236
|
-
isAuthenticated:
|
|
237
|
+
isAuthenticated: r ? !r.expired : !1,
|
|
237
238
|
isError: !1,
|
|
238
239
|
error: null
|
|
239
|
-
}),
|
|
240
|
+
}), r ?? void 0;
|
|
240
241
|
}, [t]), a = m(
|
|
241
|
-
async (
|
|
242
|
+
async (r) => {
|
|
242
243
|
try {
|
|
243
|
-
await t.signinRedirect(
|
|
244
|
+
await t.signinRedirect(r);
|
|
244
245
|
} catch (c) {
|
|
245
246
|
console.error(c);
|
|
246
247
|
}
|
|
247
248
|
},
|
|
248
249
|
[t]
|
|
249
250
|
), l = m(
|
|
250
|
-
async (
|
|
251
|
+
async (r) => await t.signinPopup(r),
|
|
251
252
|
[t]
|
|
252
253
|
), d = m(
|
|
253
|
-
async (
|
|
254
|
+
async (r) => {
|
|
254
255
|
try {
|
|
255
|
-
return await t.signinSilent(
|
|
256
|
+
return await t.signinSilent(r);
|
|
256
257
|
} catch (c) {
|
|
257
258
|
return o({
|
|
258
259
|
user: null,
|
|
@@ -265,9 +266,9 @@ const O = ({
|
|
|
265
266
|
},
|
|
266
267
|
[t]
|
|
267
268
|
), g = m(
|
|
268
|
-
async (
|
|
269
|
+
async (r) => {
|
|
269
270
|
try {
|
|
270
|
-
await t.signoutRedirect(
|
|
271
|
+
await t.signoutRedirect(r);
|
|
271
272
|
} catch (c) {
|
|
272
273
|
console.error(c);
|
|
273
274
|
}
|
|
@@ -291,7 +292,7 @@ const O = ({
|
|
|
291
292
|
g
|
|
292
293
|
]
|
|
293
294
|
);
|
|
294
|
-
return /* @__PURE__ */ w(e.Provider, { value: C, children:
|
|
295
|
+
return /* @__PURE__ */ w(e.Provider, { value: C, children: n });
|
|
295
296
|
}, A = (t) => {
|
|
296
297
|
const e = U(t);
|
|
297
298
|
if (!e)
|
|
@@ -301,14 +302,14 @@ const O = ({
|
|
|
301
302
|
const { state: e } = A(t);
|
|
302
303
|
return e;
|
|
303
304
|
}, K = (t, e) => {
|
|
304
|
-
const { state:
|
|
305
|
+
const { state: n, handleSigninCallback: s } = A(t), o = x(!1);
|
|
305
306
|
return h(() => {
|
|
306
307
|
o.current || (o.current = !0, s().then(
|
|
307
308
|
(i) => new Promise(
|
|
308
309
|
(u) => setTimeout(() => u(i), 0)
|
|
309
310
|
)
|
|
310
311
|
).then((i) => e == null ? void 0 : e(i)));
|
|
311
|
-
}, [s]),
|
|
312
|
+
}, [s]), n;
|
|
312
313
|
}, W = (t) => {
|
|
313
314
|
const e = I(null);
|
|
314
315
|
return {
|