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