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