@omni2fa/core 0.8.0 → 0.8.1
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/LICENSE +21 -0
- package/dist/client/Omni2FaClient.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +45 -28
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -52,8 +52,25 @@ const a = {
|
|
|
52
52
|
function T(t) {
|
|
53
53
|
return S[t] ?? S[a.Unknown];
|
|
54
54
|
}
|
|
55
|
-
const W = "X-Omni2FA-StepUp", F = "omni2fa:preauth",
|
|
56
|
-
|
|
55
|
+
const W = "X-Omni2FA-StepUp", F = "omni2fa:preauth", K = "omni2fa:session";
|
|
56
|
+
function b(t) {
|
|
57
|
+
let e = t;
|
|
58
|
+
const r = /^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.exec(e);
|
|
59
|
+
if (r) {
|
|
60
|
+
e = e.slice(r[0].length);
|
|
61
|
+
const l = e.indexOf("/");
|
|
62
|
+
e = l === -1 ? "/" : e.slice(l);
|
|
63
|
+
} else if (e.startsWith("//")) {
|
|
64
|
+
e = e.slice(2);
|
|
65
|
+
const l = e.indexOf("/");
|
|
66
|
+
e = l === -1 ? "/" : e.slice(l);
|
|
67
|
+
}
|
|
68
|
+
const n = e.indexOf("#");
|
|
69
|
+
n !== -1 && (e = e.slice(0, n));
|
|
70
|
+
const o = e.indexOf("?");
|
|
71
|
+
return o !== -1 && (e = e.slice(0, o)), e.startsWith("/") ? e : `/${e}`;
|
|
72
|
+
}
|
|
73
|
+
class $ {
|
|
57
74
|
storage;
|
|
58
75
|
preAuthKey;
|
|
59
76
|
sessionKey;
|
|
@@ -61,7 +78,7 @@ class K {
|
|
|
61
78
|
inner;
|
|
62
79
|
stepUpHandler = null;
|
|
63
80
|
constructor(e) {
|
|
64
|
-
this.storage = e.storage ?? new _(), this.preAuthKey = e.preAuthStorageKey ?? F, this.sessionKey = e.sessionStorageKey ??
|
|
81
|
+
this.storage = e.storage ?? new _(), this.preAuthKey = e.preAuthStorageKey ?? F, this.sessionKey = e.sessionStorageKey ?? K, this.basePath = b(e.baseUrl).replace(/\/$/, ""), this.inner = J({
|
|
65
82
|
baseUrl: e.baseUrl,
|
|
66
83
|
fetch: e.fetch ?? globalThis.fetch.bind(globalThis),
|
|
67
84
|
...e.credentials ? { credentials: e.credentials } : {}
|
|
@@ -76,7 +93,7 @@ class K {
|
|
|
76
93
|
}
|
|
77
94
|
/** Pre-auth endpoints are exactly the ones mounted under <c>{basePath}/challenge/</c>. */
|
|
78
95
|
isPreAuthEndpoint(e) {
|
|
79
|
-
const r =
|
|
96
|
+
const r = b(e);
|
|
80
97
|
return (r.startsWith(this.basePath) ? r.slice(this.basePath.length) : r).startsWith("/challenge/");
|
|
81
98
|
}
|
|
82
99
|
setPreAuthToken(e) {
|
|
@@ -230,7 +247,7 @@ class s extends Error {
|
|
|
230
247
|
super(r), this.name = "Omni2FaApiError", this.code = e, this.httpStatus = n, this.details = o;
|
|
231
248
|
}
|
|
232
249
|
}
|
|
233
|
-
const
|
|
250
|
+
const L = {
|
|
234
251
|
enrollmentId: null,
|
|
235
252
|
otpAuthUri: null,
|
|
236
253
|
secret: null,
|
|
@@ -266,7 +283,7 @@ function H(t) {
|
|
|
266
283
|
}).createMachine({
|
|
267
284
|
id: "totpEnrollment",
|
|
268
285
|
initial: "idle",
|
|
269
|
-
context:
|
|
286
|
+
context: L,
|
|
270
287
|
states: {
|
|
271
288
|
idle: {
|
|
272
289
|
on: {
|
|
@@ -483,7 +500,7 @@ function d(t) {
|
|
|
483
500
|
r += String.fromCharCode(n);
|
|
484
501
|
return btoa(r).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
485
502
|
}
|
|
486
|
-
function
|
|
503
|
+
function R(t) {
|
|
487
504
|
return (t ?? []).map((e) => ({ ...e, id: m(e.id) }));
|
|
488
505
|
}
|
|
489
506
|
async function q(t) {
|
|
@@ -491,7 +508,7 @@ async function q(t) {
|
|
|
491
508
|
...e,
|
|
492
509
|
challenge: m(e.challenge),
|
|
493
510
|
user: { ...e.user, id: m(e.user.id) },
|
|
494
|
-
excludeCredentials:
|
|
511
|
+
excludeCredentials: R(e.excludeCredentials)
|
|
495
512
|
// Cast through unknown: the spread carries Fido2's index-signature fields the DOM type omits.
|
|
496
513
|
}, n = await navigator.credentials.create({ publicKey: r });
|
|
497
514
|
if (n === null)
|
|
@@ -512,7 +529,7 @@ async function P(t) {
|
|
|
512
529
|
const e = JSON.parse(t), r = {
|
|
513
530
|
...e,
|
|
514
531
|
challenge: m(e.challenge),
|
|
515
|
-
allowCredentials:
|
|
532
|
+
allowCredentials: R(e.allowCredentials)
|
|
516
533
|
}, n = await navigator.credentials.get({ publicKey: r });
|
|
517
534
|
if (n === null)
|
|
518
535
|
throw new Error("WebAuthn authentication produced no credential.");
|
|
@@ -530,7 +547,7 @@ async function P(t) {
|
|
|
530
547
|
}
|
|
531
548
|
});
|
|
532
549
|
}
|
|
533
|
-
const
|
|
550
|
+
const z = {
|
|
534
551
|
enrollmentId: null,
|
|
535
552
|
optionsJson: null,
|
|
536
553
|
name: null,
|
|
@@ -539,7 +556,7 @@ const B = {
|
|
|
539
556
|
errorCode: null,
|
|
540
557
|
errorMessage: null
|
|
541
558
|
};
|
|
542
|
-
function
|
|
559
|
+
function B(t) {
|
|
543
560
|
return h({
|
|
544
561
|
types: {
|
|
545
562
|
context: {},
|
|
@@ -566,7 +583,7 @@ function G(t) {
|
|
|
566
583
|
}).createMachine({
|
|
567
584
|
id: "webauthnEnrollment",
|
|
568
585
|
initial: "idle",
|
|
569
|
-
context:
|
|
586
|
+
context: z,
|
|
570
587
|
states: {
|
|
571
588
|
idle: {
|
|
572
589
|
on: {
|
|
@@ -630,7 +647,7 @@ function U({ context: t }) {
|
|
|
630
647
|
function O(t, e) {
|
|
631
648
|
e instanceof s ? (t.errorCode = e.code, t.errorMessage = e.message) : (t.errorCode = "UNKNOWN", t.errorMessage = e instanceof Error ? e.message : null);
|
|
632
649
|
}
|
|
633
|
-
const
|
|
650
|
+
const G = {
|
|
634
651
|
methodId: null,
|
|
635
652
|
methodType: null,
|
|
636
653
|
userId: null,
|
|
@@ -641,7 +658,7 @@ const X = {
|
|
|
641
658
|
errorCode: null,
|
|
642
659
|
errorMessage: null
|
|
643
660
|
};
|
|
644
|
-
function
|
|
661
|
+
function X(t) {
|
|
645
662
|
return h({
|
|
646
663
|
types: {
|
|
647
664
|
context: {},
|
|
@@ -682,7 +699,7 @@ function j(t) {
|
|
|
682
699
|
}).createMachine({
|
|
683
700
|
id: "challenge",
|
|
684
701
|
initial: "idle",
|
|
685
|
-
context:
|
|
702
|
+
context: G,
|
|
686
703
|
states: {
|
|
687
704
|
idle: {
|
|
688
705
|
on: {
|
|
@@ -824,12 +841,12 @@ function C({ context: t }) {
|
|
|
824
841
|
function c(t, e) {
|
|
825
842
|
e instanceof s ? (t.errorCode = e.code, t.errorMessage = e.message) : (t.errorCode = "UNKNOWN", t.errorMessage = e instanceof Error ? e.message : null);
|
|
826
843
|
}
|
|
827
|
-
const
|
|
844
|
+
const j = {
|
|
828
845
|
items: [],
|
|
829
846
|
errorCode: null,
|
|
830
847
|
errorMessage: null
|
|
831
848
|
};
|
|
832
|
-
function
|
|
849
|
+
function Z(t) {
|
|
833
850
|
return h({
|
|
834
851
|
types: {
|
|
835
852
|
context: {},
|
|
@@ -852,7 +869,7 @@ function Q(t) {
|
|
|
852
869
|
}).createMachine({
|
|
853
870
|
id: "methods",
|
|
854
871
|
initial: "idle",
|
|
855
|
-
context:
|
|
872
|
+
context: j,
|
|
856
873
|
states: {
|
|
857
874
|
idle: {
|
|
858
875
|
on: {
|
|
@@ -903,13 +920,13 @@ function Q(t) {
|
|
|
903
920
|
failed: {
|
|
904
921
|
on: {
|
|
905
922
|
load: { target: "loading" },
|
|
906
|
-
reset: { target: "idle", actions:
|
|
923
|
+
reset: { target: "idle", actions: Q }
|
|
907
924
|
}
|
|
908
925
|
}
|
|
909
926
|
}
|
|
910
927
|
});
|
|
911
928
|
}
|
|
912
|
-
function
|
|
929
|
+
function Q({ context: t }) {
|
|
913
930
|
t.items = [], t.errorCode = null, t.errorMessage = null;
|
|
914
931
|
}
|
|
915
932
|
function N(t, e) {
|
|
@@ -1003,7 +1020,7 @@ function ee(t) {
|
|
|
1003
1020
|
},
|
|
1004
1021
|
onDone: {
|
|
1005
1022
|
target: "verified",
|
|
1006
|
-
actions: ({ context: e, event: r }) =>
|
|
1023
|
+
actions: ({ context: e, event: r }) => D(e, r.output.stepUpToken)
|
|
1007
1024
|
},
|
|
1008
1025
|
onError: {
|
|
1009
1026
|
target: "failed",
|
|
@@ -1045,7 +1062,7 @@ function ee(t) {
|
|
|
1045
1062
|
},
|
|
1046
1063
|
onDone: {
|
|
1047
1064
|
target: "verified",
|
|
1048
|
-
actions: ({ context: e, event: r }) =>
|
|
1065
|
+
actions: ({ context: e, event: r }) => D(e, r.output.stepUpToken)
|
|
1049
1066
|
},
|
|
1050
1067
|
onError: {
|
|
1051
1068
|
target: "awaitingCode",
|
|
@@ -1070,7 +1087,7 @@ function ee(t) {
|
|
|
1070
1087
|
function I(t, e) {
|
|
1071
1088
|
t.methodType = e.type, t.expiresAt = e.expiresAt ?? null, t.resendAvailableAt = e.resendAvailableAt ?? null, t.optionsJson = e.optionsJson ?? null, t.errorCode = null, t.errorMessage = null;
|
|
1072
1089
|
}
|
|
1073
|
-
function
|
|
1090
|
+
function D(t, e) {
|
|
1074
1091
|
t.stepUpToken = e, t.errorCode = null, t.errorMessage = null;
|
|
1075
1092
|
}
|
|
1076
1093
|
function A({ context: t }) {
|
|
@@ -1080,7 +1097,7 @@ function g(t, e) {
|
|
|
1080
1097
|
e instanceof s ? (t.errorCode = e.code, t.errorMessage = e.message) : (t.errorCode = "UNKNOWN", t.errorMessage = e instanceof Error ? e.message : null);
|
|
1081
1098
|
}
|
|
1082
1099
|
function se(t) {
|
|
1083
|
-
const e = new
|
|
1100
|
+
const e = new $(t), r = u(H(e)), n = u(Y(e)), o = u(B(e)), l = u(X(e)), p = u(ee(e)), f = u(Z(e));
|
|
1084
1101
|
return r.start(), n.start(), o.start(), l.start(), p.start(), f.start(), {
|
|
1085
1102
|
client: e,
|
|
1086
1103
|
totpEnrollment: r,
|
|
@@ -1098,17 +1115,17 @@ export {
|
|
|
1098
1115
|
oe as LocalStorageStorage,
|
|
1099
1116
|
_ as MemoryStorage,
|
|
1100
1117
|
s as Omni2FaApiError,
|
|
1101
|
-
|
|
1118
|
+
$ as Omni2FaClient,
|
|
1102
1119
|
a as Omni2FaErrorCodes,
|
|
1103
1120
|
W as STEP_UP_HEADER,
|
|
1104
1121
|
ne as SessionStorageStorage,
|
|
1105
|
-
|
|
1122
|
+
X as createChallengeMachine,
|
|
1106
1123
|
Y as createEmailEnrollmentMachine,
|
|
1107
|
-
|
|
1124
|
+
Z as createMethodsMachine,
|
|
1108
1125
|
se as createOmni2Fa,
|
|
1109
1126
|
ee as createStepUpMachine,
|
|
1110
1127
|
H as createTotpEnrollmentMachine,
|
|
1111
|
-
|
|
1128
|
+
B as createWebAuthnEnrollmentMachine,
|
|
1112
1129
|
T as getDefaultMessage,
|
|
1113
1130
|
P as startAuthentication,
|
|
1114
1131
|
q as startRegistration
|