@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/components/CoreFIDO.d.ts +10 -1
- package/dist/index.cjs.js +36 -20
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +36 -20
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
export interface AttestationResult {
|
|
2
|
+
id: string;
|
|
3
|
+
rawId: string;
|
|
4
|
+
type: string;
|
|
5
|
+
response: {
|
|
6
|
+
clientDataJSON: string;
|
|
7
|
+
attestationObject: string;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
1
10
|
/**
|
|
2
11
|
* Initiates the WebAuthn registration process.
|
|
3
12
|
* It takes server-provided options, converts them for the browser API,
|
|
@@ -7,7 +16,7 @@
|
|
|
7
16
|
* @param options - The PublicKeyCredentialCreationOptions from the server.
|
|
8
17
|
* @returns A promise that resolves to a JSON-serializable representation of the PublicKeyCredential.
|
|
9
18
|
*/
|
|
10
|
-
export declare function register(options: PublicKeyCredentialCreationOptions): Promise<
|
|
19
|
+
export declare function register(options: PublicKeyCredentialCreationOptions): Promise<AttestationResult>;
|
|
11
20
|
/**
|
|
12
21
|
* Initiates the WebAuthn authentication process.
|
|
13
22
|
* It takes server-provided options, converts them for the browser API,
|
package/dist/index.cjs.js
CHANGED
|
@@ -557,11 +557,11 @@ function base64urlToArrayBuffer(base64url) {
|
|
|
557
557
|
*/
|
|
558
558
|
function arrayBufferToBase64url(buffer) {
|
|
559
559
|
var bytes = new Uint8Array(buffer);
|
|
560
|
-
var binaryStr = String.fromCharCode
|
|
560
|
+
var binaryStr = Array.from(bytes, function (b) { return String.fromCharCode(b); }).join("");
|
|
561
561
|
return btoa(binaryStr)
|
|
562
562
|
.replace(/\+/g, "-")
|
|
563
563
|
.replace(/\//g, "_")
|
|
564
|
-
.replace(
|
|
564
|
+
.replace(/=+$/, ""); // use regex to remove all trailing '='
|
|
565
565
|
}
|
|
566
566
|
|
|
567
567
|
/**
|
|
@@ -575,21 +575,23 @@ function arrayBufferToBase64url(buffer) {
|
|
|
575
575
|
*/
|
|
576
576
|
function register(options) {
|
|
577
577
|
return __awaiter(this, void 0, void 0, function () {
|
|
578
|
-
var createOptions, credential, publicKeyCredential, attestationResponse;
|
|
579
|
-
|
|
580
|
-
|
|
578
|
+
var createOptions, credential, publicKeyCredential, attestationResponse, transports, err_1;
|
|
579
|
+
var _a, _b, _c;
|
|
580
|
+
return __generator(this, function (_d) {
|
|
581
|
+
switch (_d.label) {
|
|
581
582
|
case 0:
|
|
583
|
+
_d.trys.push([0, 2, , 3]);
|
|
582
584
|
createOptions = __assign(__assign({}, options), { challenge: base64urlToArrayBuffer(options.challenge), user: __assign(__assign({}, options.user), { id: base64urlToArrayBuffer(options.user.id) }) });
|
|
583
585
|
return [4 /*yield*/, navigator.credentials.create({
|
|
584
586
|
publicKey: createOptions,
|
|
585
587
|
})];
|
|
586
588
|
case 1:
|
|
587
|
-
credential =
|
|
588
|
-
if (!credential)
|
|
589
|
-
throw new Error("
|
|
590
|
-
}
|
|
589
|
+
credential = _d.sent();
|
|
590
|
+
if (!credential)
|
|
591
|
+
throw new Error("No credential created.");
|
|
591
592
|
publicKeyCredential = credential;
|
|
592
593
|
attestationResponse = publicKeyCredential.response;
|
|
594
|
+
transports = (_c = (_b = (_a = publicKeyCredential.response).getTransports) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : [];
|
|
593
595
|
return [2 /*return*/, {
|
|
594
596
|
id: publicKeyCredential.id,
|
|
595
597
|
rawId: arrayBufferToBase64url(publicKeyCredential.rawId),
|
|
@@ -597,8 +599,19 @@ function register(options) {
|
|
|
597
599
|
response: {
|
|
598
600
|
clientDataJSON: arrayBufferToBase64url(attestationResponse.clientDataJSON),
|
|
599
601
|
attestationObject: arrayBufferToBase64url(attestationResponse.attestationObject),
|
|
602
|
+
transports: transports,
|
|
600
603
|
},
|
|
601
604
|
}];
|
|
605
|
+
case 2:
|
|
606
|
+
err_1 = _d.sent();
|
|
607
|
+
if (err_1.name === "NotAllowedError") {
|
|
608
|
+
throw new Error("Registration cancelled by user.");
|
|
609
|
+
}
|
|
610
|
+
if (err_1.name === "InvalidStateError") {
|
|
611
|
+
throw new Error("Passkey already registered for this user.");
|
|
612
|
+
}
|
|
613
|
+
throw err_1;
|
|
614
|
+
case 3: return [2 /*return*/];
|
|
602
615
|
}
|
|
603
616
|
});
|
|
604
617
|
});
|
|
@@ -1864,12 +1877,12 @@ var MFAOptions = function (_a) {
|
|
|
1864
1877
|
var idToken = context.authMode === "MSAL" ? context.idToken : "";
|
|
1865
1878
|
var authenticate = useWebAuthn().authenticate;
|
|
1866
1879
|
var handleFIDOLogin = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
1867
|
-
var options,
|
|
1868
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1869
|
-
return __generator(this, function (
|
|
1870
|
-
switch (
|
|
1880
|
+
var options, assertionResponse, error_1;
|
|
1881
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
1882
|
+
return __generator(this, function (_o) {
|
|
1883
|
+
switch (_o.label) {
|
|
1871
1884
|
case 0:
|
|
1872
|
-
|
|
1885
|
+
_o.trys.push([0, 4, , 5]);
|
|
1873
1886
|
// 1. Fetch authentication challenge from your server
|
|
1874
1887
|
console.log("Requesting authentication challenge from server...");
|
|
1875
1888
|
return [4 /*yield*/, axios.post(MFAEndpoints.RetrieveAuthChallenge, {}, {
|
|
@@ -1879,17 +1892,20 @@ var MFAOptions = function (_a) {
|
|
|
1879
1892
|
},
|
|
1880
1893
|
})];
|
|
1881
1894
|
case 1:
|
|
1882
|
-
options = (
|
|
1895
|
+
options = (_o.sent()).data;
|
|
1883
1896
|
console.log("Received challenge:", options);
|
|
1884
|
-
|
|
1897
|
+
__assign(__assign({}, options), { pubKeyCredParams: (_a = options.pubKeyCredParams) === null || _a === void 0 ? void 0 : _a.map(function (param) { return ({
|
|
1885
1898
|
type: "public-key",
|
|
1886
1899
|
alg: param.alg
|
|
1887
1900
|
}); }), 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" }) });
|
|
1888
1901
|
// 2. Call the SDK to trigger the browser's passkey authentication UI
|
|
1889
1902
|
console.log("Calling SDK authenticate function...");
|
|
1890
|
-
return [4 /*yield*/, authenticate(
|
|
1903
|
+
return [4 /*yield*/, authenticate(__assign(__assign({}, options), { pubKeyCredParams: (_g = options.pubKeyCredParams) === null || _g === void 0 ? void 0 : _g.map(function (param) { return ({
|
|
1904
|
+
type: "public-key",
|
|
1905
|
+
alg: param.alg
|
|
1906
|
+
}); }), 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" }) }))];
|
|
1891
1907
|
case 2:
|
|
1892
|
-
assertionResponse =
|
|
1908
|
+
assertionResponse = _o.sent();
|
|
1893
1909
|
console.log("Authentication assertion received from client:", assertionResponse);
|
|
1894
1910
|
// 3. Send the assertion back to the server for verification
|
|
1895
1911
|
console.log("Sending assertion to server for verification...");
|
|
@@ -1901,11 +1917,11 @@ var MFAOptions = function (_a) {
|
|
|
1901
1917
|
withCredentials: true, // credentials: 'include'
|
|
1902
1918
|
})];
|
|
1903
1919
|
case 3:
|
|
1904
|
-
|
|
1920
|
+
_o.sent();
|
|
1905
1921
|
sonner.toast.success("🔑 Sign-in successful!");
|
|
1906
1922
|
return [3 /*break*/, 5];
|
|
1907
1923
|
case 4:
|
|
1908
|
-
error_1 =
|
|
1924
|
+
error_1 = _o.sent();
|
|
1909
1925
|
console.error("Authentication failed:", error_1);
|
|
1910
1926
|
sonner.toast.error("❌ Could not sign in.");
|
|
1911
1927
|
return [3 /*break*/, 5];
|