@nauth-toolkit/client 0.1.112 → 0.1.115
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.cjs +85 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +85 -3
- package/dist/index.d.ts +85 -3
- package/dist/index.mjs +85 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1775,7 +1775,8 @@ var NAuthClient = class {
|
|
|
1775
1775
|
*/
|
|
1776
1776
|
async respondToChallenge(response) {
|
|
1777
1777
|
if (this.selectedDeviceId !== void 0 && response.type === "MFA_REQUIRED" /* MFA_REQUIRED */ && (response.method === "totp" || response.method === "passkey")) {
|
|
1778
|
-
|
|
1778
|
+
const mfaResponse = response;
|
|
1779
|
+
mfaResponse.deviceId = this.selectedDeviceId;
|
|
1779
1780
|
}
|
|
1780
1781
|
if (response.type === "MFA_SETUP_REQUIRED" /* MFA_SETUP_REQUIRED */ && response.method === "totp") {
|
|
1781
1782
|
const setupData = response.setupData;
|
|
@@ -2013,18 +2014,100 @@ var NAuthClient = class {
|
|
|
2013
2014
|
}
|
|
2014
2015
|
/**
|
|
2015
2016
|
* Get MFA devices.
|
|
2017
|
+
*
|
|
2018
|
+
* @returns Promise of MFA devices response
|
|
2019
|
+
*
|
|
2020
|
+
* @example
|
|
2021
|
+
* ```typescript
|
|
2022
|
+
* const result = await client.getMfaDevices();
|
|
2023
|
+
* console.log('Devices:', result.devices);
|
|
2024
|
+
* ```
|
|
2016
2025
|
*/
|
|
2017
2026
|
async getMfaDevices() {
|
|
2018
2027
|
return this.get(this.config.endpoints.mfaDevices, true);
|
|
2019
2028
|
}
|
|
2020
2029
|
/**
|
|
2021
2030
|
* Setup MFA device (authenticated user).
|
|
2031
|
+
*
|
|
2032
|
+
* Returns method-specific setup information:
|
|
2033
|
+
* - TOTP: { secret, qrCode, manualEntryKey }
|
|
2034
|
+
* - SMS: { maskedPhone } or { deviceId, autoCompleted: true }
|
|
2035
|
+
* - Email: { maskedEmail } or { deviceId, autoCompleted: true }
|
|
2036
|
+
* - Passkey: WebAuthn registration options
|
|
2037
|
+
*
|
|
2038
|
+
* @param method - MFA method to set up
|
|
2039
|
+
* @returns Promise of setup data response
|
|
2040
|
+
*
|
|
2041
|
+
* @example
|
|
2042
|
+
* ```typescript
|
|
2043
|
+
* const result = await client.setupMfaDevice('totp');
|
|
2044
|
+
* console.log('QR Code:', result.setupData.qrCode);
|
|
2045
|
+
* ```
|
|
2022
2046
|
*/
|
|
2023
2047
|
async setupMfaDevice(method) {
|
|
2024
2048
|
return this.post(this.config.endpoints.mfaSetupData, { methodName: method }, true);
|
|
2025
2049
|
}
|
|
2026
2050
|
/**
|
|
2027
2051
|
* Verify MFA setup (authenticated user).
|
|
2052
|
+
*
|
|
2053
|
+
* Completes MFA device setup by verifying the setup data. The structure of `setupData` varies by method:
|
|
2054
|
+
*
|
|
2055
|
+
* **TOTP:**
|
|
2056
|
+
* - Requires both `secret` (from `getSetupData()` response) and `code` (from authenticator app)
|
|
2057
|
+
* - Example: `{ secret: 'JBSWY3DPEHPK3PXP', code: '123456' }`
|
|
2058
|
+
*
|
|
2059
|
+
* **SMS:**
|
|
2060
|
+
* - Requires `phoneNumber` and `code` (verification code sent to phone)
|
|
2061
|
+
* - Example: `{ phoneNumber: '+1234567890', code: '123456' }`
|
|
2062
|
+
*
|
|
2063
|
+
* **Email:**
|
|
2064
|
+
* - Requires `code` (verification code sent to email)
|
|
2065
|
+
* - Example: `{ code: '123456' }`
|
|
2066
|
+
*
|
|
2067
|
+
* **Passkey:**
|
|
2068
|
+
* - Requires `credential` (WebAuthn credential from registration) and `expectedChallenge`
|
|
2069
|
+
* - Example: `{ credential: {...}, expectedChallenge: '...' }`
|
|
2070
|
+
*
|
|
2071
|
+
* @param method - MFA method ('totp', 'sms', 'email', 'passkey')
|
|
2072
|
+
* @param setupData - Method-specific setup verification data
|
|
2073
|
+
* @param deviceName - Optional device name (can also be included in setupData for some methods)
|
|
2074
|
+
* @returns Promise with device ID of the created MFA device
|
|
2075
|
+
*
|
|
2076
|
+
* @example TOTP Setup
|
|
2077
|
+
* ```typescript
|
|
2078
|
+
* // Step 1: Get setup data
|
|
2079
|
+
* const setupData = await client.setupMfaDevice('totp');
|
|
2080
|
+
* // Returns: { setupData: { secret: 'JBSWY3DPEHPK3PXP', qrCode: '...', ... } }
|
|
2081
|
+
*
|
|
2082
|
+
* // Step 2: User scans QR code and enters code from authenticator app
|
|
2083
|
+
* const code = '123456'; // From authenticator app
|
|
2084
|
+
*
|
|
2085
|
+
* // Step 3: Verify setup (requires both secret and code)
|
|
2086
|
+
* const result = await client.verifyMfaSetup('totp', {
|
|
2087
|
+
* secret: setupData.setupData.secret,
|
|
2088
|
+
* code: code,
|
|
2089
|
+
* }, 'Google Authenticator');
|
|
2090
|
+
* // Returns: { deviceId: 123 }
|
|
2091
|
+
* ```
|
|
2092
|
+
*
|
|
2093
|
+
* @example SMS Setup
|
|
2094
|
+
* ```typescript
|
|
2095
|
+
* const result = await client.verifyMfaSetup('sms', {
|
|
2096
|
+
* phoneNumber: '+1234567890', // Phone number receiving the code
|
|
2097
|
+
* code: '123456', // Code sent to phone
|
|
2098
|
+
* }, 'My iPhone');
|
|
2099
|
+
* ```
|
|
2100
|
+
*
|
|
2101
|
+
* @example Passkey Setup
|
|
2102
|
+
* ```typescript
|
|
2103
|
+
* const credential = await navigator.credentials.create({
|
|
2104
|
+
* publicKey: setupData.setupData.options
|
|
2105
|
+
* });
|
|
2106
|
+
* const result = await client.verifyMfaSetup('passkey', {
|
|
2107
|
+
* credential: credential,
|
|
2108
|
+
* expectedChallenge: setupData.setupData.challenge,
|
|
2109
|
+
* }, 'MacBook Pro');
|
|
2110
|
+
* ```
|
|
2028
2111
|
*/
|
|
2029
2112
|
async verifyMfaSetup(method, setupData, deviceName) {
|
|
2030
2113
|
return this.post(
|
|
@@ -2038,7 +2121,7 @@ var NAuthClient = class {
|
|
|
2038
2121
|
/**
|
|
2039
2122
|
* Remove ALL MFA devices for a specific method type.
|
|
2040
2123
|
*
|
|
2041
|
-
*
|
|
2124
|
+
* WARNING: This removes ALL devices of the specified method.
|
|
2042
2125
|
* For example, if you have 3 TOTP devices, this will remove all 3.
|
|
2043
2126
|
*
|
|
2044
2127
|
* **Prefer `removeMfaDeviceById()`** to remove individual devices.
|