@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/components/CoreFIDO.d.ts +10 -1
- package/dist/index.cjs.js +37 -20
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +37 -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,24 @@ 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) }) });
|
|
585
|
+
console.log("Creating credential with options:", createOptions, "...\n\n\n", options);
|
|
583
586
|
return [4 /*yield*/, navigator.credentials.create({
|
|
584
587
|
publicKey: createOptions,
|
|
585
588
|
})];
|
|
586
589
|
case 1:
|
|
587
|
-
credential =
|
|
588
|
-
if (!credential)
|
|
589
|
-
throw new Error("
|
|
590
|
-
}
|
|
590
|
+
credential = _d.sent();
|
|
591
|
+
if (!credential)
|
|
592
|
+
throw new Error("No credential created.");
|
|
591
593
|
publicKeyCredential = credential;
|
|
592
594
|
attestationResponse = publicKeyCredential.response;
|
|
595
|
+
transports = (_c = (_b = (_a = publicKeyCredential.response).getTransports) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : [];
|
|
593
596
|
return [2 /*return*/, {
|
|
594
597
|
id: publicKeyCredential.id,
|
|
595
598
|
rawId: arrayBufferToBase64url(publicKeyCredential.rawId),
|
|
@@ -597,8 +600,19 @@ function register(options) {
|
|
|
597
600
|
response: {
|
|
598
601
|
clientDataJSON: arrayBufferToBase64url(attestationResponse.clientDataJSON),
|
|
599
602
|
attestationObject: arrayBufferToBase64url(attestationResponse.attestationObject),
|
|
603
|
+
transports: transports,
|
|
600
604
|
},
|
|
601
605
|
}];
|
|
606
|
+
case 2:
|
|
607
|
+
err_1 = _d.sent();
|
|
608
|
+
if (err_1.name === "NotAllowedError") {
|
|
609
|
+
throw new Error("Registration cancelled by user.");
|
|
610
|
+
}
|
|
611
|
+
if (err_1.name === "InvalidStateError") {
|
|
612
|
+
throw new Error("Passkey already registered for this user.");
|
|
613
|
+
}
|
|
614
|
+
throw err_1;
|
|
615
|
+
case 3: return [2 /*return*/];
|
|
602
616
|
}
|
|
603
617
|
});
|
|
604
618
|
});
|
|
@@ -1864,12 +1878,12 @@ var MFAOptions = function (_a) {
|
|
|
1864
1878
|
var idToken = context.authMode === "MSAL" ? context.idToken : "";
|
|
1865
1879
|
var authenticate = useWebAuthn().authenticate;
|
|
1866
1880
|
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 (
|
|
1881
|
+
var options, assertionResponse, error_1;
|
|
1882
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
1883
|
+
return __generator(this, function (_o) {
|
|
1884
|
+
switch (_o.label) {
|
|
1871
1885
|
case 0:
|
|
1872
|
-
|
|
1886
|
+
_o.trys.push([0, 4, , 5]);
|
|
1873
1887
|
// 1. Fetch authentication challenge from your server
|
|
1874
1888
|
console.log("Requesting authentication challenge from server...");
|
|
1875
1889
|
return [4 /*yield*/, axios.post(MFAEndpoints.RetrieveAuthChallenge, {}, {
|
|
@@ -1879,17 +1893,20 @@ var MFAOptions = function (_a) {
|
|
|
1879
1893
|
},
|
|
1880
1894
|
})];
|
|
1881
1895
|
case 1:
|
|
1882
|
-
options = (
|
|
1896
|
+
options = (_o.sent()).data;
|
|
1883
1897
|
console.log("Received challenge:", options);
|
|
1884
|
-
|
|
1898
|
+
__assign(__assign({}, options), { pubKeyCredParams: (_a = options.pubKeyCredParams) === null || _a === void 0 ? void 0 : _a.map(function (param) { return ({
|
|
1885
1899
|
type: "public-key",
|
|
1886
1900
|
alg: param.alg
|
|
1887
1901
|
}); }), 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
1902
|
// 2. Call the SDK to trigger the browser's passkey authentication UI
|
|
1889
1903
|
console.log("Calling SDK authenticate function...");
|
|
1890
|
-
return [4 /*yield*/, authenticate(
|
|
1904
|
+
return [4 /*yield*/, authenticate(__assign(__assign({}, options), { pubKeyCredParams: (_g = options.pubKeyCredParams) === null || _g === void 0 ? void 0 : _g.map(function (param) { return ({
|
|
1905
|
+
type: "public-key",
|
|
1906
|
+
alg: param.alg
|
|
1907
|
+
}); }), 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
1908
|
case 2:
|
|
1892
|
-
assertionResponse =
|
|
1909
|
+
assertionResponse = _o.sent();
|
|
1893
1910
|
console.log("Authentication assertion received from client:", assertionResponse);
|
|
1894
1911
|
// 3. Send the assertion back to the server for verification
|
|
1895
1912
|
console.log("Sending assertion to server for verification...");
|
|
@@ -1901,11 +1918,11 @@ var MFAOptions = function (_a) {
|
|
|
1901
1918
|
withCredentials: true, // credentials: 'include'
|
|
1902
1919
|
})];
|
|
1903
1920
|
case 3:
|
|
1904
|
-
|
|
1921
|
+
_o.sent();
|
|
1905
1922
|
sonner.toast.success("🔑 Sign-in successful!");
|
|
1906
1923
|
return [3 /*break*/, 5];
|
|
1907
1924
|
case 4:
|
|
1908
|
-
error_1 =
|
|
1925
|
+
error_1 = _o.sent();
|
|
1909
1926
|
console.error("Authentication failed:", error_1);
|
|
1910
1927
|
sonner.toast.error("❌ Could not sign in.");
|
|
1911
1928
|
return [3 /*break*/, 5];
|