@nauth-toolkit/client 0.1.111 → 0.1.114
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 +96 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +101 -10
- package/dist/index.d.ts +101 -10
- package/dist/index.mjs +96 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -191,6 +191,7 @@ var defaultAdminEndpoints = {
|
|
|
191
191
|
getUserSessions: "/users/:sub/sessions",
|
|
192
192
|
logoutAll: "/users/:sub/logout-all",
|
|
193
193
|
getMfaStatus: "/users/:sub/mfa/status",
|
|
194
|
+
getMfaDevices: "/users/:sub/mfa/devices",
|
|
194
195
|
removeMfaDeviceById: "/mfa/devices/:deviceId",
|
|
195
196
|
setPreferredMfaDevice: "/users/:sub/mfa/devices/:deviceId/preferred",
|
|
196
197
|
setMfaExemption: "/mfa/exemption",
|
|
@@ -1151,21 +1152,25 @@ var AdminOperations = class {
|
|
|
1151
1152
|
return this.get(path);
|
|
1152
1153
|
}
|
|
1153
1154
|
/**
|
|
1154
|
-
*
|
|
1155
|
+
* Get MFA devices for a user
|
|
1155
1156
|
*
|
|
1156
|
-
*
|
|
1157
|
-
* Remove MFA devices for a user
|
|
1157
|
+
* Returns all active MFA devices for a user including device id, name, type, and isPreferred status.
|
|
1158
1158
|
*
|
|
1159
1159
|
* @param sub - User UUID
|
|
1160
|
-
* @
|
|
1161
|
-
* @returns Success message
|
|
1160
|
+
* @returns Response containing array of MFA devices
|
|
1162
1161
|
* @throws {NAuthClientError} If operation fails
|
|
1163
1162
|
*
|
|
1164
1163
|
* @example
|
|
1165
1164
|
* ```typescript
|
|
1166
|
-
* await client.admin.
|
|
1165
|
+
* const result = await client.admin.getMfaDevices('user-uuid');
|
|
1166
|
+
* console.log('Devices:', result.devices);
|
|
1167
|
+
* // [{ id: 1, name: 'My Authenticator', type: 'totp', isPreferred: true, ... }]
|
|
1167
1168
|
* ```
|
|
1168
1169
|
*/
|
|
1170
|
+
async getMfaDevices(sub) {
|
|
1171
|
+
const path = this.buildAdminUrl(this.adminEndpoints.getMfaDevices, { sub });
|
|
1172
|
+
return this.get(path);
|
|
1173
|
+
}
|
|
1169
1174
|
/**
|
|
1170
1175
|
* Remove a single MFA device by device ID (admin).
|
|
1171
1176
|
*
|
|
@@ -1770,7 +1775,8 @@ var NAuthClient = class {
|
|
|
1770
1775
|
*/
|
|
1771
1776
|
async respondToChallenge(response) {
|
|
1772
1777
|
if (this.selectedDeviceId !== void 0 && response.type === "MFA_REQUIRED" /* MFA_REQUIRED */ && (response.method === "totp" || response.method === "passkey")) {
|
|
1773
|
-
|
|
1778
|
+
const mfaResponse = response;
|
|
1779
|
+
mfaResponse.deviceId = this.selectedDeviceId;
|
|
1774
1780
|
}
|
|
1775
1781
|
if (response.type === "MFA_SETUP_REQUIRED" /* MFA_SETUP_REQUIRED */ && response.method === "totp") {
|
|
1776
1782
|
const setupData = response.setupData;
|
|
@@ -2008,18 +2014,100 @@ var NAuthClient = class {
|
|
|
2008
2014
|
}
|
|
2009
2015
|
/**
|
|
2010
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
|
+
* ```
|
|
2011
2025
|
*/
|
|
2012
2026
|
async getMfaDevices() {
|
|
2013
2027
|
return this.get(this.config.endpoints.mfaDevices, true);
|
|
2014
2028
|
}
|
|
2015
2029
|
/**
|
|
2016
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
|
+
* ```
|
|
2017
2046
|
*/
|
|
2018
2047
|
async setupMfaDevice(method) {
|
|
2019
2048
|
return this.post(this.config.endpoints.mfaSetupData, { methodName: method }, true);
|
|
2020
2049
|
}
|
|
2021
2050
|
/**
|
|
2022
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
|
+
* ```
|
|
2023
2111
|
*/
|
|
2024
2112
|
async verifyMfaSetup(method, setupData, deviceName) {
|
|
2025
2113
|
return this.post(
|
|
@@ -2033,7 +2121,7 @@ var NAuthClient = class {
|
|
|
2033
2121
|
/**
|
|
2034
2122
|
* Remove ALL MFA devices for a specific method type.
|
|
2035
2123
|
*
|
|
2036
|
-
*
|
|
2124
|
+
* WARNING: This removes ALL devices of the specified method.
|
|
2037
2125
|
* For example, if you have 3 TOTP devices, this will remove all 3.
|
|
2038
2126
|
*
|
|
2039
2127
|
* **Prefer `removeMfaDeviceById()`** to remove individual devices.
|