@nibssplc/cams-sdk-react 0.0.1-beta.97 → 0.0.1-beta.99
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.cjs.js +31 -22
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +31 -22
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -555,22 +555,35 @@ function arrayBufferToBase64url(buffer) {
|
|
|
555
555
|
function register(options) {
|
|
556
556
|
return __awaiter(this, void 0, void 0, function () {
|
|
557
557
|
var createOptions, credential, publicKeyCredential, attestationResponse, transports, err_1;
|
|
558
|
-
var _a, _b, _c;
|
|
559
|
-
return __generator(this, function (
|
|
560
|
-
switch (
|
|
558
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
559
|
+
return __generator(this, function (_k) {
|
|
560
|
+
switch (_k.label) {
|
|
561
561
|
case 0:
|
|
562
|
-
|
|
562
|
+
_k.trys.push([0, 2, , 3]);
|
|
563
563
|
createOptions = __assign(__assign({}, options), { challenge: base64urlToArrayBuffer(options.challenge), user: __assign(__assign({}, options.user), { id: base64urlToArrayBuffer(options.user.id) }) });
|
|
564
|
+
console.log("Creating credential with options:", createOptions, "...\n\n\n", options);
|
|
564
565
|
return [4 /*yield*/, navigator.credentials.create({
|
|
565
|
-
publicKey:
|
|
566
|
+
publicKey: __assign(__assign({}, options), { pubKeyCredParams: (_a = options.pubKeyCredParams) === null || _a === void 0 ? void 0 : _a.map(function (param) { return ({
|
|
567
|
+
type: "public-key",
|
|
568
|
+
alg: param.alg,
|
|
569
|
+
}); }), attestation: (((_b = options.attestation) === null || _b === void 0 ? void 0 : _b.toLowerCase()) || "none"), authenticatorSelection: __assign(__assign({}, options.authenticatorSelection), {
|
|
570
|
+
// authenticatorAttachment:
|
|
571
|
+
// (options.authenticatorSelection?.authenticatorAttachment?.toLowerCase() ||
|
|
572
|
+
// "platform") as AuthenticatorAttachment,
|
|
573
|
+
// requireResidentKey:
|
|
574
|
+
// (options.authenticatorSelection?.requireResidentKey?.toLowerCase() ||
|
|
575
|
+
// "false") === "true",
|
|
576
|
+
residentKey: (((_d = (_c = options.authenticatorSelection) === null || _c === void 0 ? void 0 : _c.residentKey) === null || _d === void 0 ? void 0 : _d.toLowerCase()) ||
|
|
577
|
+
"discouraged"), userVerification: (((_f = (_e = options.authenticatorSelection) === null || _e === void 0 ? void 0 : _e.userVerification) === null || _f === void 0 ? void 0 : _f.toLowerCase()) ||
|
|
578
|
+
"preferred") }) }),
|
|
566
579
|
})];
|
|
567
580
|
case 1:
|
|
568
|
-
credential =
|
|
581
|
+
credential = _k.sent();
|
|
569
582
|
if (!credential)
|
|
570
583
|
throw new Error("No credential created.");
|
|
571
584
|
publicKeyCredential = credential;
|
|
572
585
|
attestationResponse = publicKeyCredential.response;
|
|
573
|
-
transports = (
|
|
586
|
+
transports = (_j = (_h = (_g = publicKeyCredential.response).getTransports) === null || _h === void 0 ? void 0 : _h.call(_g)) !== null && _j !== void 0 ? _j : [];
|
|
574
587
|
return [2 /*return*/, {
|
|
575
588
|
id: publicKeyCredential.id,
|
|
576
589
|
rawId: arrayBufferToBase64url(publicKeyCredential.rawId),
|
|
@@ -582,7 +595,7 @@ function register(options) {
|
|
|
582
595
|
},
|
|
583
596
|
}];
|
|
584
597
|
case 2:
|
|
585
|
-
err_1 =
|
|
598
|
+
err_1 = _k.sent();
|
|
586
599
|
if (err_1.name === "NotAllowedError") {
|
|
587
600
|
throw new Error("Registration cancelled by user.");
|
|
588
601
|
}
|
|
@@ -1857,11 +1870,11 @@ var MFAOptions = function (_a) {
|
|
|
1857
1870
|
var authenticate = useWebAuthn().authenticate;
|
|
1858
1871
|
var handleFIDOLogin = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
1859
1872
|
var options, assertionResponse, error_1;
|
|
1860
|
-
var _a, _b, _c, _d, _e, _f
|
|
1861
|
-
return __generator(this, function (
|
|
1862
|
-
switch (
|
|
1873
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1874
|
+
return __generator(this, function (_g) {
|
|
1875
|
+
switch (_g.label) {
|
|
1863
1876
|
case 0:
|
|
1864
|
-
|
|
1877
|
+
_g.trys.push([0, 4, , 5]);
|
|
1865
1878
|
// 1. Fetch authentication challenge from your server
|
|
1866
1879
|
console.log("Requesting authentication challenge from server...");
|
|
1867
1880
|
return [4 /*yield*/, axios.post(MFAEndpoints.RetrieveAuthChallenge, {}, {
|
|
@@ -1871,20 +1884,16 @@ var MFAOptions = function (_a) {
|
|
|
1871
1884
|
},
|
|
1872
1885
|
})];
|
|
1873
1886
|
case 1:
|
|
1874
|
-
options = (
|
|
1887
|
+
options = (_g.sent()).data;
|
|
1875
1888
|
console.log("Received challenge:", options);
|
|
1876
|
-
__assign(__assign({}, options), { pubKeyCredParams: (_a = options.pubKeyCredParams) === null || _a === void 0 ? void 0 : _a.map(function (param) { return ({
|
|
1877
|
-
type: "public-key",
|
|
1878
|
-
alg: param.alg
|
|
1879
|
-
}); }), attestation: ((_b = options.attestation) === null || _b === void 0 ? void 0 : _b.toLowerCase()) || "none", authenticatorSelection: __assign(__assign({}, options.authenticatorSelection), { residentKey: ((_d = (_c = options.authenticatorSelection) === null || _c === void 0 ? void 0 : _c.residentKey) === null || _d === void 0 ? void 0 : _d.toLowerCase()) || "discouraged", userVerification: ((_f = (_e = options.authenticatorSelection) === null || _e === void 0 ? void 0 : _e.userVerification) === null || _f === void 0 ? void 0 : _f.toLowerCase()) || "preferred" }) });
|
|
1880
1889
|
// 2. Call the SDK to trigger the browser's passkey authentication UI
|
|
1881
1890
|
console.log("Calling SDK authenticate function...");
|
|
1882
|
-
return [4 /*yield*/, authenticate(__assign(__assign({}, options), { pubKeyCredParams: (
|
|
1891
|
+
return [4 /*yield*/, authenticate(__assign(__assign({}, options), { pubKeyCredParams: (_a = options.pubKeyCredParams) === null || _a === void 0 ? void 0 : _a.map(function (param) { return ({
|
|
1883
1892
|
type: "public-key",
|
|
1884
1893
|
alg: param.alg
|
|
1885
|
-
}); }), attestation: ((
|
|
1894
|
+
}); }), attestation: ((_b = options.attestation) === null || _b === void 0 ? void 0 : _b.toLowerCase()) || "none", authenticatorSelection: __assign(__assign({}, options.authenticatorSelection), { residentKey: ((_d = (_c = options.authenticatorSelection) === null || _c === void 0 ? void 0 : _c.residentKey) === null || _d === void 0 ? void 0 : _d.toLowerCase()) || "discouraged", userVerification: ((_f = (_e = options.authenticatorSelection) === null || _e === void 0 ? void 0 : _e.userVerification) === null || _f === void 0 ? void 0 : _f.toLowerCase()) || "preferred" }) }))];
|
|
1886
1895
|
case 2:
|
|
1887
|
-
assertionResponse =
|
|
1896
|
+
assertionResponse = _g.sent();
|
|
1888
1897
|
console.log("Authentication assertion received from client:", assertionResponse);
|
|
1889
1898
|
// 3. Send the assertion back to the server for verification
|
|
1890
1899
|
console.log("Sending assertion to server for verification...");
|
|
@@ -1896,11 +1905,11 @@ var MFAOptions = function (_a) {
|
|
|
1896
1905
|
withCredentials: true, // credentials: 'include'
|
|
1897
1906
|
})];
|
|
1898
1907
|
case 3:
|
|
1899
|
-
|
|
1908
|
+
_g.sent();
|
|
1900
1909
|
toast.success("🔑 Sign-in successful!");
|
|
1901
1910
|
return [3 /*break*/, 5];
|
|
1902
1911
|
case 4:
|
|
1903
|
-
error_1 =
|
|
1912
|
+
error_1 = _g.sent();
|
|
1904
1913
|
console.error("Authentication failed:", error_1);
|
|
1905
1914
|
toast.error("❌ Could not sign in.");
|
|
1906
1915
|
return [3 /*break*/, 5];
|