@nibssplc/cams-sdk-react 0.0.1-beta.96 → 0.0.1-beta.97

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.esm.js CHANGED
@@ -536,11 +536,11 @@ function base64urlToArrayBuffer(base64url) {
536
536
  */
537
537
  function arrayBufferToBase64url(buffer) {
538
538
  var bytes = new Uint8Array(buffer);
539
- var binaryStr = String.fromCharCode.apply(null, bytes);
539
+ var binaryStr = Array.from(bytes, function (b) { return String.fromCharCode(b); }).join("");
540
540
  return btoa(binaryStr)
541
541
  .replace(/\+/g, "-")
542
542
  .replace(/\//g, "_")
543
- .replace(/=/g, "");
543
+ .replace(/=+$/, ""); // use regex to remove all trailing '='
544
544
  }
545
545
 
546
546
  /**
@@ -554,21 +554,23 @@ function arrayBufferToBase64url(buffer) {
554
554
  */
555
555
  function register(options) {
556
556
  return __awaiter(this, void 0, void 0, function () {
557
- var createOptions, credential, publicKeyCredential, attestationResponse;
558
- return __generator(this, function (_a) {
559
- switch (_a.label) {
557
+ var createOptions, credential, publicKeyCredential, attestationResponse, transports, err_1;
558
+ var _a, _b, _c;
559
+ return __generator(this, function (_d) {
560
+ switch (_d.label) {
560
561
  case 0:
562
+ _d.trys.push([0, 2, , 3]);
561
563
  createOptions = __assign(__assign({}, options), { challenge: base64urlToArrayBuffer(options.challenge), user: __assign(__assign({}, options.user), { id: base64urlToArrayBuffer(options.user.id) }) });
562
564
  return [4 /*yield*/, navigator.credentials.create({
563
565
  publicKey: createOptions,
564
566
  })];
565
567
  case 1:
566
- credential = _a.sent();
567
- if (!credential) {
568
- throw new Error("Failed to create credential.");
569
- }
568
+ credential = _d.sent();
569
+ if (!credential)
570
+ throw new Error("No credential created.");
570
571
  publicKeyCredential = credential;
571
572
  attestationResponse = publicKeyCredential.response;
573
+ transports = (_c = (_b = (_a = publicKeyCredential.response).getTransports) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : [];
572
574
  return [2 /*return*/, {
573
575
  id: publicKeyCredential.id,
574
576
  rawId: arrayBufferToBase64url(publicKeyCredential.rawId),
@@ -576,8 +578,19 @@ function register(options) {
576
578
  response: {
577
579
  clientDataJSON: arrayBufferToBase64url(attestationResponse.clientDataJSON),
578
580
  attestationObject: arrayBufferToBase64url(attestationResponse.attestationObject),
581
+ transports: transports,
579
582
  },
580
583
  }];
584
+ case 2:
585
+ err_1 = _d.sent();
586
+ if (err_1.name === "NotAllowedError") {
587
+ throw new Error("Registration cancelled by user.");
588
+ }
589
+ if (err_1.name === "InvalidStateError") {
590
+ throw new Error("Passkey already registered for this user.");
591
+ }
592
+ throw err_1;
593
+ case 3: return [2 /*return*/];
581
594
  }
582
595
  });
583
596
  });
@@ -1843,12 +1856,12 @@ var MFAOptions = function (_a) {
1843
1856
  var idToken = context.authMode === "MSAL" ? context.idToken : "";
1844
1857
  var authenticate = useWebAuthn().authenticate;
1845
1858
  var handleFIDOLogin = function () { return __awaiter(void 0, void 0, void 0, function () {
1846
- var options, fixedOptions, assertionResponse, error_1;
1847
- var _a, _b, _c, _d, _e, _f;
1848
- return __generator(this, function (_g) {
1849
- switch (_g.label) {
1859
+ var options, assertionResponse, error_1;
1860
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
1861
+ return __generator(this, function (_o) {
1862
+ switch (_o.label) {
1850
1863
  case 0:
1851
- _g.trys.push([0, 4, , 5]);
1864
+ _o.trys.push([0, 4, , 5]);
1852
1865
  // 1. Fetch authentication challenge from your server
1853
1866
  console.log("Requesting authentication challenge from server...");
1854
1867
  return [4 /*yield*/, axios.post(MFAEndpoints.RetrieveAuthChallenge, {}, {
@@ -1858,17 +1871,20 @@ var MFAOptions = function (_a) {
1858
1871
  },
1859
1872
  })];
1860
1873
  case 1:
1861
- options = (_g.sent()).data;
1874
+ options = (_o.sent()).data;
1862
1875
  console.log("Received challenge:", options);
1863
- fixedOptions = __assign(__assign({}, options), { pubKeyCredParams: (_a = options.pubKeyCredParams) === null || _a === void 0 ? void 0 : _a.map(function (param) { return ({
1876
+ __assign(__assign({}, options), { pubKeyCredParams: (_a = options.pubKeyCredParams) === null || _a === void 0 ? void 0 : _a.map(function (param) { return ({
1864
1877
  type: "public-key",
1865
1878
  alg: param.alg
1866
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" }) });
1867
1880
  // 2. Call the SDK to trigger the browser's passkey authentication UI
1868
1881
  console.log("Calling SDK authenticate function...");
1869
- return [4 /*yield*/, authenticate(fixedOptions)];
1882
+ return [4 /*yield*/, authenticate(__assign(__assign({}, options), { pubKeyCredParams: (_g = options.pubKeyCredParams) === null || _g === void 0 ? void 0 : _g.map(function (param) { return ({
1883
+ type: "public-key",
1884
+ alg: param.alg
1885
+ }); }), attestation: ((_h = options.attestation) === null || _h === void 0 ? void 0 : _h.toLowerCase()) || "none", authenticatorSelection: __assign(__assign({}, options.authenticatorSelection), { residentKey: ((_k = (_j = options.authenticatorSelection) === null || _j === void 0 ? void 0 : _j.residentKey) === null || _k === void 0 ? void 0 : _k.toLowerCase()) || "discouraged", userVerification: ((_m = (_l = options.authenticatorSelection) === null || _l === void 0 ? void 0 : _l.userVerification) === null || _m === void 0 ? void 0 : _m.toLowerCase()) || "preferred" }) }))];
1870
1886
  case 2:
1871
- assertionResponse = _g.sent();
1887
+ assertionResponse = _o.sent();
1872
1888
  console.log("Authentication assertion received from client:", assertionResponse);
1873
1889
  // 3. Send the assertion back to the server for verification
1874
1890
  console.log("Sending assertion to server for verification...");
@@ -1880,11 +1896,11 @@ var MFAOptions = function (_a) {
1880
1896
  withCredentials: true, // credentials: 'include'
1881
1897
  })];
1882
1898
  case 3:
1883
- _g.sent();
1899
+ _o.sent();
1884
1900
  toast.success("🔑 Sign-in successful!");
1885
1901
  return [3 /*break*/, 5];
1886
1902
  case 4:
1887
- error_1 = _g.sent();
1903
+ error_1 = _o.sent();
1888
1904
  console.error("Authentication failed:", error_1);
1889
1905
  toast.error("❌ Could not sign in.");
1890
1906
  return [3 /*break*/, 5];