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