@versini/auth-provider 2.1.2 → 2.3.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 -3
- package/dist/index.js +378 -363
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -10,9 +10,6 @@ type AuthProviderProps = {
|
|
|
10
10
|
|
|
11
11
|
type AuthState = {
|
|
12
12
|
isAuthenticated: boolean;
|
|
13
|
-
idToken?: string;
|
|
14
|
-
accessToken?: string;
|
|
15
|
-
refreshToken?: string;
|
|
16
13
|
logoutReason?: string;
|
|
17
14
|
userId?: string;
|
|
18
15
|
};
|
|
@@ -20,6 +17,7 @@ type AuthState = {
|
|
|
20
17
|
type AuthContextProps = {
|
|
21
18
|
login: (username: string, password: string) => Promise<boolean>;
|
|
22
19
|
logout: () => void;
|
|
20
|
+
getIdTokenClaims: () => Promise<any>;
|
|
23
21
|
} & AuthState;
|
|
24
22
|
|
|
25
23
|
declare const AuthProvider: ({ children, sessionExpiration, clientId, }: AuthProviderProps) => react_jsx_runtime.JSX.Element;
|
package/dist/index.js
CHANGED
|
@@ -1,141 +1,80 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import * as
|
|
1
|
+
import { jsx as ne } from "react/jsx-runtime";
|
|
2
|
+
import * as I from "react";
|
|
3
3
|
import { useRef as ae, useEffect as Y, createContext as se, useState as ie, useContext as ce } from "react";
|
|
4
4
|
/*!
|
|
5
|
-
@versini/auth-provider v2.
|
|
5
|
+
@versini/auth-provider v2.3.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
|
|
10
|
+
version: "2.3.0",
|
|
11
|
+
buildTime: "06/24/2024 06:34 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.3.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
|
|
23
|
+
version: "2.3.0",
|
|
24
|
+
buildTime: "06/24/2024 06:34 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 U = crypto, G = (e) => e instanceof CryptoKey, _ = 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
|
+
}, C = (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 b 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 m extends
|
|
61
|
+
class m extends b {
|
|
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 $ extends b {
|
|
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 b {
|
|
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 b {
|
|
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 b {
|
|
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 q extends b {
|
|
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 b {
|
|
171
110
|
constructor() {
|
|
172
111
|
super(...arguments), this.code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED", this.message = "signature verification failed";
|
|
173
112
|
}
|
|
@@ -178,13 +117,13 @@ class Ae extends g {
|
|
|
178
117
|
function S(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 v(e, t) {
|
|
182
121
|
return e.name === t;
|
|
183
122
|
}
|
|
184
|
-
function
|
|
123
|
+
function P(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,46 +135,46 @@ 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 (!
|
|
154
|
+
if (!v(e.algorithm, "HMAC"))
|
|
216
155
|
throw S("HMAC");
|
|
217
156
|
const r = parseInt(t.slice(2), 10);
|
|
218
|
-
if (
|
|
157
|
+
if (P(e.algorithm.hash) !== r)
|
|
219
158
|
throw S(`SHA-${r}`, "algorithm.hash");
|
|
220
159
|
break;
|
|
221
160
|
}
|
|
222
161
|
case "RS256":
|
|
223
162
|
case "RS384":
|
|
224
163
|
case "RS512": {
|
|
225
|
-
if (!
|
|
164
|
+
if (!v(e.algorithm, "RSASSA-PKCS1-v1_5"))
|
|
226
165
|
throw S("RSASSA-PKCS1-v1_5");
|
|
227
166
|
const r = parseInt(t.slice(2), 10);
|
|
228
|
-
if (
|
|
167
|
+
if (P(e.algorithm.hash) !== r)
|
|
229
168
|
throw S(`SHA-${r}`, "algorithm.hash");
|
|
230
169
|
break;
|
|
231
170
|
}
|
|
232
171
|
case "PS256":
|
|
233
172
|
case "PS384":
|
|
234
173
|
case "PS512": {
|
|
235
|
-
if (!
|
|
174
|
+
if (!v(e.algorithm, "RSA-PSS"))
|
|
236
175
|
throw S("RSA-PSS");
|
|
237
176
|
const r = parseInt(t.slice(2), 10);
|
|
238
|
-
if (
|
|
177
|
+
if (P(e.algorithm.hash) !== r)
|
|
239
178
|
throw S(`SHA-${r}`, "algorithm.hash");
|
|
240
179
|
break;
|
|
241
180
|
}
|
|
@@ -247,9 +186,9 @@ function _e(e, t, ...n) {
|
|
|
247
186
|
case "ES256":
|
|
248
187
|
case "ES384":
|
|
249
188
|
case "ES512": {
|
|
250
|
-
if (!
|
|
189
|
+
if (!v(e.algorithm, "ECDSA"))
|
|
251
190
|
throw S("ECDSA");
|
|
252
|
-
const r =
|
|
191
|
+
const r = pe(t);
|
|
253
192
|
if (e.algorithm.namedCurve !== r)
|
|
254
193
|
throw S(r, "algorithm.namedCurve");
|
|
255
194
|
break;
|
|
@@ -257,45 +196,45 @@ function _e(e, t, ...n) {
|
|
|
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 z(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 L = (e, ...t) => z("Key must be ", e, ...t);
|
|
211
|
+
function X(e, t, ...o) {
|
|
212
|
+
return z(`Key for the ${e} algorithm must be `, t, ...o);
|
|
274
213
|
}
|
|
275
|
-
const
|
|
214
|
+
const Q = (e) => G(e), g = ["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 H(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
|
+
}, E = (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]) || E(e, t, r + 1);
|
|
259
|
+
}, K = (e) => {
|
|
321
260
|
switch (!0) {
|
|
322
|
-
case
|
|
261
|
+
case E(e, [42, 134, 72, 206, 61, 3, 1, 7]):
|
|
323
262
|
return "P-256";
|
|
324
|
-
case
|
|
263
|
+
case E(e, [43, 129, 4, 0, 34]):
|
|
325
264
|
return "P-384";
|
|
326
|
-
case
|
|
265
|
+
case E(e, [43, 129, 4, 0, 35]):
|
|
327
266
|
return "P-521";
|
|
328
|
-
case
|
|
267
|
+
case E(e, [43, 101, 110]):
|
|
329
268
|
return "X25519";
|
|
330
|
-
case
|
|
269
|
+
case E(e, [43, 101, 111]):
|
|
331
270
|
return "X448";
|
|
332
|
-
case
|
|
271
|
+
case E(e, [43, 101, 112]):
|
|
333
272
|
return "Ed25519";
|
|
334
|
-
case
|
|
273
|
+
case E(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
|
+
}, Ee = 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 = K(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: K(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 U.subtle.importKey(t, i, a, !1, s);
|
|
325
|
+
}, ge = (e, t, o) => Ee(/(?:-----(?: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 ge(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 (!Q(t))
|
|
334
|
+
throw new TypeError(X(e, t, ...g, "Uint8Array"));
|
|
396
335
|
if (t.type !== "secret")
|
|
397
|
-
throw new TypeError(`${
|
|
336
|
+
throw new TypeError(`${g.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 (!Q(t))
|
|
340
|
+
throw new TypeError(X(e, t, ...g));
|
|
402
341
|
if (t.type === "secret")
|
|
403
|
-
throw new TypeError(`${
|
|
404
|
-
if (t.algorithm &&
|
|
405
|
-
throw new TypeError(`${
|
|
406
|
-
if (t.algorithm &&
|
|
407
|
-
throw new TypeError(`${
|
|
408
|
-
},
|
|
409
|
-
e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ?
|
|
342
|
+
throw new TypeError(`${g.join(" or ")} instances for asymmetric algorithms must not be of type "secret"`);
|
|
343
|
+
if (t.algorithm && o === "verify" && t.type === "private")
|
|
344
|
+
throw new TypeError(`${g.join(" or ")} instances for asymmetric algorithm verifying must be of type "public"`);
|
|
345
|
+
if (t.algorithm && o === "encrypt" && t.type === "private")
|
|
346
|
+
throw new TypeError(`${g.join(" or ")} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
347
|
+
}, _e = (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 ve(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(L(t, ...g));
|
|
406
|
+
return U.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [o]);
|
|
468
407
|
}
|
|
469
|
-
throw new TypeError(
|
|
408
|
+
throw new TypeError(L(t, ...g, "Uint8Array"));
|
|
470
409
|
}
|
|
471
|
-
const
|
|
472
|
-
const
|
|
473
|
-
|
|
474
|
-
const
|
|
410
|
+
const Ce = 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 U.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 Pe(e, t, o) {
|
|
421
|
+
if (!H(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,256 +428,319 @@ 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 && !H(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 p = C(e.protected);
|
|
437
|
+
r = JSON.parse(T.decode(p));
|
|
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 = ve(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
|
|
525
|
-
let
|
|
461
|
+
let f = !1;
|
|
462
|
+
typeof t == "function" && (t = await t(r, e), f = !0), _e(i, t, "verify");
|
|
463
|
+
const w = ue(_.encode(e.protected ?? ""), _.encode("."), typeof e.payload == "string" ? _.encode(e.payload) : e.payload);
|
|
464
|
+
let h;
|
|
526
465
|
try {
|
|
527
|
-
|
|
466
|
+
h = C(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 Ce(i, t, h, w))
|
|
471
|
+
throw new he();
|
|
472
|
+
let u;
|
|
473
|
+
if (s)
|
|
535
474
|
try {
|
|
536
|
-
|
|
475
|
+
u = C(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" ? u = _.encode(e.payload) : u = e.payload;
|
|
481
|
+
const y = { payload: u };
|
|
482
|
+
return e.protected !== void 0 && (y.protectedHeader = r), e.header !== void 0 && (y.unprotectedHeader = e.header), f ? { ...y, key: t } : y;
|
|
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 Pe({ 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), Z = 60, ee = Z * 60, J = ee * 24, He = J * 7, Ne = J * 365.25, Ue = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i, W = (e) => {
|
|
494
|
+
const t = Ue.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 * Z);
|
|
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 * ee);
|
|
581
520
|
break;
|
|
582
521
|
case "day":
|
|
583
522
|
case "days":
|
|
584
523
|
case "d":
|
|
585
|
-
|
|
524
|
+
n = Math.round(o * J);
|
|
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 * Ne);
|
|
594
533
|
break;
|
|
595
534
|
}
|
|
596
|
-
return t[1] === "-" || t[4] === "ago" ? -
|
|
597
|
-
},
|
|
535
|
+
return t[1] === "-" || t[4] === "ago" ? -n : n;
|
|
536
|
+
}, x = (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 (
|
|
542
|
+
if (!H(r))
|
|
543
|
+
throw new q("JWT Claims Set must be a top-level JSON object");
|
|
544
|
+
const { typ: n } = o;
|
|
545
|
+
if (n && (typeof e.typ != "string" || x(e.typ) !== x(n)))
|
|
607
546
|
throw new m('unexpected "typ" JWT header value', r, "typ", "check_failed");
|
|
608
|
-
const { requiredClaims:
|
|
609
|
-
|
|
610
|
-
for (const p of new Set(
|
|
547
|
+
const { requiredClaims: a = [], issuer: s, subject: i, audience: c, maxTokenAge: f } = o, w = [...a];
|
|
548
|
+
f !== void 0 && w.push("iat"), c !== void 0 && w.push("aud"), i !== void 0 && w.push("sub"), s !== void 0 && w.push("iss");
|
|
549
|
+
for (const p of new Set(w.reverse()))
|
|
611
550
|
if (!(p in r))
|
|
612
551
|
throw new m(`missing required "${p}" claim`, r, p, "missing");
|
|
613
|
-
if (
|
|
552
|
+
if (s && !(Array.isArray(s) ? s : [s]).includes(r.iss))
|
|
614
553
|
throw new m('unexpected "iss" claim value', r, "iss", "check_failed");
|
|
615
554
|
if (i && r.sub !== i)
|
|
616
555
|
throw new m('unexpected "sub" claim value', r, "sub", "check_failed");
|
|
617
|
-
if (c && !
|
|
556
|
+
if (c && !Je(r.aud, typeof c == "string" ? [c] : c))
|
|
618
557
|
throw new m('unexpected "aud" claim value', r, "aud", "check_failed");
|
|
619
|
-
let
|
|
620
|
-
switch (typeof
|
|
558
|
+
let h;
|
|
559
|
+
switch (typeof o.clockTolerance) {
|
|
621
560
|
case "string":
|
|
622
|
-
|
|
561
|
+
h = W(o.clockTolerance);
|
|
623
562
|
break;
|
|
624
563
|
case "number":
|
|
625
|
-
|
|
564
|
+
h = o.clockTolerance;
|
|
626
565
|
break;
|
|
627
566
|
case "undefined":
|
|
628
|
-
|
|
567
|
+
h = 0;
|
|
629
568
|
break;
|
|
630
569
|
default:
|
|
631
570
|
throw new TypeError("Invalid clockTolerance option type");
|
|
632
571
|
}
|
|
633
|
-
const { currentDate:
|
|
634
|
-
if ((r.iat !== void 0 ||
|
|
572
|
+
const { currentDate: u } = o, y = De(u || /* @__PURE__ */ new Date());
|
|
573
|
+
if ((r.iat !== void 0 || f) && typeof r.iat != "number")
|
|
635
574
|
throw new m('"iat" claim must be a number', r, "iat", "invalid");
|
|
636
575
|
if (r.nbf !== void 0) {
|
|
637
576
|
if (typeof r.nbf != "number")
|
|
638
577
|
throw new m('"nbf" claim must be a number', r, "nbf", "invalid");
|
|
639
|
-
if (r.nbf >
|
|
578
|
+
if (r.nbf > y + h)
|
|
640
579
|
throw new m('"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
583
|
throw new m('"exp" claim must be a number', r, "exp", "invalid");
|
|
645
|
-
if (r.exp <=
|
|
646
|
-
throw new
|
|
647
|
-
}
|
|
648
|
-
if (
|
|
649
|
-
const p =
|
|
650
|
-
if (p -
|
|
651
|
-
throw new
|
|
652
|
-
if (p < 0 -
|
|
584
|
+
if (r.exp <= y - h)
|
|
585
|
+
throw new $('"exp" claim timestamp check failed', r, "exp", "check_failed");
|
|
586
|
+
}
|
|
587
|
+
if (f) {
|
|
588
|
+
const p = y - r.iat, oe = typeof f == "number" ? f : W(f);
|
|
589
|
+
if (p - h > oe)
|
|
590
|
+
throw new $('"iat" claim timestamp check failed (too far in the past)', r, "iat", "check_failed");
|
|
591
|
+
if (p < 0 - h)
|
|
653
592
|
throw new m('"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 q("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 Ke = {
|
|
605
|
+
ID_TOKEN: "id_token"
|
|
606
|
+
}, We = {
|
|
607
|
+
CLIENT_ID: "X-Auth-ClientId"
|
|
608
|
+
}, A = {
|
|
609
|
+
ALG: "RS256",
|
|
610
|
+
USER_ID_KEY: "_id",
|
|
611
|
+
TOKEN_ID_KEY: "__raw",
|
|
612
|
+
ISSUER: "gizmette.com"
|
|
613
|
+
}, xe = `-----BEGIN PUBLIC KEY-----
|
|
614
|
+
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsF6i3Jd9fY/3COqCw/m7
|
|
615
|
+
w5PKyTYLGAI2I6SIIdpe6i6DOCbEkmDz7LdVsBqwNtVi8gvWYIj+8ol6rU3qu1v5
|
|
616
|
+
i1Jd45GSK4kzkVdgCmQZbM5ak0KI99q5wsrAIzUd+LRJ2HRvWtr5IYdsIiXaQjle
|
|
617
|
+
aMwPFOIcJH+rKfFgNcHLcaS5syp7zU1ANwZ+trgR+DifBr8TLVkBynmNeTyhDm2+
|
|
618
|
+
l0haqjMk0UoNPPE8iYBWUHQJJE1Dqstj65d6Eh5g64Pao25y4cmYJbKjiblIGEkE
|
|
619
|
+
sjqybA9mARAqh9k/eiIopecWSiffNQTwVQVd2I9ZH3BalhEXHlqFgrjz51kFqg81
|
|
620
|
+
awIDAQAB
|
|
621
|
+
-----END PUBLIC KEY-----`, N = async (e, t) => {
|
|
622
|
+
try {
|
|
623
|
+
const o = A.ALG, r = await Ae(xe, o);
|
|
624
|
+
return await Le(e, r, {
|
|
625
|
+
issuer: A.ISSUER,
|
|
626
|
+
audience: t
|
|
627
|
+
});
|
|
628
|
+
} catch {
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
function te(e, t) {
|
|
633
|
+
window.dispatchEvent(new StorageEvent("storage", { key: e, newValue: t }));
|
|
634
|
+
}
|
|
635
|
+
const j = (e, t) => {
|
|
636
|
+
const o = JSON.stringify(
|
|
637
|
+
typeof t == "function" ? t() : t
|
|
638
|
+
);
|
|
639
|
+
window.localStorage.setItem(e, o), te(e, o);
|
|
640
|
+
}, je = (e) => {
|
|
641
|
+
window.localStorage.removeItem(e), te(e, null);
|
|
642
|
+
}, M = (e) => window.localStorage.getItem(e), Me = (e) => (window.addEventListener("storage", e), () => window.removeEventListener("storage", e));
|
|
643
|
+
function Ve({
|
|
644
|
+
key: e,
|
|
645
|
+
initialValue: t
|
|
646
|
+
}) {
|
|
647
|
+
const o = () => M(e), r = I.useSyncExternalStore(
|
|
648
|
+
Me,
|
|
649
|
+
o
|
|
650
|
+
), n = I.useCallback(
|
|
651
|
+
(i) => {
|
|
652
|
+
try {
|
|
653
|
+
const c = typeof i == "function" ? i(JSON.parse(r)) : i;
|
|
654
|
+
c == null ? je(e) : j(e, c);
|
|
655
|
+
} catch (c) {
|
|
656
|
+
console.warn(c);
|
|
657
|
+
}
|
|
658
|
+
},
|
|
659
|
+
[e, r]
|
|
660
|
+
), a = I.useCallback(() => {
|
|
661
|
+
n(t);
|
|
662
|
+
}, [t, n]), s = I.useCallback(() => {
|
|
663
|
+
n(null);
|
|
664
|
+
}, [n]);
|
|
665
|
+
return I.useEffect(() => {
|
|
666
|
+
try {
|
|
667
|
+
M(e) === null && typeof t < "u" && j(e, t);
|
|
668
|
+
} catch (i) {
|
|
669
|
+
console.warn(i);
|
|
670
|
+
}
|
|
671
|
+
}, [e, t]), [r ? JSON.parse(r) : null, n, a, s];
|
|
672
|
+
}
|
|
673
|
+
const V = "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>.", B = {
|
|
674
|
+
dev: "https://auth.gizmette.local.com:3003",
|
|
675
|
+
prod: "https://mylogin.gizmette.com"
|
|
676
|
+
}, Ye = "@@auth@@";
|
|
665
677
|
var d = [];
|
|
666
|
-
for (var
|
|
667
|
-
d.push((
|
|
668
|
-
function
|
|
678
|
+
for (var O = 0; O < 256; ++O)
|
|
679
|
+
d.push((O + 256).toString(16).slice(1));
|
|
680
|
+
function Ge(e, t = 0) {
|
|
669
681
|
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
682
|
}
|
|
671
|
-
var
|
|
672
|
-
function
|
|
673
|
-
if (!
|
|
683
|
+
var R, qe = new Uint8Array(16);
|
|
684
|
+
function ze() {
|
|
685
|
+
if (!R && (R = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !R))
|
|
674
686
|
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
675
|
-
return
|
|
687
|
+
return R(qe);
|
|
676
688
|
}
|
|
677
|
-
var
|
|
689
|
+
var Xe = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
678
690
|
const F = {
|
|
679
|
-
randomUUID:
|
|
691
|
+
randomUUID: Xe
|
|
680
692
|
};
|
|
681
|
-
function Qe(e, t,
|
|
693
|
+
function Qe(e, t, o) {
|
|
682
694
|
if (F.randomUUID && !t && !e)
|
|
683
695
|
return F.randomUUID();
|
|
684
696
|
e = e || {};
|
|
685
|
-
var r = e.random || (e.rng ||
|
|
686
|
-
return r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128,
|
|
697
|
+
var r = e.random || (e.rng || ze)();
|
|
698
|
+
return r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, Ge(r);
|
|
687
699
|
}
|
|
688
700
|
const Ze = process.env.NODE_ENV === "production", et = !Ze, tt = async ({ params: e = {} }) => {
|
|
689
701
|
try {
|
|
690
|
-
const t = Qe(),
|
|
691
|
-
et ? `${
|
|
702
|
+
const t = Qe(), o = await fetch(
|
|
703
|
+
et ? `${B.dev}/authenticate` : `${B.prod}/authenticate`,
|
|
692
704
|
{
|
|
693
705
|
credentials: "include",
|
|
694
706
|
method: "POST",
|
|
695
707
|
headers: {
|
|
696
708
|
"Content-Type": "application/json",
|
|
697
|
-
[
|
|
709
|
+
[We.CLIENT_ID]: `${e.clientId}`
|
|
698
710
|
},
|
|
699
711
|
body: JSON.stringify({ ...e, nonce: t })
|
|
700
712
|
}
|
|
701
713
|
);
|
|
702
|
-
if (
|
|
703
|
-
return { status:
|
|
704
|
-
const { data: r, errors:
|
|
714
|
+
if (o.status !== 200)
|
|
715
|
+
return { status: o.status, data: [] };
|
|
716
|
+
const { data: r, errors: n } = await o.json();
|
|
705
717
|
return r.nonce !== t ? { status: 500, data: [] } : {
|
|
706
|
-
status:
|
|
718
|
+
status: o.status,
|
|
707
719
|
data: r,
|
|
708
|
-
errors:
|
|
720
|
+
errors: n
|
|
709
721
|
};
|
|
710
722
|
} catch (t) {
|
|
711
723
|
return console.error(t), { status: 500, data: [] };
|
|
712
724
|
}
|
|
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
725
|
}, rt = async ({
|
|
724
726
|
username: e,
|
|
725
727
|
password: t,
|
|
726
|
-
clientId:
|
|
728
|
+
clientId: o,
|
|
727
729
|
sessionExpiration: r
|
|
728
730
|
}) => {
|
|
729
731
|
try {
|
|
730
|
-
const
|
|
732
|
+
const n = await tt({
|
|
731
733
|
params: {
|
|
732
|
-
type:
|
|
734
|
+
type: Ke.ID_TOKEN,
|
|
733
735
|
username: e,
|
|
734
736
|
password: t,
|
|
735
737
|
sessionExpiration: r,
|
|
736
|
-
clientId:
|
|
738
|
+
clientId: o
|
|
737
739
|
}
|
|
738
|
-
}),
|
|
739
|
-
return
|
|
740
|
-
idToken:
|
|
741
|
-
userId:
|
|
740
|
+
}), a = await N(n.data.idToken, o);
|
|
741
|
+
return a && a.payload[A.USER_ID_KEY] !== "" ? {
|
|
742
|
+
idToken: n.data.idToken,
|
|
743
|
+
userId: a.payload[A.USER_ID_KEY],
|
|
742
744
|
status: !0
|
|
743
745
|
} : {
|
|
744
746
|
status: !1
|
|
@@ -749,77 +751,90 @@ const Ze = process.env.NODE_ENV === "production", et = !Ze, tt = async ({ params
|
|
|
749
751
|
};
|
|
750
752
|
}
|
|
751
753
|
};
|
|
752
|
-
function
|
|
754
|
+
function ot(e) {
|
|
753
755
|
const t = ae();
|
|
754
756
|
return Y(() => {
|
|
755
757
|
t.current = e;
|
|
756
758
|
}), t.current;
|
|
757
759
|
}
|
|
758
|
-
const
|
|
759
|
-
throw new Error(
|
|
760
|
-
},
|
|
760
|
+
const D = () => {
|
|
761
|
+
throw new Error(Fe);
|
|
762
|
+
}, re = se({
|
|
761
763
|
isAuthenticated: !1,
|
|
762
|
-
login:
|
|
763
|
-
logout:
|
|
764
|
-
|
|
765
|
-
refreshToken: void 0,
|
|
766
|
-
idToken: void 0,
|
|
764
|
+
login: D,
|
|
765
|
+
logout: D,
|
|
766
|
+
getIdTokenClaims: D,
|
|
767
767
|
logoutReason: ""
|
|
768
|
-
}),
|
|
768
|
+
}), it = ({
|
|
769
769
|
children: e,
|
|
770
770
|
sessionExpiration: t,
|
|
771
|
-
clientId:
|
|
771
|
+
clientId: o
|
|
772
772
|
}) => {
|
|
773
|
-
const [r,
|
|
774
|
-
key: `${
|
|
775
|
-
}), [
|
|
773
|
+
const [r, n, , a] = Ve({
|
|
774
|
+
key: `${Ye}::${o}::@@user@@`
|
|
775
|
+
}), [s, i] = ie({
|
|
776
776
|
isAuthenticated: !!r,
|
|
777
777
|
logoutReason: "",
|
|
778
778
|
userId: ""
|
|
779
|
-
}), c =
|
|
779
|
+
}), c = ot(r) || "";
|
|
780
780
|
Y(() => {
|
|
781
781
|
c !== r && r !== null && (async () => {
|
|
782
782
|
try {
|
|
783
|
-
const u = await
|
|
783
|
+
const u = await N(r, o);
|
|
784
784
|
u && u.payload[A.USER_ID_KEY] !== "" ? i({
|
|
785
785
|
isAuthenticated: !0,
|
|
786
786
|
logoutReason: "",
|
|
787
787
|
userId: u.payload[A.USER_ID_KEY]
|
|
788
788
|
}) : i({
|
|
789
789
|
isAuthenticated: !1,
|
|
790
|
-
logoutReason:
|
|
790
|
+
logoutReason: V,
|
|
791
791
|
userId: ""
|
|
792
792
|
});
|
|
793
793
|
} catch {
|
|
794
794
|
i({
|
|
795
795
|
isAuthenticated: !1,
|
|
796
|
-
logoutReason:
|
|
796
|
+
logoutReason: V,
|
|
797
797
|
userId: ""
|
|
798
798
|
});
|
|
799
799
|
}
|
|
800
800
|
})();
|
|
801
|
-
}, [r, c,
|
|
802
|
-
const
|
|
803
|
-
const
|
|
801
|
+
}, [r, c, o]);
|
|
802
|
+
const f = async (u, y) => {
|
|
803
|
+
const p = await rt({
|
|
804
804
|
username: u,
|
|
805
|
-
password:
|
|
806
|
-
clientId:
|
|
805
|
+
password: y,
|
|
806
|
+
clientId: o,
|
|
807
807
|
sessionExpiration: t
|
|
808
808
|
});
|
|
809
|
-
return
|
|
809
|
+
return p.status ? (n(p.idToken), i({
|
|
810
810
|
isAuthenticated: !0,
|
|
811
|
-
userId:
|
|
811
|
+
userId: p.userId
|
|
812
812
|
}), !0) : !1;
|
|
813
|
-
},
|
|
813
|
+
}, w = () => {
|
|
814
814
|
i({
|
|
815
815
|
isAuthenticated: !1,
|
|
816
|
-
logoutReason:
|
|
816
|
+
logoutReason: Be,
|
|
817
817
|
userId: ""
|
|
818
|
-
}),
|
|
818
|
+
}), a();
|
|
819
|
+
}, h = async () => {
|
|
820
|
+
if (s.isAuthenticated)
|
|
821
|
+
try {
|
|
822
|
+
const u = await N(r, o);
|
|
823
|
+
return { ...u == null ? void 0 : u.payload, [A.TOKEN_ID_KEY]: r };
|
|
824
|
+
} catch {
|
|
825
|
+
return {};
|
|
826
|
+
}
|
|
827
|
+
return {};
|
|
819
828
|
};
|
|
820
|
-
return /* @__PURE__ */
|
|
821
|
-
|
|
829
|
+
return /* @__PURE__ */ ne(
|
|
830
|
+
re.Provider,
|
|
831
|
+
{
|
|
832
|
+
value: { ...s, login: f, logout: w, getIdTokenClaims: h },
|
|
833
|
+
children: e
|
|
834
|
+
}
|
|
835
|
+
);
|
|
836
|
+
}, ct = (e = re) => ce(e);
|
|
822
837
|
export {
|
|
823
|
-
|
|
824
|
-
|
|
838
|
+
it as AuthProvider,
|
|
839
|
+
ct as useAuth
|
|
825
840
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@versini/auth-provider",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.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.3.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": "db5816d0e48518c40b0aa20ff564a88abf5bc426"
|
|
53
53
|
}
|