@versini/auth-provider 6.2.1 → 6.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { AUTH_TYPES } from '@versini/auth-common';
3
- export { AUTH_TYPES } from '@versini/auth-common';
3
+ export { AUTH_TYPES, isGranted } from '@versini/auth-common';
4
4
  import * as react from 'react';
5
5
 
6
6
  type AuthenticationTypes =
package/dist/index.js CHANGED
@@ -1,22 +1,22 @@
1
1
  var _t = Object.defineProperty;
2
2
  var vt = (e, t, n) => t in e ? _t(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
3
  var z = (e, t, n) => vt(e, typeof t != "symbol" ? t + "" : t, n);
4
- import { jsx as ke } from "react/jsx-runtime";
5
- import kt, { useSyncExternalStore as Pt, useCallback as x, useEffect as Te, createContext as Ct, useReducer as Ot, useRef as Pe, useContext as Nt } from "react";
4
+ import { jsx as Pe } from "react/jsx-runtime";
5
+ import Pt, { useSyncExternalStore as Ct, useCallback as x, useEffect as Te, createContext as kt, useReducer as Ot, useRef as Ce, useContext as Nt } from "react";
6
6
  /*!
7
- @versini/auth-provider v6.2.1
7
+ @versini/auth-provider v6.3.0
8
8
  © 2024 gizmette.com
9
9
  */
10
10
  try {
11
11
  window.__VERSINI_AUTH_CLIENT__ || (window.__VERSINI_AUTH_CLIENT__ = {
12
- version: "6.2.1",
13
- buildTime: "07/18/2024 12:26 PM EDT",
12
+ version: "6.3.0",
13
+ buildTime: "07/21/2024 06:09 PM EDT",
14
14
  homepage: "https://github.com/aversini/auth-client",
15
15
  license: "MIT"
16
16
  });
17
17
  } catch {
18
18
  }
19
- function k(e) {
19
+ function P(e) {
20
20
  const t = new Uint8Array(e);
21
21
  let n = "";
22
22
  for (const a of t)
@@ -32,7 +32,7 @@ function ie(e) {
32
32
  function Re() {
33
33
  return (window == null ? void 0 : window.PublicKeyCredential) !== void 0 && typeof window.PublicKeyCredential == "function";
34
34
  }
35
- function Ve(e) {
35
+ function Ye(e) {
36
36
  const { id: t } = e;
37
37
  return {
38
38
  ...e,
@@ -40,10 +40,10 @@ function Ve(e) {
40
40
  transports: e.transports
41
41
  };
42
42
  }
43
- function Ye(e) {
43
+ function Ve(e) {
44
44
  return e === "localhost" || /^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i.test(e);
45
45
  }
46
- class b extends Error {
46
+ class I extends Error {
47
47
  constructor({ message: t, code: n, cause: r, name: a }) {
48
48
  super(t, { cause: r }), this.name = a ?? r.name, this.code = n;
49
49
  }
@@ -55,70 +55,70 @@ function Dt({ error: e, options: t }) {
55
55
  throw Error("options was missing required publicKey property");
56
56
  if (e.name === "AbortError") {
57
57
  if (t.signal instanceof AbortSignal)
58
- return new b({
58
+ return new I({
59
59
  message: "Registration ceremony was sent an abort signal",
60
60
  code: "ERROR_CEREMONY_ABORTED",
61
61
  cause: e
62
62
  });
63
63
  } else if (e.name === "ConstraintError") {
64
64
  if (((r = n.authenticatorSelection) == null ? void 0 : r.requireResidentKey) === !0)
65
- return new b({
65
+ return new I({
66
66
  message: "Discoverable credentials were required but no available authenticator supported it",
67
67
  code: "ERROR_AUTHENTICATOR_MISSING_DISCOVERABLE_CREDENTIAL_SUPPORT",
68
68
  cause: e
69
69
  });
70
70
  if (((a = n.authenticatorSelection) == null ? void 0 : a.userVerification) === "required")
71
- return new b({
71
+ return new I({
72
72
  message: "User verification was required but no available authenticator supported it",
73
73
  code: "ERROR_AUTHENTICATOR_MISSING_USER_VERIFICATION_SUPPORT",
74
74
  cause: e
75
75
  });
76
76
  } else {
77
77
  if (e.name === "InvalidStateError")
78
- return new b({
78
+ return new I({
79
79
  message: "The authenticator was previously registered",
80
80
  code: "ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED",
81
81
  cause: e
82
82
  });
83
83
  if (e.name === "NotAllowedError")
84
- return new b({
84
+ return new I({
85
85
  message: e.message,
86
86
  code: "ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY",
87
87
  cause: e
88
88
  });
89
89
  if (e.name === "NotSupportedError")
90
- return n.pubKeyCredParams.filter((o) => o.type === "public-key").length === 0 ? new b({
90
+ return n.pubKeyCredParams.filter((o) => o.type === "public-key").length === 0 ? new I({
91
91
  message: 'No entry in pubKeyCredParams was of type "public-key"',
92
92
  code: "ERROR_MALFORMED_PUBKEYCREDPARAMS",
93
93
  cause: e
94
- }) : new b({
94
+ }) : new I({
95
95
  message: "No available authenticator supported any of the specified pubKeyCredParams algorithms",
96
96
  code: "ERROR_AUTHENTICATOR_NO_SUPPORTED_PUBKEYCREDPARAMS_ALG",
97
97
  cause: e
98
98
  });
99
99
  if (e.name === "SecurityError") {
100
100
  const s = window.location.hostname;
101
- if (Ye(s)) {
101
+ if (Ve(s)) {
102
102
  if (n.rp.id !== s)
103
- return new b({
103
+ return new I({
104
104
  message: `The RP ID "${n.rp.id}" is invalid for this domain`,
105
105
  code: "ERROR_INVALID_RP_ID",
106
106
  cause: e
107
107
  });
108
- } else return new b({
108
+ } else return new I({
109
109
  message: `${window.location.hostname} is an invalid domain`,
110
110
  code: "ERROR_INVALID_DOMAIN",
111
111
  cause: e
112
112
  });
113
113
  } else if (e.name === "TypeError") {
114
114
  if (n.user.id.byteLength < 1 || n.user.id.byteLength > 64)
115
- return new b({
115
+ return new I({
116
116
  message: "User ID was not between 1 and 64 characters",
117
117
  code: "ERROR_INVALID_USER_ID_LENGTH",
118
118
  cause: e
119
119
  });
120
120
  } else if (e.name === "UnknownError")
121
- return new b({
121
+ return new I({
122
122
  message: "The authenticator was unable to process the specified options, or could not create a new credential",
123
123
  code: "ERROR_AUTHENTICATOR_GENERAL_ERROR",
124
124
  cause: e
@@ -158,7 +158,7 @@ async function Kt(e) {
158
158
  ...e.user,
159
159
  id: ie(e.user.id)
160
160
  },
161
- excludeCredentials: (p = e.excludeCredentials) == null ? void 0 : p.map(Ve)
161
+ excludeCredentials: (p = e.excludeCredentials) == null ? void 0 : p.map(Ye)
162
162
  } };
163
163
  n.signal = je.createNewAbortSignal();
164
164
  let r;
@@ -183,23 +183,23 @@ async function Kt(e) {
183
183
  if (typeof o.getPublicKey == "function")
184
184
  try {
185
185
  const l = o.getPublicKey();
186
- l !== null && (y = k(l));
186
+ l !== null && (y = P(l));
187
187
  } catch (l) {
188
188
  fe("getPublicKey()", l);
189
189
  }
190
190
  let h;
191
191
  if (typeof o.getAuthenticatorData == "function")
192
192
  try {
193
- h = k(o.getAuthenticatorData());
193
+ h = P(o.getAuthenticatorData());
194
194
  } catch (l) {
195
195
  fe("getAuthenticatorData()", l);
196
196
  }
197
197
  return {
198
198
  id: a,
199
- rawId: k(s),
199
+ rawId: P(s),
200
200
  response: {
201
- attestationObject: k(o.attestationObject),
202
- clientDataJSON: k(o.clientDataJSON),
201
+ attestationObject: P(o.attestationObject),
202
+ clientDataJSON: P(o.clientDataJSON),
203
203
  transports: u,
204
204
  publicKeyAlgorithm: f,
205
205
  publicKey: y,
@@ -226,34 +226,34 @@ function Lt({ error: e, options: t }) {
226
226
  throw Error("options was missing required publicKey property");
227
227
  if (e.name === "AbortError") {
228
228
  if (t.signal instanceof AbortSignal)
229
- return new b({
229
+ return new I({
230
230
  message: "Authentication ceremony was sent an abort signal",
231
231
  code: "ERROR_CEREMONY_ABORTED",
232
232
  cause: e
233
233
  });
234
234
  } else {
235
235
  if (e.name === "NotAllowedError")
236
- return new b({
236
+ return new I({
237
237
  message: e.message,
238
238
  code: "ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY",
239
239
  cause: e
240
240
  });
241
241
  if (e.name === "SecurityError") {
242
242
  const r = window.location.hostname;
243
- if (Ye(r)) {
243
+ if (Ve(r)) {
244
244
  if (n.rpId !== r)
245
- return new b({
245
+ return new I({
246
246
  message: `The RP ID "${n.rpId}" is invalid for this domain`,
247
247
  code: "ERROR_INVALID_RP_ID",
248
248
  cause: e
249
249
  });
250
- } else return new b({
250
+ } else return new I({
251
251
  message: `${window.location.hostname} is an invalid domain`,
252
252
  code: "ERROR_INVALID_DOMAIN",
253
253
  cause: e
254
254
  });
255
255
  } else if (e.name === "UnknownError")
256
- return new b({
256
+ return new I({
257
257
  message: "The authenticator was unable to process the specified options, or could not create a new assertion signature",
258
258
  code: "ERROR_AUTHENTICATOR_GENERAL_ERROR",
259
259
  cause: e
@@ -266,7 +266,7 @@ async function Wt(e, t = !1) {
266
266
  if (!Re())
267
267
  throw new Error("WebAuthn is not supported in this browser");
268
268
  let n;
269
- ((h = e.allowCredentials) == null ? void 0 : h.length) !== 0 && (n = (p = e.allowCredentials) == null ? void 0 : p.map(Ve));
269
+ ((h = e.allowCredentials) == null ? void 0 : h.length) !== 0 && (n = (p = e.allowCredentials) == null ? void 0 : p.map(Ye));
270
270
  const r = {
271
271
  ...e,
272
272
  challenge: ie(e.challenge),
@@ -290,13 +290,13 @@ async function Wt(e, t = !1) {
290
290
  throw new Error("Authentication was not completed");
291
291
  const { id: o, rawId: i, response: u, type: f } = s;
292
292
  let y;
293
- return u.userHandle && (y = k(u.userHandle)), {
293
+ return u.userHandle && (y = P(u.userHandle)), {
294
294
  id: o,
295
- rawId: k(i),
295
+ rawId: P(i),
296
296
  response: {
297
- authenticatorData: k(u.authenticatorData),
298
- clientDataJSON: k(u.clientDataJSON),
299
- signature: k(u.signature),
297
+ authenticatorData: P(u.authenticatorData),
298
+ clientDataJSON: P(u.clientDataJSON),
299
+ signature: P(u.signature),
300
300
  userHandle: y
301
301
  },
302
302
  type: f,
@@ -305,19 +305,19 @@ async function Wt(e, t = !1) {
305
305
  };
306
306
  }
307
307
  /*!
308
- @versini/auth-common v2.12.1
308
+ @versini/auth-common v3.2.0
309
309
  © 2024 gizmette.com
310
310
  */
311
311
  try {
312
312
  window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
313
- version: "2.12.1",
314
- buildTime: "07/18/2024 12:26 PM EDT",
313
+ version: "3.2.0",
314
+ buildTime: "07/21/2024 06:09 PM EDT",
315
315
  homepage: "https://github.com/aversini/auth-client",
316
316
  license: "MIT"
317
317
  });
318
318
  } catch {
319
319
  }
320
- const j = {
320
+ const F = {
321
321
  ID_TOKEN: "id_token",
322
322
  ACCESS_TOKEN: "token",
323
323
  ID_AND_ACCESS_TOKEN: "id_token token",
@@ -326,13 +326,16 @@ const j = {
326
326
  PASSKEY: "passkey"
327
327
  }, Be = {
328
328
  CLIENT_ID: "X-Auth-ClientId"
329
- }, I = {
329
+ }, b = {
330
330
  ALG: "RS256",
331
331
  USER_ID_KEY: "sub",
332
332
  TOKEN_ID_KEY: "__raw",
333
333
  NONCE_KEY: "_nonce",
334
334
  USERNAME_KEY: "username",
335
335
  AUTH_TYPE_KEY: "auth_type",
336
+ EXPIRES_AT_KEY: "exp",
337
+ CREATED_AT_KEY: "iat",
338
+ SCOPES_KEY: "scopes",
336
339
  ISSUER: "gizmette.com"
337
340
  }, xt = `-----BEGIN PUBLIC KEY-----
338
341
  MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsF6i3Jd9fY/3COqCw/m7
@@ -359,7 +362,7 @@ const Gt = (e) => {
359
362
  for (let r = 0; r < t.length; r++)
360
363
  n[r] = t.charCodeAt(r);
361
364
  return n;
362
- }, Y = (e) => {
365
+ }, j = (e) => {
363
366
  let t = e;
364
367
  t instanceof Uint8Array && (t = B.decode(t)), t = t.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
365
368
  try {
@@ -383,7 +386,7 @@ let U = class extends Error {
383
386
  constructor(t, n, r = "unspecified", a = "unspecified") {
384
387
  super(t), this.code = "ERR_JWT_CLAIM_VALIDATION_FAILED", this.claim = r, this.reason = a, this.payload = n;
385
388
  }
386
- }, Ce = class extends U {
389
+ }, ke = class extends U {
387
390
  static get code() {
388
391
  return "ERR_JWT_EXPIRED";
389
392
  }
@@ -415,7 +418,7 @@ class R extends U {
415
418
  return "ERR_JWS_INVALID";
416
419
  }
417
420
  }
418
- let C = class extends U {
421
+ let k = class extends U {
419
422
  constructor() {
420
423
  super(...arguments), this.code = "ERR_JWT_INVALID";
421
424
  }
@@ -423,7 +426,7 @@ let C = class extends U {
423
426
  return "ERR_JWT_INVALID";
424
427
  }
425
428
  };
426
- class Vt extends U {
429
+ class Yt extends U {
427
430
  constructor() {
428
431
  super(...arguments), this.code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED", this.message = "signature verification failed";
429
432
  }
@@ -431,7 +434,7 @@ class Vt extends U {
431
434
  return "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
432
435
  }
433
436
  }
434
- function P(e, t = "algorithm.name") {
437
+ function C(e, t = "algorithm.name") {
435
438
  return new TypeError(`CryptoKey does not support this operation, its ${t} must be ${e}`);
436
439
  }
437
440
  function X(e, t) {
@@ -440,7 +443,7 @@ function X(e, t) {
440
443
  function ye(e) {
441
444
  return parseInt(e.name.slice(4), 10);
442
445
  }
443
- function Yt(e) {
446
+ function Vt(e) {
444
447
  switch (e) {
445
448
  case "ES256":
446
449
  return "P-256";
@@ -468,45 +471,45 @@ function Ft(e, t, ...n) {
468
471
  case "HS384":
469
472
  case "HS512": {
470
473
  if (!X(e.algorithm, "HMAC"))
471
- throw P("HMAC");
474
+ throw C("HMAC");
472
475
  const r = parseInt(t.slice(2), 10);
473
476
  if (ye(e.algorithm.hash) !== r)
474
- throw P(`SHA-${r}`, "algorithm.hash");
477
+ throw C(`SHA-${r}`, "algorithm.hash");
475
478
  break;
476
479
  }
477
480
  case "RS256":
478
481
  case "RS384":
479
482
  case "RS512": {
480
483
  if (!X(e.algorithm, "RSASSA-PKCS1-v1_5"))
481
- throw P("RSASSA-PKCS1-v1_5");
484
+ throw C("RSASSA-PKCS1-v1_5");
482
485
  const r = parseInt(t.slice(2), 10);
483
486
  if (ye(e.algorithm.hash) !== r)
484
- throw P(`SHA-${r}`, "algorithm.hash");
487
+ throw C(`SHA-${r}`, "algorithm.hash");
485
488
  break;
486
489
  }
487
490
  case "PS256":
488
491
  case "PS384":
489
492
  case "PS512": {
490
493
  if (!X(e.algorithm, "RSA-PSS"))
491
- throw P("RSA-PSS");
494
+ throw C("RSA-PSS");
492
495
  const r = parseInt(t.slice(2), 10);
493
496
  if (ye(e.algorithm.hash) !== r)
494
- throw P(`SHA-${r}`, "algorithm.hash");
497
+ throw C(`SHA-${r}`, "algorithm.hash");
495
498
  break;
496
499
  }
497
500
  case "EdDSA": {
498
501
  if (e.algorithm.name !== "Ed25519" && e.algorithm.name !== "Ed448")
499
- throw P("Ed25519 or Ed448");
502
+ throw C("Ed25519 or Ed448");
500
503
  break;
501
504
  }
502
505
  case "ES256":
503
506
  case "ES384":
504
507
  case "ES512": {
505
508
  if (!X(e.algorithm, "ECDSA"))
506
- throw P("ECDSA");
507
- const r = Yt(t);
509
+ throw C("ECDSA");
510
+ const r = Vt(t);
508
511
  if (e.algorithm.namedCurve !== r)
509
- throw P(r, "algorithm.namedCurve");
512
+ throw C(r, "algorithm.namedCurve");
510
513
  break;
511
514
  }
512
515
  default:
@@ -646,7 +649,7 @@ const Xt = async (e) => {
646
649
  e.key_ops ?? n
647
650
  ], a = { ...e };
648
651
  return delete a.alg, delete a.use, he.subtle.importKey("jwk", a, ...r);
649
- }, Ze = (e) => Y(e);
652
+ }, Ze = (e) => j(e);
650
653
  let ge, me;
651
654
  const et = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject", tt = async (e, t, n, r) => {
652
655
  let a = e.get(t);
@@ -850,7 +853,7 @@ async function fn(e, t, n) {
850
853
  let r = {};
851
854
  if (e.protected)
852
855
  try {
853
- const d = Y(e.protected);
856
+ const d = j(e.protected);
854
857
  r = JSON.parse(B.decode(d));
855
858
  } catch {
856
859
  throw new R("JWS Protected Header is invalid");
@@ -880,16 +883,16 @@ async function fn(e, t, n) {
880
883
  const y = Mt(Q.encode(e.protected ?? ""), Q.encode("."), typeof e.payload == "string" ? Q.encode(e.payload) : e.payload);
881
884
  let h;
882
885
  try {
883
- h = Y(e.signature);
886
+ h = j(e.signature);
884
887
  } catch {
885
888
  throw new R("Failed to base64url decode the signature");
886
889
  }
887
890
  if (!await pn(i, t, h, y))
888
- throw new Vt();
891
+ throw new Yt();
889
892
  let p;
890
893
  if (o)
891
894
  try {
892
- p = Y(e.payload);
895
+ p = j(e.payload);
893
896
  } catch {
894
897
  throw new R("Failed to base64url decode the payload");
895
898
  }
@@ -956,7 +959,7 @@ const gn = (e) => Math.floor(e.getTime() / 1e3), nt = 60, rt = nt * 60, be = rt
956
959
  } catch {
957
960
  }
958
961
  if (!ue(r))
959
- throw new C("JWT Claims Set must be a top-level JSON object");
962
+ throw new k("JWT Claims Set must be a top-level JSON object");
960
963
  const { typ: a } = n;
961
964
  if (a && (typeof e.typ != "string" || Ue(e.typ) !== Ue(a)))
962
965
  throw new v('unexpected "typ" JWT header value', r, "typ", "check_failed");
@@ -998,12 +1001,12 @@ const gn = (e) => Math.floor(e.getTime() / 1e3), nt = 60, rt = nt * 60, be = rt
998
1001
  if (typeof r.exp != "number")
999
1002
  throw new v('"exp" claim must be a number', r, "exp", "invalid");
1000
1003
  if (r.exp <= l - h)
1001
- throw new Ce('"exp" claim timestamp check failed', r, "exp", "check_failed");
1004
+ throw new ke('"exp" claim timestamp check failed', r, "exp", "check_failed");
1002
1005
  }
1003
1006
  if (f) {
1004
1007
  const d = l - r.iat, m = typeof f == "number" ? f : De(f);
1005
1008
  if (d - h > m)
1006
- throw new Ce('"iat" claim timestamp check failed (too far in the past)', r, "iat", "check_failed");
1009
+ throw new ke('"iat" claim timestamp check failed (too far in the past)', r, "iat", "check_failed");
1007
1010
  if (d < 0 - h)
1008
1011
  throw new v('"iat" claim timestamp check failed (it should be in the past)', r, "iat", "check_failed");
1009
1012
  }
@@ -1013,42 +1016,42 @@ async function Tn(e, t, n) {
1013
1016
  var r;
1014
1017
  const a = await yn(e, t, n);
1015
1018
  if ((r = a.protectedHeader.crit) != null && r.includes("b64") && a.protectedHeader.b64 === !1)
1016
- throw new C("JWTs MUST NOT use unencoded payload");
1019
+ throw new k("JWTs MUST NOT use unencoded payload");
1017
1020
  const s = { payload: An(a.protectedHeader, a.payload, n), protectedHeader: a.protectedHeader };
1018
1021
  return typeof t == "function" ? { ...s, key: a.key } : s;
1019
1022
  }
1020
- const Rn = Y;
1023
+ const Rn = j;
1021
1024
  function bn(e) {
1022
1025
  if (typeof e != "string")
1023
- throw new C("JWTs must use Compact JWS serialization, JWT must be a string");
1026
+ throw new k("JWTs must use Compact JWS serialization, JWT must be a string");
1024
1027
  const { 1: t, length: n } = e.split(".");
1025
1028
  if (n === 5)
1026
- throw new C("Only JWTs using Compact JWS serialization can be decoded");
1029
+ throw new k("Only JWTs using Compact JWS serialization can be decoded");
1027
1030
  if (n !== 3)
1028
- throw new C("Invalid JWT");
1031
+ throw new k("Invalid JWT");
1029
1032
  if (!t)
1030
- throw new C("JWTs must contain a payload");
1033
+ throw new k("JWTs must contain a payload");
1031
1034
  let r;
1032
1035
  try {
1033
1036
  r = Rn(t);
1034
1037
  } catch {
1035
- throw new C("Failed to base64url decode the payload");
1038
+ throw new k("Failed to base64url decode the payload");
1036
1039
  }
1037
1040
  let a;
1038
1041
  try {
1039
1042
  a = JSON.parse(B.decode(r));
1040
1043
  } catch {
1041
- throw new C("Failed to parse the decoded payload as JSON");
1044
+ throw new k("Failed to parse the decoded payload as JSON");
1042
1045
  }
1043
1046
  if (!ue(a))
1044
- throw new C("Invalid JWT Claims Set");
1047
+ throw new k("Invalid JWT Claims Set");
1045
1048
  return a;
1046
1049
  }
1047
- const F = async (e) => {
1050
+ const M = async (e) => {
1048
1051
  try {
1049
- const t = I.ALG, n = await an(xt, t);
1052
+ const t = b.ALG, n = await an(xt, t);
1050
1053
  return await Tn(e, n, {
1051
- issuer: I.ISSUER
1054
+ issuer: b.ISSUER
1052
1055
  });
1053
1056
  } catch {
1054
1057
  return;
@@ -1067,23 +1070,23 @@ function _n(e, t = 0) {
1067
1070
  return (A[e[t + 0]] + A[e[t + 1]] + A[e[t + 2]] + A[e[t + 3]] + "-" + A[e[t + 4]] + A[e[t + 5]] + "-" + A[e[t + 6]] + A[e[t + 7]] + "-" + A[e[t + 8]] + A[e[t + 9]] + "-" + A[e[t + 10]] + A[e[t + 11]] + A[e[t + 12]] + A[e[t + 13]] + A[e[t + 14]] + A[e[t + 15]]).toLowerCase();
1068
1071
  }
1069
1072
  var Z, vn = new Uint8Array(16);
1070
- function kn() {
1073
+ function Pn() {
1071
1074
  if (!Z && (Z = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !Z))
1072
1075
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
1073
1076
  return Z(vn);
1074
1077
  }
1075
- var Pn = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
1078
+ var Cn = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
1076
1079
  const $e = {
1077
- randomUUID: Pn
1080
+ randomUUID: Cn
1078
1081
  };
1079
1082
  function Ke(e, t, n) {
1080
1083
  if ($e.randomUUID && !t && !e)
1081
1084
  return $e.randomUUID();
1082
1085
  e = e || {};
1083
- var r = e.random || (e.rng || kn)();
1086
+ var r = e.random || (e.rng || Pn)();
1084
1087
  return r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, _n(r);
1085
1088
  }
1086
- const He = globalThis.crypto, Cn = (e) => `${Ke()}${Ke()}`.slice(0, e), On = (e) => btoa(
1089
+ const He = globalThis.crypto, kn = (e) => `${Ke()}${Ke()}`.slice(0, e), On = (e) => btoa(
1087
1090
  [...new Uint8Array(e)].map((t) => String.fromCharCode(t)).join("")
1088
1091
  );
1089
1092
  async function Nn(e) {
@@ -1095,12 +1098,21 @@ async function Nn(e) {
1095
1098
  return On(n).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
1096
1099
  }
1097
1100
  async function Dn(e) {
1098
- const n = Cn(43), r = await Nn(n);
1101
+ const n = kn(43), r = await Nn(n);
1099
1102
  return {
1100
1103
  code_verifier: n,
1101
1104
  code_challenge: r
1102
1105
  };
1103
1106
  }
1107
+ const Cr = async (e, t) => {
1108
+ var n, r;
1109
+ const a = await M(e);
1110
+ if ((r = a && ((n = a == null ? void 0 : a.payload) == null ? void 0 : n[b.SCOPES_KEY])) != null && r.length) {
1111
+ const s = a.payload[b.SCOPES_KEY];
1112
+ return t.every((o) => s.includes(o));
1113
+ }
1114
+ return !1;
1115
+ };
1104
1116
  function at(e, t) {
1105
1117
  window.dispatchEvent(new StorageEvent("storage", { key: e, newValue: t }));
1106
1118
  }
@@ -1116,7 +1128,7 @@ function ee({
1116
1128
  key: e,
1117
1129
  initialValue: t
1118
1130
  }) {
1119
- const n = Pt($n, () => We(e)), r = x(
1131
+ const n = Ct($n, () => We(e)), r = x(
1120
1132
  (o) => {
1121
1133
  try {
1122
1134
  const i = typeof o == "function" ? o(JSON.parse(n)) : o;
@@ -1246,11 +1258,11 @@ const Gn = {
1246
1258
  }
1247
1259
  });
1248
1260
  }
1249
- }), st = { browser: "" }, Vn = async (e) => typeof navigator > "u" ? st : { browser: navigator.userAgent }, it = {
1261
+ }), st = { browser: "" }, Yn = async (e) => typeof navigator > "u" ? st : { browser: navigator.userAgent }, it = {
1250
1262
  canvas: {
1251
1263
  data: ""
1252
1264
  }
1253
- }, Yn = async (e) => {
1265
+ }, Vn = async (e) => {
1254
1266
  try {
1255
1267
  const t = Array.from(
1256
1268
  { length: 3 },
@@ -1491,8 +1503,8 @@ const cr = async (e) => {
1491
1503
  try {
1492
1504
  return Promise.all([
1493
1505
  Jn(),
1494
- Vn(),
1495
1506
  Yn(),
1507
+ Vn(),
1496
1508
  Xn(),
1497
1509
  rr(),
1498
1510
  or(),
@@ -1521,10 +1533,10 @@ const cr = async (e) => {
1521
1533
  }, ne = "Oops! It looks like your session has expired. For your security, please log in again to continue.", dr = "Your session has been successfully terminated.", re = "Login failed. Please try again.", Ae = "Error getting access token, please re-authenticate.", hr = "You forgot to wrap your component in <AuthProvider>.", le = {
1522
1534
  dev: "https://auth.gizmette.local.com:3003",
1523
1535
  prod: "https://mylogin.gizmette.com/auth"
1524
- }, ae = "@@auth@@", J = "LOADING", V = "LOGIN", ht = "LOGOUT", pr = process.env.NODE_ENV === "production", pt = !pr, fr = (e) => {
1536
+ }, ae = "@@auth@@", Y = "LOADING", V = "LOGIN", ht = "LOGOUT", pr = process.env.NODE_ENV === "production", pt = !pr, fr = (e) => {
1525
1537
  try {
1526
1538
  const t = In(e);
1527
- return t ? t[I.USER_ID_KEY] : "";
1539
+ return t ? t[b.USER_ID_KEY] : "";
1528
1540
  } catch {
1529
1541
  return "";
1530
1542
  }
@@ -1601,7 +1613,7 @@ const cr = async (e) => {
1601
1613
  type: de.AUTHENTICATE,
1602
1614
  clientId: n,
1603
1615
  params: {
1604
- type: a || j.ID_AND_ACCESS_TOKEN,
1616
+ type: a || F.ID_AND_ACCESS_TOKEN,
1605
1617
  username: e,
1606
1618
  password: t,
1607
1619
  sessionExpiration: s,
@@ -1611,12 +1623,12 @@ const cr = async (e) => {
1611
1623
  domain: u,
1612
1624
  fingerprint: f
1613
1625
  }
1614
- }), h = await F(y.data.idToken);
1615
- return h && h.payload[I.USER_ID_KEY] !== "" && h.payload[I.NONCE_KEY] === r ? {
1626
+ }), h = await M(y.data.idToken);
1627
+ return h && h.payload[b.USER_ID_KEY] !== "" && h.payload[b.NONCE_KEY] === r ? {
1616
1628
  idToken: y.data.idToken,
1617
1629
  accessToken: y.data.accessToken,
1618
1630
  refreshToken: y.data.refreshToken,
1619
- userId: h.payload[I.USER_ID_KEY],
1631
+ userId: h.payload[b.USER_ID_KEY],
1620
1632
  status: !0
1621
1633
  } : {
1622
1634
  status: !1
@@ -1636,7 +1648,7 @@ const cr = async (e) => {
1636
1648
  type: de.CODE,
1637
1649
  clientId: t,
1638
1650
  params: {
1639
- type: j.CODE,
1651
+ type: F.CODE,
1640
1652
  nonce: e,
1641
1653
  code_challenge: n
1642
1654
  }
@@ -1665,7 +1677,7 @@ const cr = async (e) => {
1665
1677
  type: de.AUTHENTICATE,
1666
1678
  clientId: e,
1667
1679
  params: {
1668
- type: j.REFRESH_TOKEN,
1680
+ type: F.REFRESH_TOKEN,
1669
1681
  userId: t,
1670
1682
  nonce: n,
1671
1683
  refreshToken: r,
@@ -1673,11 +1685,11 @@ const cr = async (e) => {
1673
1685
  domain: s,
1674
1686
  fingerprint: await ft()
1675
1687
  }
1676
- }), i = await F(o.data.accessToken);
1677
- return i && i.payload[I.USER_ID_KEY] !== "" && i.payload[I.NONCE_KEY] === n ? {
1688
+ }), i = await M(o.data.accessToken);
1689
+ return i && i.payload[b.USER_ID_KEY] !== "" && i.payload[b.NONCE_KEY] === n ? {
1678
1690
  accessToken: o.data.accessToken,
1679
1691
  refreshToken: o.data.refreshToken,
1680
- userId: i.payload[I.USER_ID_KEY],
1692
+ userId: i.payload[b.USER_ID_KEY],
1681
1693
  status: !0
1682
1694
  } : {
1683
1695
  status: !1
@@ -1852,8 +1864,8 @@ class wr {
1852
1864
  nonce: r,
1853
1865
  domain: a
1854
1866
  }) {
1855
- const s = await F(this.refreshToken);
1856
- if (s && s.payload[I.USER_ID_KEY] !== "") {
1867
+ const s = await M(this.refreshToken);
1868
+ if (s && s.payload[b.USER_ID_KEY] !== "") {
1857
1869
  const o = await mr({
1858
1870
  clientId: t,
1859
1871
  userId: n,
@@ -1877,7 +1889,7 @@ class wr {
1877
1889
  }
1878
1890
  const W = () => {
1879
1891
  throw new Error(hr);
1880
- }, yt = Ct({
1892
+ }, yt = kt({
1881
1893
  isAuthenticated: !1,
1882
1894
  isLoading: !1,
1883
1895
  authenticationType: null,
@@ -1888,7 +1900,7 @@ const W = () => {
1888
1900
  registeringForPasskey: W,
1889
1901
  loginWithPasskey: W,
1890
1902
  logoutReason: ""
1891
- }), Er = kt.createContext({
1903
+ }), Er = Pt.createContext({
1892
1904
  state: {
1893
1905
  isLoading: !0,
1894
1906
  isAuthenticated: !1,
@@ -1899,7 +1911,7 @@ const W = () => {
1899
1911
  },
1900
1912
  dispatch: () => {
1901
1913
  }
1902
- }), Sr = (e, t) => (t == null ? void 0 : t.type) === J ? {
1914
+ }), Sr = (e, t) => (t == null ? void 0 : t.type) === Y ? {
1903
1915
  ...e,
1904
1916
  isLoading: t.payload.isLoading
1905
1917
  } : (t == null ? void 0 : t.type) === V ? {
@@ -1916,7 +1928,7 @@ const W = () => {
1916
1928
  user: void 0,
1917
1929
  authenticationType: null,
1918
1930
  logoutReason: t.payload.logoutReason
1919
- } : e, Pr = ({
1931
+ } : e, kr = ({
1920
1932
  children: e,
1921
1933
  sessionExpiration: t,
1922
1934
  clientId: n,
@@ -1930,7 +1942,7 @@ const W = () => {
1930
1942
  user: void 0,
1931
1943
  logoutReason: "",
1932
1944
  debug: a
1933
- }), i = Pe(!1), u = Pe(""), [f, y, , h] = ee({
1945
+ }), i = Ce(!1), u = Ce(""), [f, y, , h] = ee({
1934
1946
  key: `${ae}::${n}::@@user@@`
1935
1947
  }), [p, l, , d] = ee({
1936
1948
  key: `${ae}::${n}::@@access@@`
@@ -1955,7 +1967,7 @@ const W = () => {
1955
1967
  payload: {
1956
1968
  logoutReason: c || ne
1957
1969
  }
1958
- }), h(), d(), q(), _e(), o({ type: J, payload: { isLoading: !1 } });
1970
+ }), h(), d(), q(), _e(), o({ type: Y, payload: { isLoading: !1 } });
1959
1971
  },
1960
1972
  [d, h, _e, q, w]
1961
1973
  ), D = x(
@@ -1990,14 +2002,14 @@ const W = () => {
1990
2002
  if (!i.current)
1991
2003
  return s.isLoading && f !== null ? (async () => {
1992
2004
  try {
1993
- const c = await F(f);
1994
- c && c.payload[I.USER_ID_KEY] !== "" ? (w("useEffect: setting the authentication state"), o({
2005
+ const c = await M(f);
2006
+ c && c.payload[b.USER_ID_KEY] !== "" ? (w("useEffect: setting the authentication state"), o({
1995
2007
  type: V,
1996
2008
  payload: {
1997
- authenticationType: c.payload[I.AUTH_TYPE_KEY],
2009
+ authenticationType: c.payload[b.AUTH_TYPE_KEY],
1998
2010
  user: {
1999
- userId: c.payload[I.USER_ID_KEY],
2000
- username: c.payload[I.USERNAME_KEY]
2011
+ userId: c.payload[b.USER_ID_KEY],
2012
+ username: c.payload[b.USERNAME_KEY]
2001
2013
  }
2002
2014
  }
2003
2015
  })) : (w("useEffect: invalid JWT, invalidating and logging out"), await D(ne));
@@ -2006,20 +2018,20 @@ const W = () => {
2006
2018
  "useEffect: exception validating JWT, invalidating and logging out"
2007
2019
  ), await D(ne);
2008
2020
  }
2009
- })() : (w("useEffect: setting the loading state to false"), o({ type: J, payload: { isLoading: !1 } })), () => {
2021
+ })() : (w("useEffect: setting the loading state to false"), o({ type: Y, payload: { isLoading: !1 } })), () => {
2010
2022
  i.current = !0;
2011
2023
  };
2012
2024
  }, [s.isLoading, f, D, w]);
2013
2025
  const wt = async (c, E, g) => {
2014
2026
  const _ = Se();
2015
- if (Ie(_), o({ type: J, payload: { isLoading: !0 } }), h(), d(), q(), w("login: Logging in with type: ", g), g === j.CODE) {
2027
+ if (Ie(_), o({ type: Y, payload: { isLoading: !0 } }), h(), d(), q(), w("login: Logging in with type: ", g), g === F.CODE) {
2016
2028
  const { code_verifier: bt, code_challenge: It } = await Dn(), ve = await gr({
2017
2029
  nonce: _,
2018
2030
  clientId: n,
2019
2031
  code_challenge: It
2020
2032
  });
2021
2033
  if (ve.status) {
2022
- const G = await Je({
2034
+ const J = await Je({
2023
2035
  username: c,
2024
2036
  password: E,
2025
2037
  clientId: n,
@@ -2031,12 +2043,12 @@ const W = () => {
2031
2043
  domain: r,
2032
2044
  fingerprint: u.current
2033
2045
  });
2034
- return G.status ? (y(G.idToken), l(G.accessToken), S(G.refreshToken), o({
2046
+ return J.status ? (y(J.idToken), l(J.accessToken), S(J.refreshToken), o({
2035
2047
  type: V,
2036
2048
  payload: {
2037
2049
  authenticationType: g,
2038
2050
  user: {
2039
- userId: G.userId,
2051
+ userId: J.userId,
2040
2052
  username: c
2041
2053
  }
2042
2054
  }
@@ -2044,7 +2056,7 @@ const W = () => {
2044
2056
  }
2045
2057
  return !1;
2046
2058
  }
2047
- const M = await Je({
2059
+ const G = await Je({
2048
2060
  username: c,
2049
2061
  password: E,
2050
2062
  clientId: n,
@@ -2054,12 +2066,12 @@ const W = () => {
2054
2066
  domain: r,
2055
2067
  fingerprint: u.current
2056
2068
  });
2057
- return M.status ? (y(M.idToken), l(M.accessToken), S(M.refreshToken), o({
2069
+ return G.status ? (y(G.idToken), l(G.accessToken), S(G.refreshToken), o({
2058
2070
  type: V,
2059
2071
  payload: {
2060
2072
  authenticationType: g,
2061
2073
  user: {
2062
- userId: M.userId,
2074
+ userId: G.userId,
2063
2075
  username: c
2064
2076
  }
2065
2077
  }
@@ -2072,8 +2084,8 @@ const W = () => {
2072
2084
  if (c && E && E.userId) {
2073
2085
  if (p) {
2074
2086
  w("getAccessToken");
2075
- const _ = await F(p);
2076
- if (_ && _.payload[I.USER_ID_KEY] !== "")
2087
+ const _ = await M(p);
2088
+ if (_ && _.payload[b.USER_ID_KEY] !== "")
2077
2089
  return p;
2078
2090
  }
2079
2091
  w("getAccessToken: invalid access token, refreshing it");
@@ -2137,7 +2149,7 @@ const W = () => {
2137
2149
  }
2138
2150
  }, Rt = async () => {
2139
2151
  const c = Se();
2140
- Ie(c), o({ type: J, payload: { isLoading: !0 } }), h(), d(), q(), w("loginWithPasskey");
2152
+ Ie(c), o({ type: Y, payload: { isLoading: !0 } }), h(), d(), q(), w("loginWithPasskey");
2141
2153
  const E = Se();
2142
2154
  let g = await L({
2143
2155
  accessToken: p,
@@ -2166,7 +2178,7 @@ const W = () => {
2166
2178
  }), g.data.status === "success" ? (y(g.data.idToken), l(g.data.accessToken), S(g.data.refreshToken), o({
2167
2179
  type: V,
2168
2180
  payload: {
2169
- authenticationType: j.PASSKEY,
2181
+ authenticationType: F.PASSKEY,
2170
2182
  user: {
2171
2183
  userId: g.data.userId,
2172
2184
  username: g.data.username
@@ -2188,7 +2200,7 @@ const W = () => {
2188
2200
  }), $(re), !1;
2189
2201
  }
2190
2202
  };
2191
- return /* @__PURE__ */ ke(Er.Provider, { value: { state: s, dispatch: o }, children: /* @__PURE__ */ ke(
2203
+ return /* @__PURE__ */ Pe(Er.Provider, { value: { state: s, dispatch: o }, children: /* @__PURE__ */ Pe(
2192
2204
  yt.Provider,
2193
2205
  {
2194
2206
  value: {
@@ -2203,9 +2215,10 @@ const W = () => {
2203
2215
  children: e
2204
2216
  }
2205
2217
  ) });
2206
- }, Cr = (e = yt) => Nt(e);
2218
+ }, Or = (e = yt) => Nt(e);
2207
2219
  export {
2208
- j as AUTH_TYPES,
2209
- Pr as AuthProvider,
2210
- Cr as useAuth
2220
+ F as AUTH_TYPES,
2221
+ kr as AuthProvider,
2222
+ Cr as isGranted,
2223
+ Or as useAuth
2211
2224
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versini/auth-provider",
3
- "version": "6.2.1",
3
+ "version": "6.3.0",
4
4
  "license": "MIT",
5
5
  "author": "Arno Versini",
6
6
  "publishConfig": {
@@ -45,11 +45,11 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "@simplewebauthn/browser": "10.0.0",
48
- "@versini/auth-common": "2.12.1",
48
+ "@versini/auth-common": "3.2.0",
49
49
  "@versini/ui-fingerprint": "1.0.1",
50
50
  "@versini/ui-hooks": "4.0.1",
51
51
  "jose": "5.6.3",
52
52
  "uuid": "10.0.0"
53
53
  },
54
- "gitHead": "8602491302f1b74ebeca8b4e34d7998a426a99c6"
54
+ "gitHead": "4e1b9bc9a8abff76274d07957bdbb45cf8ee1c00"
55
55
  }