@ideem/zsm-client-sdk 2.2.3 → 2.2.4
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/package.json +1 -1
- package/zsm-client-sdk.js +96 -78
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name" : "@ideem/zsm-client-sdk",
|
|
3
|
-
"version" : "2.2.
|
|
3
|
+
"version" : "2.2.4",
|
|
4
4
|
"description" : "A monolithic library exporting UMFAClient and FIDO2Client.",
|
|
5
5
|
"author" : "@JJ (Jason Jurusz) <jj@useideem.com>/<nerdy.deeds@done.cheap>",
|
|
6
6
|
"keywords" : [ "ideem", "zsm", "zsm-client-sdk", "UMFAClient", "FIDO2Client", "library", "UMFA", "FIDO2", "client", "authentication", "javascript", "multi-factor", "webauthn", "authentication", "security" ],
|
package/zsm-client-sdk.js
CHANGED
|
@@ -1536,10 +1536,15 @@ function base64ToArrayBuffer(base64) {
|
|
|
1536
1536
|
headers : Object.assign(this.xhrHeaders, ((!headers?.Authorization) ? {'Authorization': `Bearer ${this.#apiKey}`} : {}), headers),
|
|
1537
1537
|
body : JSON.stringify(body)
|
|
1538
1538
|
};
|
|
1539
|
-
return
|
|
1540
|
-
.then(response => response.ok
|
|
1541
|
-
|
|
1542
|
-
|
|
1539
|
+
return fetch(url, fetchObj)
|
|
1540
|
+
.then(response => console.log('response, response.ok :', response, response.ok) || response)
|
|
1541
|
+
.then(response => {
|
|
1542
|
+
if(!response.ok) throw new Error(`Request failed: ${response.statusText}`);
|
|
1543
|
+
let responseJSON = response.json();
|
|
1544
|
+
console.log('responseJSON :', responseJSON);
|
|
1545
|
+
return responseJSON;
|
|
1546
|
+
})
|
|
1547
|
+
.catch(response => console.error('makePostRequest ERROR :: ', response)
|
|
1543
1548
|
);
|
|
1544
1549
|
}
|
|
1545
1550
|
|
|
@@ -1629,7 +1634,7 @@ function base64ToArrayBuffer(base64) {
|
|
|
1629
1634
|
"api_path" : "INLINE_WASM",
|
|
1630
1635
|
"installation_description" : (typeof window !== 'undefined' ? window?.navigator?.userAgent : ''),
|
|
1631
1636
|
"log_level" : 'Debug',
|
|
1632
|
-
"request_timeout_ms" :
|
|
1637
|
+
"request_timeout_ms" : 100000,
|
|
1633
1638
|
"retry_count" : 0,
|
|
1634
1639
|
"consumer_id" : "",
|
|
1635
1640
|
};
|
|
@@ -1688,22 +1693,21 @@ function base64ToArrayBuffer(base64) {
|
|
|
1688
1693
|
* @param {string} username - The username.
|
|
1689
1694
|
* @returns {Promise<string>} Resolves with the identity_id if it exists.
|
|
1690
1695
|
*/
|
|
1691
|
-
webauthnRetrieve = (userIdentifier, silent=false) => {
|
|
1696
|
+
webauthnRetrieve = async (userIdentifier, silent=false) => {
|
|
1692
1697
|
this.credentialID = null;
|
|
1693
1698
|
if(!silent) this.status='CREDENTIAL_RETRIEVING';
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
.
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
});
|
|
1699
|
+
await this.initializeZsm(userIdentifier)
|
|
1700
|
+
const retrievedUser = await this.#zsmApi.webauthn_retrieve(userIdentifier);
|
|
1701
|
+
if(retrievedUser.error) return false;
|
|
1702
|
+
|
|
1703
|
+
const userData = retrievedUser.result;
|
|
1704
|
+
|
|
1705
|
+
const userDataRes = (!Object.entries(userData).length) ? Object.fromEntries(userData.entries()) : userData;
|
|
1706
|
+
const userRawId = userDataRes.rawId || undefined;
|
|
1707
|
+
|
|
1708
|
+
if(!userRawId) return false;
|
|
1709
|
+
this.credentialID = userRawId;
|
|
1710
|
+
return userRawId;
|
|
1707
1711
|
}
|
|
1708
1712
|
|
|
1709
1713
|
/**
|
|
@@ -1712,17 +1716,19 @@ function base64ToArrayBuffer(base64) {
|
|
|
1712
1716
|
* @param {boolean} createNewIdentity Create a new identity if one does not already exist
|
|
1713
1717
|
* @returns {Promise<Object>} Resolves with the retrieved identity if it exists.
|
|
1714
1718
|
*/
|
|
1715
|
-
checkIdentity = (userIdentifier, createNewIdentity=false) => {
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1719
|
+
checkIdentity = async (userIdentifier, createNewIdentity=false) => {
|
|
1720
|
+
try {
|
|
1721
|
+
this.status='CHECKING_IDENTITY_STARTING';
|
|
1722
|
+
await this.initializeZsm(userIdentifier);
|
|
1723
|
+
const resultOfCheck = await this.#relyingParty.checkServerSideIdentity(createNewIdentity);
|
|
1724
|
+
if(!resultOfCheck) throw new Error('Unable to communicate with identity server!');
|
|
1725
|
+
const identityID = resultOfCheck.identity_id;
|
|
1726
|
+
if(!identityID) throw new Error('Unable to acquire identity_id!');
|
|
1727
|
+
return identityID;
|
|
1728
|
+
} catch(err) {
|
|
1722
1729
|
this.status='CHECKING_IDENTITY_FAILED';
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
})
|
|
1730
|
+
return Promise.reject(err);
|
|
1731
|
+
}
|
|
1726
1732
|
}
|
|
1727
1733
|
|
|
1728
1734
|
/**
|
|
@@ -1730,24 +1736,28 @@ function base64ToArrayBuffer(base64) {
|
|
|
1730
1736
|
* @param {string} userIdentifier - The userIdentifier.
|
|
1731
1737
|
* @returns {Promise<Object>} Resolves with the created credential.
|
|
1732
1738
|
*/
|
|
1733
|
-
webauthnCreate = userIdentifier => {
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
.
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
.
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1739
|
+
webauthnCreate = async (userIdentifier) => {
|
|
1740
|
+
try {
|
|
1741
|
+
this.status='ENROLLMENT_STARTING';
|
|
1742
|
+
await this.initializeZsm(userIdentifier);
|
|
1743
|
+
const publicKey = await this.#relyingParty.registrationStart();
|
|
1744
|
+
const webAuthnRes = await this.#zsmApi.webauthn_create(publicKey);
|
|
1745
|
+
|
|
1746
|
+
if(!webAuthnRes?.result) throw new Error('[mpc_round] webauthnCreate failed');
|
|
1747
|
+
|
|
1748
|
+
const credObjRAW = webAuthnRes.result;
|
|
1749
|
+
const credential = (!Object.entries(credObjRAW).length) ? Object.fromEntries(credObjRAW.entries()) : credObjRAW;
|
|
1750
|
+
|
|
1751
|
+
if(!credential.response) throw new Error('Unable to acquire attestation object!');
|
|
1752
|
+
credential.response = (!Object.entries(credential.response).length) ? Object.fromEntries(credential.response.entries()) : credential.response;
|
|
1753
|
+
|
|
1754
|
+
const regObject = await this.#relyingParty.registrationFinish(credential);
|
|
1755
|
+
return regObject;
|
|
1756
|
+
} catch(err) {
|
|
1757
|
+
this.status='ENROLLMENT_FAILED';
|
|
1758
|
+
this.#relyingParty.clearEnrollmentCredentials();
|
|
1759
|
+
return Promise.reject(err);
|
|
1760
|
+
}
|
|
1751
1761
|
}
|
|
1752
1762
|
|
|
1753
1763
|
/**
|
|
@@ -1755,32 +1765,40 @@ function base64ToArrayBuffer(base64) {
|
|
|
1755
1765
|
* @param {string} userIdentifier - The userIdentifier.
|
|
1756
1766
|
* @returns {Promise<Object>} Resolves with the signed challenge and authentication details.
|
|
1757
1767
|
*/
|
|
1758
|
-
webauthnGet = userIdentifier => {
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1768
|
+
webauthnGet = async (userIdentifier) => {
|
|
1769
|
+
try {
|
|
1770
|
+
this.status='AUTHENTICATION_STARTING';
|
|
1771
|
+
await this.initializeZsm(userIdentifier)
|
|
1772
|
+
if(!this.isEnrolled) throw new Error(`Credential is missing for ${userIdentifier}`);
|
|
1773
|
+
|
|
1774
|
+
const authData = await this.#relyingParty.authenticationStart(this.credentialID);
|
|
1775
|
+
if(!authData?.rcr?.publicKey) throw new Error(`Unable to acquire public key!`);
|
|
1776
|
+
|
|
1777
|
+
const publicKey = authData.rcr.publicKey;
|
|
1778
|
+
const challenge = publicKey.challenge;
|
|
1779
|
+
|
|
1780
|
+
const webAuthnRes = await this.#zsmApi.webauthn_get(publicKey);
|
|
1781
|
+
const credObjRAW = webAuthnRes.result;
|
|
1782
|
+
const credential = (!Object.entries(credObjRAW).length) ? Object.fromEntries(credObjRAW.entries()) : credObjRAW;
|
|
1783
|
+
credential.challenge = challenge;
|
|
1784
|
+
|
|
1785
|
+
if(!credential.response) throw new Error('Unable to acquire credential challenge response!');
|
|
1786
|
+
credential.response = (!Object.entries(credential.response).length) ? Object.fromEntries(credential.response.entries()) : credential.response;
|
|
1787
|
+
|
|
1788
|
+
const authObject = await this.#relyingParty.authenticationFinish(credential);
|
|
1789
|
+
const authOutput = {
|
|
1790
|
+
signature : credential.response.signature,
|
|
1791
|
+
signedChallenge : credential.response.clientDataJSON,
|
|
1792
|
+
user_id : authObject.user_id,
|
|
1793
|
+
token : authObject.token,
|
|
1794
|
+
challenge,
|
|
1795
|
+
credential
|
|
1796
|
+
}
|
|
1797
|
+
return authOutput;
|
|
1798
|
+
} catch(err) {
|
|
1780
1799
|
this.status='AUTHENTICATION_FAILED';
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
})
|
|
1800
|
+
return Promise.reject(err);
|
|
1801
|
+
}
|
|
1784
1802
|
}
|
|
1785
1803
|
|
|
1786
1804
|
/**
|
|
@@ -1840,16 +1858,16 @@ function base64ToArrayBuffer(base64) {
|
|
|
1840
1858
|
}
|
|
1841
1859
|
|
|
1842
1860
|
authenticate = async (userIdentifier=this.userIdentifier) => {
|
|
1843
|
-
try {
|
|
1861
|
+
// try {
|
|
1844
1862
|
let userIsEnrolled = await this.checkEnrollment(userIdentifier);
|
|
1845
1863
|
if(userIsEnrolled === false) throw(`${userIdentifier} is not enrolled.`);
|
|
1846
1864
|
let authCredentalIdentity = await this.#zsmAPI.webauthnGet(userIdentifier);
|
|
1847
1865
|
return authCredentalIdentity;
|
|
1848
|
-
} catch(e) {
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
}
|
|
1866
|
+
// } catch(e) {
|
|
1867
|
+
// e = e.message || e;
|
|
1868
|
+
// e = 'Unable to authenticate user:' + e;
|
|
1869
|
+
// return new Error(e);
|
|
1870
|
+
// }
|
|
1853
1871
|
}
|
|
1854
1872
|
|
|
1855
1873
|
resetDevice = async () => { this.#zsmAPI.webauthnReset(); }
|