@versini/auth-provider 3.0.0 → 4.0.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/index.d.ts +1 -0
- package/dist/index.js +341 -322
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ type AuthState = {
|
|
|
19
19
|
type AuthContextProps = {
|
|
20
20
|
login: (username: string, password: string) => Promise<boolean>;
|
|
21
21
|
logout: () => void;
|
|
22
|
+
getAccessToken: () => string;
|
|
22
23
|
} & AuthState;
|
|
23
24
|
|
|
24
25
|
declare const AuthProvider: ({ children, sessionExpiration, clientId, }: AuthProviderProps) => react_jsx_runtime.JSX.Element;
|
package/dist/index.js
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
import { jsx as
|
|
1
|
+
import { jsx as he } from "react/jsx-runtime";
|
|
2
2
|
import * as I from "react";
|
|
3
|
-
import { useRef as
|
|
3
|
+
import { useRef as pe, useEffect as Q, createContext as fe, useState as ye, useCallback as me, useContext as we } from "react";
|
|
4
4
|
/*!
|
|
5
|
-
@versini/auth-provider
|
|
5
|
+
@versini/auth-provider v4.0.0
|
|
6
6
|
© 2024 gizmette.com
|
|
7
7
|
*/
|
|
8
8
|
try {
|
|
9
9
|
window.__VERSINI_AUTH_CLIENT__ || (window.__VERSINI_AUTH_CLIENT__ = {
|
|
10
|
-
version: "
|
|
11
|
-
buildTime: "06/
|
|
10
|
+
version: "4.0.0",
|
|
11
|
+
buildTime: "06/26/2024 09:06 AM EDT",
|
|
12
12
|
homepage: "https://github.com/aversini/auth-client",
|
|
13
13
|
license: "MIT"
|
|
14
14
|
});
|
|
15
15
|
} catch {
|
|
16
16
|
}
|
|
17
17
|
/*!
|
|
18
|
-
@versini/auth-common v2.
|
|
18
|
+
@versini/auth-common v2.6.0
|
|
19
19
|
© 2024 gizmette.com
|
|
20
20
|
*/
|
|
21
21
|
try {
|
|
22
22
|
window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
|
|
23
|
-
version: "2.
|
|
24
|
-
buildTime: "06/
|
|
23
|
+
version: "2.6.0",
|
|
24
|
+
buildTime: "06/26/2024 09:06 AM EDT",
|
|
25
25
|
homepage: "https://github.com/aversini/auth-client",
|
|
26
26
|
license: "MIT"
|
|
27
27
|
});
|
|
28
28
|
} catch {
|
|
29
29
|
}
|
|
30
|
-
const
|
|
31
|
-
function
|
|
32
|
-
const t = e.reduce((n, { length:
|
|
30
|
+
const W = crypto, Z = (e) => e instanceof CryptoKey, T = new TextEncoder(), C = new TextDecoder();
|
|
31
|
+
function Se(...e) {
|
|
32
|
+
const t = e.reduce((n, { length: s }) => n + s, 0), o = new Uint8Array(t);
|
|
33
33
|
let r = 0;
|
|
34
34
|
for (const n of e)
|
|
35
35
|
o.set(n, r), r += n.length;
|
|
36
36
|
return o;
|
|
37
37
|
}
|
|
38
|
-
const
|
|
38
|
+
const Ee = (e) => {
|
|
39
39
|
const t = atob(e), o = new Uint8Array(t.length);
|
|
40
40
|
for (let r = 0; r < t.length; r++)
|
|
41
41
|
o[r] = t.charCodeAt(r);
|
|
42
42
|
return o;
|
|
43
|
-
},
|
|
43
|
+
}, N = (e) => {
|
|
44
44
|
let t = e;
|
|
45
|
-
t instanceof Uint8Array && (t =
|
|
45
|
+
t instanceof Uint8Array && (t = C.decode(t)), t = t.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
|
|
46
46
|
try {
|
|
47
|
-
return
|
|
47
|
+
return Ee(t);
|
|
48
48
|
} catch {
|
|
49
49
|
throw new TypeError("The input to be decoded is not correctly encoded.");
|
|
50
50
|
}
|
|
51
51
|
};
|
|
52
|
-
|
|
52
|
+
let b = class extends Error {
|
|
53
53
|
static get code() {
|
|
54
54
|
return "ERR_JOSE_GENERIC";
|
|
55
55
|
}
|
|
@@ -57,8 +57,8 @@ class b extends Error {
|
|
|
57
57
|
var o;
|
|
58
58
|
super(t), this.code = "ERR_JOSE_GENERIC", this.name = this.constructor.name, (o = Error.captureStackTrace) == null || o.call(Error, this, this.constructor);
|
|
59
59
|
}
|
|
60
|
-
}
|
|
61
|
-
class
|
|
60
|
+
};
|
|
61
|
+
class S extends b {
|
|
62
62
|
static get code() {
|
|
63
63
|
return "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
64
64
|
}
|
|
@@ -66,7 +66,7 @@ class m extends b {
|
|
|
66
66
|
super(t), this.code = "ERR_JWT_CLAIM_VALIDATION_FAILED", this.claim = r, this.reason = n, this.payload = o;
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
class
|
|
69
|
+
class M extends b {
|
|
70
70
|
static get code() {
|
|
71
71
|
return "ERR_JWT_EXPIRED";
|
|
72
72
|
}
|
|
@@ -74,7 +74,7 @@ class L extends b {
|
|
|
74
74
|
super(t), this.code = "ERR_JWT_EXPIRED", this.claim = r, this.reason = n, this.payload = o;
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
-
class
|
|
77
|
+
class ge extends b {
|
|
78
78
|
constructor() {
|
|
79
79
|
super(...arguments), this.code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
80
80
|
}
|
|
@@ -82,7 +82,7 @@ class he extends b {
|
|
|
82
82
|
return "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
-
class
|
|
85
|
+
class P extends b {
|
|
86
86
|
constructor() {
|
|
87
87
|
super(...arguments), this.code = "ERR_JOSE_NOT_SUPPORTED";
|
|
88
88
|
}
|
|
@@ -90,7 +90,7 @@ class k extends b {
|
|
|
90
90
|
return "ERR_JOSE_NOT_SUPPORTED";
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
|
-
let
|
|
93
|
+
let d = class extends b {
|
|
94
94
|
constructor() {
|
|
95
95
|
super(...arguments), this.code = "ERR_JWS_INVALID";
|
|
96
96
|
}
|
|
@@ -98,7 +98,7 @@ let l = class extends b {
|
|
|
98
98
|
return "ERR_JWS_INVALID";
|
|
99
99
|
}
|
|
100
100
|
};
|
|
101
|
-
class
|
|
101
|
+
class ee extends b {
|
|
102
102
|
constructor() {
|
|
103
103
|
super(...arguments), this.code = "ERR_JWT_INVALID";
|
|
104
104
|
}
|
|
@@ -106,7 +106,7 @@ class Y extends b {
|
|
|
106
106
|
return "ERR_JWT_INVALID";
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
-
class
|
|
109
|
+
class Ae extends b {
|
|
110
110
|
constructor() {
|
|
111
111
|
super(...arguments), this.code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED", this.message = "signature verification failed";
|
|
112
112
|
}
|
|
@@ -114,16 +114,16 @@ class pe extends b {
|
|
|
114
114
|
return "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
|
-
function
|
|
117
|
+
function E(e, t = "algorithm.name") {
|
|
118
118
|
return new TypeError(`CryptoKey does not support this operation, its ${t} must be ${e}`);
|
|
119
119
|
}
|
|
120
|
-
function
|
|
120
|
+
function R(e, t) {
|
|
121
121
|
return e.name === t;
|
|
122
122
|
}
|
|
123
|
-
function
|
|
123
|
+
function D(e) {
|
|
124
124
|
return parseInt(e.name.slice(4), 10);
|
|
125
125
|
}
|
|
126
|
-
function
|
|
126
|
+
function _e(e) {
|
|
127
127
|
switch (e) {
|
|
128
128
|
case "ES256":
|
|
129
129
|
return "P-256";
|
|
@@ -135,7 +135,7 @@ function fe(e) {
|
|
|
135
135
|
throw new Error("unreachable");
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
|
-
function
|
|
138
|
+
function be(e, t) {
|
|
139
139
|
if (t.length && !t.some((o) => e.usages.includes(o))) {
|
|
140
140
|
let o = "CryptoKey does not support this operation, its usages must include ";
|
|
141
141
|
if (t.length > 2) {
|
|
@@ -146,59 +146,59 @@ function ye(e, t) {
|
|
|
146
146
|
throw new TypeError(o);
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
|
-
function
|
|
149
|
+
function Ie(e, t, ...o) {
|
|
150
150
|
switch (t) {
|
|
151
151
|
case "HS256":
|
|
152
152
|
case "HS384":
|
|
153
153
|
case "HS512": {
|
|
154
|
-
if (!
|
|
155
|
-
throw
|
|
154
|
+
if (!R(e.algorithm, "HMAC"))
|
|
155
|
+
throw E("HMAC");
|
|
156
156
|
const r = parseInt(t.slice(2), 10);
|
|
157
|
-
if (
|
|
158
|
-
throw
|
|
157
|
+
if (D(e.algorithm.hash) !== r)
|
|
158
|
+
throw E(`SHA-${r}`, "algorithm.hash");
|
|
159
159
|
break;
|
|
160
160
|
}
|
|
161
161
|
case "RS256":
|
|
162
162
|
case "RS384":
|
|
163
163
|
case "RS512": {
|
|
164
|
-
if (!
|
|
165
|
-
throw
|
|
164
|
+
if (!R(e.algorithm, "RSASSA-PKCS1-v1_5"))
|
|
165
|
+
throw E("RSASSA-PKCS1-v1_5");
|
|
166
166
|
const r = parseInt(t.slice(2), 10);
|
|
167
|
-
if (
|
|
168
|
-
throw
|
|
167
|
+
if (D(e.algorithm.hash) !== r)
|
|
168
|
+
throw E(`SHA-${r}`, "algorithm.hash");
|
|
169
169
|
break;
|
|
170
170
|
}
|
|
171
171
|
case "PS256":
|
|
172
172
|
case "PS384":
|
|
173
173
|
case "PS512": {
|
|
174
|
-
if (!
|
|
175
|
-
throw
|
|
174
|
+
if (!R(e.algorithm, "RSA-PSS"))
|
|
175
|
+
throw E("RSA-PSS");
|
|
176
176
|
const r = parseInt(t.slice(2), 10);
|
|
177
|
-
if (
|
|
178
|
-
throw
|
|
177
|
+
if (D(e.algorithm.hash) !== r)
|
|
178
|
+
throw E(`SHA-${r}`, "algorithm.hash");
|
|
179
179
|
break;
|
|
180
180
|
}
|
|
181
181
|
case "EdDSA": {
|
|
182
182
|
if (e.algorithm.name !== "Ed25519" && e.algorithm.name !== "Ed448")
|
|
183
|
-
throw
|
|
183
|
+
throw E("Ed25519 or Ed448");
|
|
184
184
|
break;
|
|
185
185
|
}
|
|
186
186
|
case "ES256":
|
|
187
187
|
case "ES384":
|
|
188
188
|
case "ES512": {
|
|
189
|
-
if (!
|
|
190
|
-
throw
|
|
191
|
-
const r =
|
|
189
|
+
if (!R(e.algorithm, "ECDSA"))
|
|
190
|
+
throw E("ECDSA");
|
|
191
|
+
const r = _e(t);
|
|
192
192
|
if (e.algorithm.namedCurve !== r)
|
|
193
|
-
throw
|
|
193
|
+
throw E(r, "algorithm.namedCurve");
|
|
194
194
|
break;
|
|
195
195
|
}
|
|
196
196
|
default:
|
|
197
197
|
throw new TypeError("CryptoKey does not support this operation");
|
|
198
198
|
}
|
|
199
|
-
|
|
199
|
+
be(e, o);
|
|
200
200
|
}
|
|
201
|
-
function
|
|
201
|
+
function te(e, t, ...o) {
|
|
202
202
|
var r;
|
|
203
203
|
if (o.length > 2) {
|
|
204
204
|
const n = o.pop();
|
|
@@ -207,11 +207,11 @@ function q(e, t, ...o) {
|
|
|
207
207
|
o.length === 2 ? e += `one of type ${o[0]} or ${o[1]}.` : e += `of type ${o[0]}.`;
|
|
208
208
|
return t == null ? e += ` Received ${t}` : typeof t == "function" && t.name ? e += ` Received function ${t.name}` : typeof t == "object" && t != null && (r = t.constructor) != null && r.name && (e += ` Received an instance of ${t.constructor.name}`), e;
|
|
209
209
|
}
|
|
210
|
-
const
|
|
211
|
-
function
|
|
212
|
-
return
|
|
210
|
+
const V = (e, ...t) => te("Key must be ", e, ...t);
|
|
211
|
+
function re(e, t, ...o) {
|
|
212
|
+
return te(`Key for the ${e} algorithm must be `, t, ...o);
|
|
213
213
|
}
|
|
214
|
-
const
|
|
214
|
+
const oe = (e) => Z(e), A = ["CryptoKey"], ve = (...e) => {
|
|
215
215
|
const t = e.filter(Boolean);
|
|
216
216
|
if (t.length === 0 || t.length === 1)
|
|
217
217
|
return !0;
|
|
@@ -222,19 +222,19 @@ const X = (e) => G(e), E = ["CryptoKey"], we = (...e) => {
|
|
|
222
222
|
o = new Set(n);
|
|
223
223
|
continue;
|
|
224
224
|
}
|
|
225
|
-
for (const
|
|
226
|
-
if (o.has(
|
|
225
|
+
for (const s of n) {
|
|
226
|
+
if (o.has(s))
|
|
227
227
|
return !1;
|
|
228
|
-
o.add(
|
|
228
|
+
o.add(s);
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
231
|
return !0;
|
|
232
232
|
};
|
|
233
|
-
function
|
|
233
|
+
function Te(e) {
|
|
234
234
|
return typeof e == "object" && e !== null;
|
|
235
235
|
}
|
|
236
|
-
function
|
|
237
|
-
if (!
|
|
236
|
+
function K(e) {
|
|
237
|
+
if (!Te(e) || Object.prototype.toString.call(e) !== "[object Object]")
|
|
238
238
|
return !1;
|
|
239
239
|
if (Object.getPrototypeOf(e) === null)
|
|
240
240
|
return !0;
|
|
@@ -243,7 +243,7 @@ function H(e) {
|
|
|
243
243
|
t = Object.getPrototypeOf(t);
|
|
244
244
|
return Object.getPrototypeOf(e) === t;
|
|
245
245
|
}
|
|
246
|
-
const
|
|
246
|
+
const Re = (e, t) => {
|
|
247
247
|
if (e.startsWith("RS") || e.startsWith("PS")) {
|
|
248
248
|
const { modulusLength: o } = t.algorithm;
|
|
249
249
|
if (typeof o != "number" || o < 2048)
|
|
@@ -255,8 +255,8 @@ const ge = (e, t) => {
|
|
|
255
255
|
if (r === -1)
|
|
256
256
|
return !1;
|
|
257
257
|
const n = e.subarray(r, r + t.length);
|
|
258
|
-
return n.length !== t.length ? !1 : n.every((
|
|
259
|
-
},
|
|
258
|
+
return n.length !== t.length ? !1 : n.every((s, a) => s === t[a]) || g(e, t, r + 1);
|
|
259
|
+
}, Y = (e) => {
|
|
260
260
|
switch (!0) {
|
|
261
261
|
case g(e, [42, 134, 72, 206, 61, 3, 1, 7]):
|
|
262
262
|
return "P-256";
|
|
@@ -273,106 +273,106 @@ const ge = (e, t) => {
|
|
|
273
273
|
case g(e, [43, 101, 113]):
|
|
274
274
|
return "Ed448";
|
|
275
275
|
default:
|
|
276
|
-
throw new
|
|
276
|
+
throw new P("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
|
|
277
277
|
}
|
|
278
|
-
},
|
|
279
|
-
let
|
|
278
|
+
}, ke = async (e, t, o, r, n) => {
|
|
279
|
+
let s, a;
|
|
280
280
|
const i = new Uint8Array(atob(o.replace(e, "")).split("").map((c) => c.charCodeAt(0)));
|
|
281
281
|
switch (r) {
|
|
282
282
|
case "PS256":
|
|
283
283
|
case "PS384":
|
|
284
284
|
case "PS512":
|
|
285
|
-
|
|
285
|
+
s = { name: "RSA-PSS", hash: `SHA-${r.slice(-3)}` }, a = ["verify"];
|
|
286
286
|
break;
|
|
287
287
|
case "RS256":
|
|
288
288
|
case "RS384":
|
|
289
289
|
case "RS512":
|
|
290
|
-
|
|
290
|
+
s = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${r.slice(-3)}` }, a = ["verify"];
|
|
291
291
|
break;
|
|
292
292
|
case "RSA-OAEP":
|
|
293
293
|
case "RSA-OAEP-256":
|
|
294
294
|
case "RSA-OAEP-384":
|
|
295
295
|
case "RSA-OAEP-512":
|
|
296
|
-
|
|
296
|
+
s = {
|
|
297
297
|
name: "RSA-OAEP",
|
|
298
298
|
hash: `SHA-${parseInt(r.slice(-3), 10) || 1}`
|
|
299
|
-
},
|
|
299
|
+
}, a = ["encrypt", "wrapKey"];
|
|
300
300
|
break;
|
|
301
301
|
case "ES256":
|
|
302
|
-
|
|
302
|
+
s = { name: "ECDSA", namedCurve: "P-256" }, a = ["verify"];
|
|
303
303
|
break;
|
|
304
304
|
case "ES384":
|
|
305
|
-
|
|
305
|
+
s = { name: "ECDSA", namedCurve: "P-384" }, a = ["verify"];
|
|
306
306
|
break;
|
|
307
307
|
case "ES512":
|
|
308
|
-
|
|
308
|
+
s = { name: "ECDSA", namedCurve: "P-521" }, a = ["verify"];
|
|
309
309
|
break;
|
|
310
310
|
case "ECDH-ES":
|
|
311
311
|
case "ECDH-ES+A128KW":
|
|
312
312
|
case "ECDH-ES+A192KW":
|
|
313
313
|
case "ECDH-ES+A256KW": {
|
|
314
|
-
const c =
|
|
315
|
-
|
|
314
|
+
const c = Y(i);
|
|
315
|
+
s = c.startsWith("P-") ? { name: "ECDH", namedCurve: c } : { name: c }, a = [];
|
|
316
316
|
break;
|
|
317
317
|
}
|
|
318
318
|
case "EdDSA":
|
|
319
|
-
|
|
319
|
+
s = { name: Y(i) }, a = ["verify"];
|
|
320
320
|
break;
|
|
321
321
|
default:
|
|
322
|
-
throw new
|
|
322
|
+
throw new P('Invalid or unsupported "alg" (Algorithm) value');
|
|
323
323
|
}
|
|
324
|
-
return
|
|
325
|
-
},
|
|
326
|
-
async function
|
|
324
|
+
return W.subtle.importKey(t, i, s, !1, a);
|
|
325
|
+
}, Ce = (e, t, o) => ke(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "spki", e, t);
|
|
326
|
+
async function Pe(e, t, o) {
|
|
327
327
|
if (e.indexOf("-----BEGIN PUBLIC KEY-----") !== 0)
|
|
328
328
|
throw new TypeError('"spki" must be SPKI formatted string');
|
|
329
|
-
return
|
|
329
|
+
return Ce(e, t);
|
|
330
330
|
}
|
|
331
|
-
const
|
|
331
|
+
const Oe = (e, t) => {
|
|
332
332
|
if (!(t instanceof Uint8Array)) {
|
|
333
|
-
if (!
|
|
334
|
-
throw new TypeError(
|
|
333
|
+
if (!oe(t))
|
|
334
|
+
throw new TypeError(re(e, t, ...A, "Uint8Array"));
|
|
335
335
|
if (t.type !== "secret")
|
|
336
|
-
throw new TypeError(`${
|
|
336
|
+
throw new TypeError(`${A.join(" or ")} instances for symmetric algorithms must be of type "secret"`);
|
|
337
337
|
}
|
|
338
|
-
},
|
|
339
|
-
if (!
|
|
340
|
-
throw new TypeError(
|
|
338
|
+
}, Ne = (e, t, o) => {
|
|
339
|
+
if (!oe(t))
|
|
340
|
+
throw new TypeError(re(e, t, ...A));
|
|
341
341
|
if (t.type === "secret")
|
|
342
|
-
throw new TypeError(`${
|
|
342
|
+
throw new TypeError(`${A.join(" or ")} instances for asymmetric algorithms must not be of type "secret"`);
|
|
343
343
|
if (t.algorithm && o === "verify" && t.type === "private")
|
|
344
|
-
throw new TypeError(`${
|
|
344
|
+
throw new TypeError(`${A.join(" or ")} instances for asymmetric algorithm verifying must be of type "public"`);
|
|
345
345
|
if (t.algorithm && o === "encrypt" && t.type === "private")
|
|
346
|
-
throw new TypeError(`${
|
|
347
|
-
},
|
|
348
|
-
e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ?
|
|
346
|
+
throw new TypeError(`${A.join(" or ")} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
347
|
+
}, De = (e, t, o) => {
|
|
348
|
+
e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ? Oe(e, t) : Ne(e, t, o);
|
|
349
349
|
};
|
|
350
|
-
function
|
|
350
|
+
function He(e, t, o, r, n) {
|
|
351
351
|
if (n.crit !== void 0 && (r == null ? void 0 : r.crit) === void 0)
|
|
352
352
|
throw new e('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
353
353
|
if (!r || r.crit === void 0)
|
|
354
354
|
return /* @__PURE__ */ new Set();
|
|
355
|
-
if (!Array.isArray(r.crit) || r.crit.length === 0 || r.crit.some((
|
|
355
|
+
if (!Array.isArray(r.crit) || r.crit.length === 0 || r.crit.some((a) => typeof a != "string" || a.length === 0))
|
|
356
356
|
throw new e('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
|
|
357
|
-
let
|
|
358
|
-
o !== void 0 ?
|
|
359
|
-
for (const
|
|
360
|
-
if (!
|
|
361
|
-
throw new
|
|
362
|
-
if (n[
|
|
363
|
-
throw new e(`Extension Header Parameter "${
|
|
364
|
-
if (
|
|
365
|
-
throw new e(`Extension Header Parameter "${
|
|
357
|
+
let s;
|
|
358
|
+
o !== void 0 ? s = new Map([...Object.entries(o), ...t.entries()]) : s = t;
|
|
359
|
+
for (const a of r.crit) {
|
|
360
|
+
if (!s.has(a))
|
|
361
|
+
throw new P(`Extension Header Parameter "${a}" is not recognized`);
|
|
362
|
+
if (n[a] === void 0)
|
|
363
|
+
throw new e(`Extension Header Parameter "${a}" is missing`);
|
|
364
|
+
if (s.get(a) && r[a] === void 0)
|
|
365
|
+
throw new e(`Extension Header Parameter "${a}" MUST be integrity protected`);
|
|
366
366
|
}
|
|
367
367
|
return new Set(r.crit);
|
|
368
368
|
}
|
|
369
|
-
const
|
|
369
|
+
const Ue = (e, t) => {
|
|
370
370
|
if (t !== void 0 && (!Array.isArray(t) || t.some((o) => typeof o != "string")))
|
|
371
371
|
throw new TypeError(`"${e}" option must be an array of strings`);
|
|
372
372
|
if (t)
|
|
373
373
|
return new Set(t);
|
|
374
374
|
};
|
|
375
|
-
function
|
|
375
|
+
function Le(e, t) {
|
|
376
376
|
const o = `SHA-${e.slice(-3)}`;
|
|
377
377
|
switch (e) {
|
|
378
378
|
case "HS256":
|
|
@@ -394,104 +394,104 @@ function ke(e, t) {
|
|
|
394
394
|
case "EdDSA":
|
|
395
395
|
return { name: t.name };
|
|
396
396
|
default:
|
|
397
|
-
throw new
|
|
397
|
+
throw new P(`alg ${e} is not supported either by JOSE or your javascript runtime`);
|
|
398
398
|
}
|
|
399
399
|
}
|
|
400
|
-
function
|
|
401
|
-
if (
|
|
402
|
-
return
|
|
400
|
+
function $e(e, t, o) {
|
|
401
|
+
if (Z(t))
|
|
402
|
+
return Ie(t, e, o), t;
|
|
403
403
|
if (t instanceof Uint8Array) {
|
|
404
404
|
if (!e.startsWith("HS"))
|
|
405
|
-
throw new TypeError(
|
|
406
|
-
return
|
|
405
|
+
throw new TypeError(V(t, ...A));
|
|
406
|
+
return W.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [o]);
|
|
407
407
|
}
|
|
408
|
-
throw new TypeError(
|
|
408
|
+
throw new TypeError(V(t, ...A, "Uint8Array"));
|
|
409
409
|
}
|
|
410
|
-
const
|
|
411
|
-
const n = await
|
|
412
|
-
|
|
413
|
-
const
|
|
410
|
+
const Je = async (e, t, o, r) => {
|
|
411
|
+
const n = await $e(e, t, "verify");
|
|
412
|
+
Re(e, n);
|
|
413
|
+
const s = Le(e, n.algorithm);
|
|
414
414
|
try {
|
|
415
|
-
return await
|
|
415
|
+
return await W.subtle.verify(s, n, o, r);
|
|
416
416
|
} catch {
|
|
417
417
|
return !1;
|
|
418
418
|
}
|
|
419
419
|
};
|
|
420
|
-
async function
|
|
421
|
-
if (!
|
|
422
|
-
throw new
|
|
420
|
+
async function Ke(e, t, o) {
|
|
421
|
+
if (!K(e))
|
|
422
|
+
throw new d("Flattened JWS must be an object");
|
|
423
423
|
if (e.protected === void 0 && e.header === void 0)
|
|
424
|
-
throw new
|
|
424
|
+
throw new d('Flattened JWS must have either of the "protected" or "header" members');
|
|
425
425
|
if (e.protected !== void 0 && typeof e.protected != "string")
|
|
426
|
-
throw new
|
|
426
|
+
throw new d("JWS Protected Header incorrect type");
|
|
427
427
|
if (e.payload === void 0)
|
|
428
|
-
throw new
|
|
428
|
+
throw new d("JWS Payload missing");
|
|
429
429
|
if (typeof e.signature != "string")
|
|
430
|
-
throw new
|
|
431
|
-
if (e.header !== void 0 && !
|
|
432
|
-
throw new
|
|
430
|
+
throw new d("JWS Signature missing or incorrect type");
|
|
431
|
+
if (e.header !== void 0 && !K(e.header))
|
|
432
|
+
throw new d("JWS Unprotected Header incorrect type");
|
|
433
433
|
let r = {};
|
|
434
434
|
if (e.protected)
|
|
435
435
|
try {
|
|
436
|
-
const
|
|
437
|
-
r = JSON.parse(
|
|
436
|
+
const l = N(e.protected);
|
|
437
|
+
r = JSON.parse(C.decode(l));
|
|
438
438
|
} catch {
|
|
439
|
-
throw new
|
|
439
|
+
throw new d("JWS Protected Header is invalid");
|
|
440
440
|
}
|
|
441
|
-
if (!
|
|
442
|
-
throw new
|
|
441
|
+
if (!ve(r, e.header))
|
|
442
|
+
throw new d("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
443
443
|
const n = {
|
|
444
444
|
...r,
|
|
445
445
|
...e.header
|
|
446
|
-
},
|
|
447
|
-
let
|
|
448
|
-
if (
|
|
449
|
-
throw new
|
|
446
|
+
}, s = He(d, /* @__PURE__ */ new Map([["b64", !0]]), o == null ? void 0 : o.crit, r, n);
|
|
447
|
+
let a = !0;
|
|
448
|
+
if (s.has("b64") && (a = r.b64, typeof a != "boolean"))
|
|
449
|
+
throw new d('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
|
450
450
|
const { alg: i } = n;
|
|
451
451
|
if (typeof i != "string" || !i)
|
|
452
|
-
throw new
|
|
453
|
-
const c = o &&
|
|
452
|
+
throw new d('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
453
|
+
const c = o && Ue("algorithms", o.algorithms);
|
|
454
454
|
if (c && !c.has(i))
|
|
455
|
-
throw new
|
|
456
|
-
if (
|
|
455
|
+
throw new ge('"alg" (Algorithm) Header Parameter value not allowed');
|
|
456
|
+
if (a) {
|
|
457
457
|
if (typeof e.payload != "string")
|
|
458
|
-
throw new
|
|
458
|
+
throw new d("JWS Payload must be a string");
|
|
459
459
|
} else if (typeof e.payload != "string" && !(e.payload instanceof Uint8Array))
|
|
460
|
-
throw new
|
|
461
|
-
let
|
|
462
|
-
typeof t == "function" && (t = await t(r, e),
|
|
463
|
-
const
|
|
464
|
-
let
|
|
460
|
+
throw new d("JWS Payload must be a string or an Uint8Array instance");
|
|
461
|
+
let p = !1;
|
|
462
|
+
typeof t == "function" && (t = await t(r, e), p = !0), De(i, t, "verify");
|
|
463
|
+
const m = Se(T.encode(e.protected ?? ""), T.encode("."), typeof e.payload == "string" ? T.encode(e.payload) : e.payload);
|
|
464
|
+
let h;
|
|
465
465
|
try {
|
|
466
|
-
|
|
466
|
+
h = N(e.signature);
|
|
467
467
|
} catch {
|
|
468
|
-
throw new
|
|
468
|
+
throw new d("Failed to base64url decode the signature");
|
|
469
469
|
}
|
|
470
|
-
if (!await
|
|
471
|
-
throw new
|
|
472
|
-
let
|
|
473
|
-
if (
|
|
470
|
+
if (!await Je(i, t, h, m))
|
|
471
|
+
throw new Ae();
|
|
472
|
+
let w;
|
|
473
|
+
if (a)
|
|
474
474
|
try {
|
|
475
|
-
|
|
475
|
+
w = N(e.payload);
|
|
476
476
|
} catch {
|
|
477
|
-
throw new
|
|
477
|
+
throw new d("Failed to base64url decode the payload");
|
|
478
478
|
}
|
|
479
479
|
else
|
|
480
|
-
typeof e.payload == "string" ?
|
|
481
|
-
const
|
|
482
|
-
return e.protected !== void 0 && (
|
|
483
|
-
}
|
|
484
|
-
async function
|
|
485
|
-
if (e instanceof Uint8Array && (e =
|
|
486
|
-
throw new
|
|
487
|
-
const { 0: r, 1: n, 2:
|
|
488
|
-
if (
|
|
489
|
-
throw new
|
|
490
|
-
const i = await
|
|
480
|
+
typeof e.payload == "string" ? w = T.encode(e.payload) : w = e.payload;
|
|
481
|
+
const f = { payload: w };
|
|
482
|
+
return e.protected !== void 0 && (f.protectedHeader = r), e.header !== void 0 && (f.unprotectedHeader = e.header), p ? { ...f, key: t } : f;
|
|
483
|
+
}
|
|
484
|
+
async function We(e, t, o) {
|
|
485
|
+
if (e instanceof Uint8Array && (e = C.decode(e)), typeof e != "string")
|
|
486
|
+
throw new d("Compact JWS must be a string or Uint8Array");
|
|
487
|
+
const { 0: r, 1: n, 2: s, length: a } = e.split(".");
|
|
488
|
+
if (a !== 3)
|
|
489
|
+
throw new d("Invalid Compact JWS");
|
|
490
|
+
const i = await Ke({ payload: n, protected: r, signature: s }, t, o), c = { payload: i.payload, protectedHeader: i.protectedHeader };
|
|
491
491
|
return typeof t == "function" ? { ...c, key: i.key } : c;
|
|
492
492
|
}
|
|
493
|
-
const
|
|
494
|
-
const t =
|
|
493
|
+
const xe = (e) => Math.floor(e.getTime() / 1e3), ne = 60, ae = ne * 60, x = ae * 24, je = x * 7, Me = x * 365.25, Ve = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i, B = (e) => {
|
|
494
|
+
const t = Ve.exec(e);
|
|
495
495
|
if (!t || t[4] && t[1])
|
|
496
496
|
throw new TypeError("Invalid time period format");
|
|
497
497
|
const o = parseFloat(t[2]), r = t[3].toLowerCase();
|
|
@@ -509,108 +509,111 @@ const He = (e) => Math.floor(e.getTime() / 1e3), Q = 60, Z = Q * 60, U = Z * 24,
|
|
|
509
509
|
case "min":
|
|
510
510
|
case "mins":
|
|
511
511
|
case "m":
|
|
512
|
-
n = Math.round(o *
|
|
512
|
+
n = Math.round(o * ne);
|
|
513
513
|
break;
|
|
514
514
|
case "hour":
|
|
515
515
|
case "hours":
|
|
516
516
|
case "hr":
|
|
517
517
|
case "hrs":
|
|
518
518
|
case "h":
|
|
519
|
-
n = Math.round(o *
|
|
519
|
+
n = Math.round(o * ae);
|
|
520
520
|
break;
|
|
521
521
|
case "day":
|
|
522
522
|
case "days":
|
|
523
523
|
case "d":
|
|
524
|
-
n = Math.round(o *
|
|
524
|
+
n = Math.round(o * x);
|
|
525
525
|
break;
|
|
526
526
|
case "week":
|
|
527
527
|
case "weeks":
|
|
528
528
|
case "w":
|
|
529
|
-
n = Math.round(o *
|
|
529
|
+
n = Math.round(o * je);
|
|
530
530
|
break;
|
|
531
531
|
default:
|
|
532
|
-
n = Math.round(o *
|
|
532
|
+
n = Math.round(o * Me);
|
|
533
533
|
break;
|
|
534
534
|
}
|
|
535
535
|
return t[1] === "-" || t[4] === "ago" ? -n : n;
|
|
536
|
-
},
|
|
536
|
+
}, F = (e) => e.toLowerCase().replace(/^application\//, ""), Ye = (e, t) => typeof e == "string" ? t.includes(e) : Array.isArray(e) ? t.some(Set.prototype.has.bind(new Set(e))) : !1, Be = (e, t, o = {}) => {
|
|
537
537
|
let r;
|
|
538
538
|
try {
|
|
539
|
-
r = JSON.parse(
|
|
539
|
+
r = JSON.parse(C.decode(t));
|
|
540
540
|
} catch {
|
|
541
541
|
}
|
|
542
|
-
if (!
|
|
543
|
-
throw new
|
|
542
|
+
if (!K(r))
|
|
543
|
+
throw new ee("JWT Claims Set must be a top-level JSON object");
|
|
544
544
|
const { typ: n } = o;
|
|
545
|
-
if (n && (typeof e.typ != "string" ||
|
|
546
|
-
throw new
|
|
547
|
-
const { requiredClaims:
|
|
548
|
-
|
|
549
|
-
for (const
|
|
550
|
-
if (!(
|
|
551
|
-
throw new
|
|
552
|
-
if (
|
|
553
|
-
throw new
|
|
545
|
+
if (n && (typeof e.typ != "string" || F(e.typ) !== F(n)))
|
|
546
|
+
throw new S('unexpected "typ" JWT header value', r, "typ", "check_failed");
|
|
547
|
+
const { requiredClaims: s = [], issuer: a, subject: i, audience: c, maxTokenAge: p } = o, m = [...s];
|
|
548
|
+
p !== void 0 && m.push("iat"), c !== void 0 && m.push("aud"), i !== void 0 && m.push("sub"), a !== void 0 && m.push("iss");
|
|
549
|
+
for (const l of new Set(m.reverse()))
|
|
550
|
+
if (!(l in r))
|
|
551
|
+
throw new S(`missing required "${l}" claim`, r, l, "missing");
|
|
552
|
+
if (a && !(Array.isArray(a) ? a : [a]).includes(r.iss))
|
|
553
|
+
throw new S('unexpected "iss" claim value', r, "iss", "check_failed");
|
|
554
554
|
if (i && r.sub !== i)
|
|
555
|
-
throw new
|
|
556
|
-
if (c && !
|
|
557
|
-
throw new
|
|
558
|
-
let
|
|
555
|
+
throw new S('unexpected "sub" claim value', r, "sub", "check_failed");
|
|
556
|
+
if (c && !Ye(r.aud, typeof c == "string" ? [c] : c))
|
|
557
|
+
throw new S('unexpected "aud" claim value', r, "aud", "check_failed");
|
|
558
|
+
let h;
|
|
559
559
|
switch (typeof o.clockTolerance) {
|
|
560
560
|
case "string":
|
|
561
|
-
|
|
561
|
+
h = B(o.clockTolerance);
|
|
562
562
|
break;
|
|
563
563
|
case "number":
|
|
564
|
-
|
|
564
|
+
h = o.clockTolerance;
|
|
565
565
|
break;
|
|
566
566
|
case "undefined":
|
|
567
|
-
|
|
567
|
+
h = 0;
|
|
568
568
|
break;
|
|
569
569
|
default:
|
|
570
570
|
throw new TypeError("Invalid clockTolerance option type");
|
|
571
571
|
}
|
|
572
|
-
const { currentDate:
|
|
573
|
-
if ((r.iat !== void 0 ||
|
|
574
|
-
throw new
|
|
572
|
+
const { currentDate: w } = o, f = xe(w || /* @__PURE__ */ new Date());
|
|
573
|
+
if ((r.iat !== void 0 || p) && typeof r.iat != "number")
|
|
574
|
+
throw new S('"iat" claim must be a number', r, "iat", "invalid");
|
|
575
575
|
if (r.nbf !== void 0) {
|
|
576
576
|
if (typeof r.nbf != "number")
|
|
577
|
-
throw new
|
|
578
|
-
if (r.nbf >
|
|
579
|
-
throw new
|
|
577
|
+
throw new S('"nbf" claim must be a number', r, "nbf", "invalid");
|
|
578
|
+
if (r.nbf > f + h)
|
|
579
|
+
throw new S('"nbf" claim timestamp check failed', r, "nbf", "check_failed");
|
|
580
580
|
}
|
|
581
581
|
if (r.exp !== void 0) {
|
|
582
582
|
if (typeof r.exp != "number")
|
|
583
|
-
throw new
|
|
584
|
-
if (r.exp <=
|
|
585
|
-
throw new
|
|
583
|
+
throw new S('"exp" claim must be a number', r, "exp", "invalid");
|
|
584
|
+
if (r.exp <= f - h)
|
|
585
|
+
throw new M('"exp" claim timestamp check failed', r, "exp", "check_failed");
|
|
586
586
|
}
|
|
587
|
-
if (
|
|
588
|
-
const
|
|
589
|
-
if (
|
|
590
|
-
throw new
|
|
591
|
-
if (
|
|
592
|
-
throw new
|
|
587
|
+
if (p) {
|
|
588
|
+
const l = f - r.iat, O = typeof p == "number" ? p : B(p);
|
|
589
|
+
if (l - h > O)
|
|
590
|
+
throw new M('"iat" claim timestamp check failed (too far in the past)', r, "iat", "check_failed");
|
|
591
|
+
if (l < 0 - h)
|
|
592
|
+
throw new S('"iat" claim timestamp check failed (it should be in the past)', r, "iat", "check_failed");
|
|
593
593
|
}
|
|
594
594
|
return r;
|
|
595
595
|
};
|
|
596
|
-
async function
|
|
596
|
+
async function Fe(e, t, o) {
|
|
597
597
|
var r;
|
|
598
|
-
const n = await
|
|
598
|
+
const n = await We(e, t, o);
|
|
599
599
|
if ((r = n.protectedHeader.crit) != null && r.includes("b64") && n.protectedHeader.b64 === !1)
|
|
600
|
-
throw new
|
|
601
|
-
const
|
|
602
|
-
return typeof t == "function" ? { ...
|
|
603
|
-
}
|
|
604
|
-
const
|
|
605
|
-
ID_TOKEN: "id_token"
|
|
606
|
-
|
|
600
|
+
throw new ee("JWTs MUST NOT use unencoded payload");
|
|
601
|
+
const s = { payload: Be(n.protectedHeader, n.payload, o), protectedHeader: n.protectedHeader };
|
|
602
|
+
return typeof t == "function" ? { ...s, key: n.key } : s;
|
|
603
|
+
}
|
|
604
|
+
const Ge = {
|
|
605
|
+
ID_TOKEN: "id_token",
|
|
606
|
+
ACCESS_TOKEN: "token",
|
|
607
|
+
ID_AND_ACCESS_TOKEN: "id_token token"
|
|
608
|
+
}, qe = {
|
|
607
609
|
CLIENT_ID: "X-Auth-ClientId"
|
|
608
|
-
},
|
|
610
|
+
}, _ = {
|
|
609
611
|
ALG: "RS256",
|
|
610
612
|
USER_ID_KEY: "_id",
|
|
611
613
|
TOKEN_ID_KEY: "__raw",
|
|
614
|
+
NONCE_KEY: "_nonce",
|
|
612
615
|
ISSUER: "gizmette.com"
|
|
613
|
-
},
|
|
616
|
+
}, ze = `-----BEGIN PUBLIC KEY-----
|
|
614
617
|
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsF6i3Jd9fY/3COqCw/m7
|
|
615
618
|
w5PKyTYLGAI2I6SIIdpe6i6DOCbEkmDz7LdVsBqwNtVi8gvWYIj+8ol6rU3qu1v5
|
|
616
619
|
i1Jd45GSK4kzkVdgCmQZbM5ak0KI99q5wsrAIzUd+LRJ2HRvWtr5IYdsIiXaQjle
|
|
@@ -618,129 +621,131 @@ aMwPFOIcJH+rKfFgNcHLcaS5syp7zU1ANwZ+trgR+DifBr8TLVkBynmNeTyhDm2+
|
|
|
618
621
|
l0haqjMk0UoNPPE8iYBWUHQJJE1Dqstj65d6Eh5g64Pao25y4cmYJbKjiblIGEkE
|
|
619
622
|
sjqybA9mARAqh9k/eiIopecWSiffNQTwVQVd2I9ZH3BalhEXHlqFgrjz51kFqg81
|
|
620
623
|
awIDAQAB
|
|
621
|
-
-----END PUBLIC KEY-----`,
|
|
624
|
+
-----END PUBLIC KEY-----`, se = async (e, t) => {
|
|
622
625
|
try {
|
|
623
|
-
const o =
|
|
624
|
-
return await
|
|
625
|
-
issuer:
|
|
626
|
+
const o = _.ALG, r = await Pe(ze, o);
|
|
627
|
+
return await Fe(e, r, {
|
|
628
|
+
issuer: _.ISSUER,
|
|
626
629
|
audience: t
|
|
627
630
|
});
|
|
628
631
|
} catch {
|
|
629
632
|
return;
|
|
630
633
|
}
|
|
631
634
|
};
|
|
632
|
-
function
|
|
635
|
+
function ie(e, t) {
|
|
633
636
|
window.dispatchEvent(new StorageEvent("storage", { key: e, newValue: t }));
|
|
634
637
|
}
|
|
635
|
-
const
|
|
638
|
+
const G = (e, t) => {
|
|
636
639
|
const o = JSON.stringify(
|
|
637
640
|
typeof t == "function" ? t() : t
|
|
638
641
|
);
|
|
639
|
-
window.localStorage.setItem(e, o),
|
|
640
|
-
},
|
|
641
|
-
window.localStorage.removeItem(e),
|
|
642
|
-
},
|
|
643
|
-
function
|
|
642
|
+
window.localStorage.setItem(e, o), ie(e, o);
|
|
643
|
+
}, Xe = (e) => {
|
|
644
|
+
window.localStorage.removeItem(e), ie(e, null);
|
|
645
|
+
}, q = (e) => window.localStorage.getItem(e), Qe = (e) => (window.addEventListener("storage", e), () => window.removeEventListener("storage", e));
|
|
646
|
+
function H({
|
|
644
647
|
key: e,
|
|
645
648
|
initialValue: t
|
|
646
649
|
}) {
|
|
647
|
-
const o = () =>
|
|
648
|
-
|
|
650
|
+
const o = () => q(e), r = I.useSyncExternalStore(
|
|
651
|
+
Qe,
|
|
649
652
|
o
|
|
650
653
|
), n = I.useCallback(
|
|
651
654
|
(i) => {
|
|
652
655
|
try {
|
|
653
656
|
const c = typeof i == "function" ? i(JSON.parse(r)) : i;
|
|
654
|
-
c == null ?
|
|
657
|
+
c == null ? Xe(e) : G(e, c);
|
|
655
658
|
} catch (c) {
|
|
656
659
|
console.warn(c);
|
|
657
660
|
}
|
|
658
661
|
},
|
|
659
662
|
[e, r]
|
|
660
|
-
),
|
|
663
|
+
), s = I.useCallback(() => {
|
|
661
664
|
n(t);
|
|
662
|
-
}, [t, n]),
|
|
665
|
+
}, [t, n]), a = I.useCallback(() => {
|
|
663
666
|
n(null);
|
|
664
667
|
}, [n]);
|
|
665
668
|
return I.useEffect(() => {
|
|
666
669
|
try {
|
|
667
|
-
|
|
670
|
+
q(e) === null && typeof t < "u" && G(e, t);
|
|
668
671
|
} catch (i) {
|
|
669
672
|
console.warn(i);
|
|
670
673
|
}
|
|
671
|
-
}, [e, t]), [r ? JSON.parse(r) : null, n,
|
|
674
|
+
}, [e, t]), [r ? JSON.parse(r) : null, n, s, a];
|
|
672
675
|
}
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
function
|
|
681
|
-
|
|
682
|
-
}
|
|
683
|
-
var R, Xe = new Uint8Array(16);
|
|
684
|
-
function Qe() {
|
|
685
|
-
if (!R && (R = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !R))
|
|
676
|
+
var u = [];
|
|
677
|
+
for (var U = 0; U < 256; ++U)
|
|
678
|
+
u.push((U + 256).toString(16).slice(1));
|
|
679
|
+
function Ze(e, t = 0) {
|
|
680
|
+
return (u[e[t + 0]] + u[e[t + 1]] + u[e[t + 2]] + u[e[t + 3]] + "-" + u[e[t + 4]] + u[e[t + 5]] + "-" + u[e[t + 6]] + u[e[t + 7]] + "-" + u[e[t + 8]] + u[e[t + 9]] + "-" + u[e[t + 10]] + u[e[t + 11]] + u[e[t + 12]] + u[e[t + 13]] + u[e[t + 14]] + u[e[t + 15]]).toLowerCase();
|
|
681
|
+
}
|
|
682
|
+
var k, et = new Uint8Array(16);
|
|
683
|
+
function tt() {
|
|
684
|
+
if (!k && (k = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !k))
|
|
686
685
|
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
687
|
-
return
|
|
686
|
+
return k(et);
|
|
688
687
|
}
|
|
689
|
-
var
|
|
690
|
-
const
|
|
691
|
-
randomUUID:
|
|
688
|
+
var rt = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
689
|
+
const z = {
|
|
690
|
+
randomUUID: rt
|
|
692
691
|
};
|
|
693
|
-
function
|
|
694
|
-
if (
|
|
695
|
-
return
|
|
692
|
+
function ot(e, t, o) {
|
|
693
|
+
if (z.randomUUID && !t && !e)
|
|
694
|
+
return z.randomUUID();
|
|
696
695
|
e = e || {};
|
|
697
|
-
var r = e.random || (e.rng ||
|
|
698
|
-
return r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128,
|
|
696
|
+
var r = e.random || (e.rng || tt)();
|
|
697
|
+
return r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, Ze(r);
|
|
699
698
|
}
|
|
700
|
-
const
|
|
699
|
+
const L = "Oops! It looks like your session has expired. For your security, please log in again to continue.", nt = "Your session has been successfully terminated.", at = "Login failed. Please try again.", st = "You forgot to wrap your component in <AuthProvider>.", X = {
|
|
700
|
+
dev: "https://auth.gizmette.local.com:3003",
|
|
701
|
+
prod: "https://mylogin.gizmette.com"
|
|
702
|
+
}, $ = "@@auth@@", it = process.env.NODE_ENV === "production", ct = !it, ut = async ({ params: e = {} }) => {
|
|
701
703
|
try {
|
|
702
|
-
const t =
|
|
703
|
-
|
|
704
|
+
const t = await fetch(
|
|
705
|
+
ct ? `${X.dev}/authenticate` : `${X.prod}/authenticate`,
|
|
704
706
|
{
|
|
705
707
|
credentials: "include",
|
|
706
708
|
method: "POST",
|
|
707
709
|
headers: {
|
|
708
710
|
"Content-Type": "application/json",
|
|
709
|
-
[
|
|
711
|
+
[qe.CLIENT_ID]: `${e.clientId}`
|
|
710
712
|
},
|
|
711
|
-
body: JSON.stringify(
|
|
713
|
+
body: JSON.stringify(e)
|
|
712
714
|
}
|
|
713
715
|
);
|
|
714
|
-
if (
|
|
715
|
-
return { status:
|
|
716
|
-
const { data:
|
|
717
|
-
return
|
|
718
|
-
status:
|
|
719
|
-
data:
|
|
720
|
-
errors:
|
|
716
|
+
if (t.status !== 200)
|
|
717
|
+
return { status: t.status, data: [] };
|
|
718
|
+
const { data: o, errors: r } = await t.json();
|
|
719
|
+
return {
|
|
720
|
+
status: t.status,
|
|
721
|
+
data: o,
|
|
722
|
+
errors: r
|
|
721
723
|
};
|
|
722
724
|
} catch (t) {
|
|
723
725
|
return console.error(t), { status: 500, data: [] };
|
|
724
726
|
}
|
|
725
|
-
},
|
|
727
|
+
}, dt = async ({
|
|
726
728
|
username: e,
|
|
727
729
|
password: t,
|
|
728
730
|
clientId: o,
|
|
729
|
-
|
|
731
|
+
nonce: r,
|
|
732
|
+
sessionExpiration: n
|
|
730
733
|
}) => {
|
|
731
734
|
try {
|
|
732
|
-
const
|
|
735
|
+
const s = await ut({
|
|
733
736
|
params: {
|
|
734
|
-
type:
|
|
737
|
+
type: Ge.ID_AND_ACCESS_TOKEN,
|
|
735
738
|
username: e,
|
|
736
739
|
password: t,
|
|
737
|
-
sessionExpiration:
|
|
738
|
-
clientId: o
|
|
740
|
+
sessionExpiration: n,
|
|
741
|
+
clientId: o,
|
|
742
|
+
nonce: r
|
|
739
743
|
}
|
|
740
|
-
}), a = await
|
|
741
|
-
return a && a.payload[
|
|
742
|
-
idToken:
|
|
743
|
-
|
|
744
|
+
}), a = await se(s.data.idToken, o);
|
|
745
|
+
return a && a.payload[_.USER_ID_KEY] !== "" && a.payload[_.NONCE_KEY] === r ? {
|
|
746
|
+
idToken: s.data.idToken,
|
|
747
|
+
accessToken: s.data.accessToken,
|
|
748
|
+
userId: a.payload[_.USER_ID_KEY],
|
|
744
749
|
status: !0
|
|
745
750
|
} : {
|
|
746
751
|
status: !1
|
|
@@ -751,83 +756,97 @@ const tt = process.env.NODE_ENV === "production", rt = !tt, ot = async ({ params
|
|
|
751
756
|
};
|
|
752
757
|
}
|
|
753
758
|
};
|
|
754
|
-
function
|
|
755
|
-
const t =
|
|
756
|
-
return
|
|
759
|
+
function lt(e) {
|
|
760
|
+
const t = pe();
|
|
761
|
+
return Q(() => {
|
|
757
762
|
t.current = e;
|
|
758
763
|
}), t.current;
|
|
759
764
|
}
|
|
760
|
-
const
|
|
761
|
-
throw new Error(
|
|
762
|
-
},
|
|
765
|
+
const J = () => {
|
|
766
|
+
throw new Error(st);
|
|
767
|
+
}, ce = fe({
|
|
763
768
|
isAuthenticated: !1,
|
|
764
769
|
isLoading: !1,
|
|
765
|
-
login:
|
|
766
|
-
logout:
|
|
770
|
+
login: J,
|
|
771
|
+
logout: J,
|
|
772
|
+
getAccessToken: J,
|
|
767
773
|
logoutReason: "",
|
|
768
774
|
idTokenClaims: null
|
|
769
|
-
}),
|
|
775
|
+
}), mt = ({
|
|
770
776
|
children: e,
|
|
771
777
|
sessionExpiration: t,
|
|
772
778
|
clientId: o
|
|
773
779
|
}) => {
|
|
774
|
-
const [r, n, ,
|
|
775
|
-
key: `${
|
|
776
|
-
}), [
|
|
780
|
+
const [r, n, , s] = H({
|
|
781
|
+
key: `${$}::${o}::@@user@@`
|
|
782
|
+
}), [a, i, , c] = H({
|
|
783
|
+
key: `${$}::${o}::@@access@@`
|
|
784
|
+
}), [, p, , m] = H({
|
|
785
|
+
key: `${$}::${o}::@@nonce@@`
|
|
786
|
+
}), [h, w] = ye({
|
|
777
787
|
isLoading: !0,
|
|
778
788
|
isAuthenticated: !1,
|
|
779
789
|
logoutReason: "",
|
|
780
790
|
userId: "",
|
|
781
791
|
idTokenClaims: null
|
|
782
|
-
}),
|
|
783
|
-
(
|
|
784
|
-
|
|
792
|
+
}), f = lt(r) || "", l = me(
|
|
793
|
+
(y) => {
|
|
794
|
+
w({
|
|
785
795
|
isLoading: !1,
|
|
786
796
|
isAuthenticated: !1,
|
|
787
|
-
logoutReason:
|
|
797
|
+
logoutReason: y || L,
|
|
788
798
|
userId: "",
|
|
789
799
|
idTokenClaims: null
|
|
790
|
-
}),
|
|
800
|
+
}), s(), c(), m();
|
|
791
801
|
},
|
|
792
|
-
[
|
|
802
|
+
[s, c, m]
|
|
793
803
|
);
|
|
794
|
-
|
|
795
|
-
|
|
804
|
+
Q(() => {
|
|
805
|
+
f !== r && r !== null && (async () => {
|
|
796
806
|
try {
|
|
797
|
-
const
|
|
798
|
-
|
|
807
|
+
const y = await se(r, o);
|
|
808
|
+
y && y.payload[_.USER_ID_KEY] !== "" ? w({
|
|
799
809
|
isLoading: !1,
|
|
800
810
|
isAuthenticated: !0,
|
|
801
811
|
logoutReason: "",
|
|
802
|
-
userId:
|
|
812
|
+
userId: y.payload[_.USER_ID_KEY],
|
|
803
813
|
idTokenClaims: {
|
|
804
|
-
...
|
|
805
|
-
[
|
|
814
|
+
...y == null ? void 0 : y.payload,
|
|
815
|
+
[_.TOKEN_ID_KEY]: r
|
|
806
816
|
}
|
|
807
|
-
}) :
|
|
817
|
+
}) : l(L);
|
|
808
818
|
} catch {
|
|
809
|
-
|
|
819
|
+
l(L);
|
|
810
820
|
}
|
|
811
821
|
})();
|
|
812
|
-
}, [r,
|
|
813
|
-
const
|
|
814
|
-
const
|
|
815
|
-
|
|
816
|
-
|
|
822
|
+
}, [r, f, o, l]);
|
|
823
|
+
const O = async (y, le) => {
|
|
824
|
+
const j = ot();
|
|
825
|
+
p(j);
|
|
826
|
+
const v = await dt({
|
|
827
|
+
username: y,
|
|
828
|
+
password: le,
|
|
817
829
|
clientId: o,
|
|
818
|
-
sessionExpiration: t
|
|
830
|
+
sessionExpiration: t,
|
|
831
|
+
nonce: j
|
|
819
832
|
});
|
|
820
|
-
return
|
|
833
|
+
return v.status ? (n(v.idToken), i(v.accessToken), w({
|
|
821
834
|
isLoading: !1,
|
|
822
835
|
isAuthenticated: !0,
|
|
823
|
-
userId:
|
|
824
|
-
}), !0) : (
|
|
825
|
-
},
|
|
826
|
-
|
|
827
|
-
};
|
|
828
|
-
return /* @__PURE__ */
|
|
829
|
-
|
|
836
|
+
userId: v.userId
|
|
837
|
+
}), !0) : (l(at), !1);
|
|
838
|
+
}, ue = () => {
|
|
839
|
+
l(nt);
|
|
840
|
+
}, de = () => a;
|
|
841
|
+
return /* @__PURE__ */ he(
|
|
842
|
+
ce.Provider,
|
|
843
|
+
{
|
|
844
|
+
value: { ...h, login: O, logout: ue, getAccessToken: de },
|
|
845
|
+
children: e
|
|
846
|
+
}
|
|
847
|
+
);
|
|
848
|
+
}, wt = (e = ce) => we(e);
|
|
830
849
|
export {
|
|
831
|
-
|
|
832
|
-
|
|
850
|
+
mt as AuthProvider,
|
|
851
|
+
wt as useAuth
|
|
833
852
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@versini/auth-provider",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Arno Versini",
|
|
6
6
|
"publishConfig": {
|
|
@@ -44,10 +44,10 @@
|
|
|
44
44
|
"react-dom": "18.3.1"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@versini/auth-common": "2.
|
|
47
|
+
"@versini/auth-common": "2.6.0",
|
|
48
48
|
"@versini/ui-hooks": "4.0.0",
|
|
49
49
|
"jose": "5.4.1",
|
|
50
50
|
"uuid": "10.0.0"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "8229de388733e13731f9dcfdfe6ffbc0ee9e77fb"
|
|
53
53
|
}
|