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

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,24 @@ 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) }) });
564
+ console.log("Creating credential with options:", createOptions, "...\n\n\n", options);
562
565
  return [4 /*yield*/, navigator.credentials.create({
563
566
  publicKey: createOptions,
564
567
  })];
565
568
  case 1:
566
- credential = _a.sent();
567
- if (!credential) {
568
- throw new Error("Failed to create credential.");
569
- }
569
+ credential = _d.sent();
570
+ if (!credential)
571
+ throw new Error("No credential created.");
570
572
  publicKeyCredential = credential;
571
573
  attestationResponse = publicKeyCredential.response;
574
+ transports = (_c = (_b = (_a = publicKeyCredential.response).getTransports) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : [];
572
575
  return [2 /*return*/, {
573
576
  id: publicKeyCredential.id,
574
577
  rawId: arrayBufferToBase64url(publicKeyCredential.rawId),
@@ -576,8 +579,19 @@ function register(options) {
576
579
  response: {
577
580
  clientDataJSON: arrayBufferToBase64url(attestationResponse.clientDataJSON),
578
581
  attestationObject: arrayBufferToBase64url(attestationResponse.attestationObject),
582
+ transports: transports,
579
583
  },
580
584
  }];
585
+ case 2:
586
+ err_1 = _d.sent();
587
+ if (err_1.name === "NotAllowedError") {
588
+ throw new Error("Registration cancelled by user.");
589
+ }
590
+ if (err_1.name === "InvalidStateError") {
591
+ throw new Error("Passkey already registered for this user.");
592
+ }
593
+ throw err_1;
594
+ case 3: return [2 /*return*/];
581
595
  }
582
596
  });
583
597
  });
@@ -1843,12 +1857,12 @@ var MFAOptions = function (_a) {
1843
1857
  var idToken = context.authMode === "MSAL" ? context.idToken : "";
1844
1858
  var authenticate = useWebAuthn().authenticate;
1845
1859
  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) {
1860
+ var options, assertionResponse, error_1;
1861
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
1862
+ return __generator(this, function (_o) {
1863
+ switch (_o.label) {
1850
1864
  case 0:
1851
- _g.trys.push([0, 4, , 5]);
1865
+ _o.trys.push([0, 4, , 5]);
1852
1866
  // 1. Fetch authentication challenge from your server
1853
1867
  console.log("Requesting authentication challenge from server...");
1854
1868
  return [4 /*yield*/, axios.post(MFAEndpoints.RetrieveAuthChallenge, {}, {
@@ -1858,17 +1872,20 @@ var MFAOptions = function (_a) {
1858
1872
  },
1859
1873
  })];
1860
1874
  case 1:
1861
- options = (_g.sent()).data;
1875
+ options = (_o.sent()).data;
1862
1876
  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 ({
1877
+ __assign(__assign({}, options), { pubKeyCredParams: (_a = options.pubKeyCredParams) === null || _a === void 0 ? void 0 : _a.map(function (param) { return ({
1864
1878
  type: "public-key",
1865
1879
  alg: param.alg
1866
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" }) });
1867
1881
  // 2. Call the SDK to trigger the browser's passkey authentication UI
1868
1882
  console.log("Calling SDK authenticate function...");
1869
- return [4 /*yield*/, authenticate(fixedOptions)];
1883
+ return [4 /*yield*/, authenticate(__assign(__assign({}, options), { pubKeyCredParams: (_g = options.pubKeyCredParams) === null || _g === void 0 ? void 0 : _g.map(function (param) { return ({
1884
+ type: "public-key",
1885
+ alg: param.alg
1886
+ }); }), 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
1887
  case 2:
1871
- assertionResponse = _g.sent();
1888
+ assertionResponse = _o.sent();
1872
1889
  console.log("Authentication assertion received from client:", assertionResponse);
1873
1890
  // 3. Send the assertion back to the server for verification
1874
1891
  console.log("Sending assertion to server for verification...");
@@ -1880,11 +1897,11 @@ var MFAOptions = function (_a) {
1880
1897
  withCredentials: true, // credentials: 'include'
1881
1898
  })];
1882
1899
  case 3:
1883
- _g.sent();
1900
+ _o.sent();
1884
1901
  toast.success("🔑 Sign-in successful!");
1885
1902
  return [3 /*break*/, 5];
1886
1903
  case 4:
1887
- error_1 = _g.sent();
1904
+ error_1 = _o.sent();
1888
1905
  console.error("Authentication failed:", error_1);
1889
1906
  toast.error("❌ Could not sign in.");
1890
1907
  return [3 /*break*/, 5];