@nauth-toolkit/client-angular 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.
|
@@ -1192,11 +1192,12 @@ class AuthService {
|
|
|
1192
1192
|
/**
|
|
1193
1193
|
* Get MFA devices for the current user.
|
|
1194
1194
|
*
|
|
1195
|
-
* @returns Promise of MFA devices
|
|
1195
|
+
* @returns Promise of MFA devices response
|
|
1196
1196
|
*
|
|
1197
1197
|
* @example
|
|
1198
1198
|
* ```typescript
|
|
1199
|
-
* const
|
|
1199
|
+
* const result = await this.auth.getMfaDevices();
|
|
1200
|
+
* console.log('Devices:', result.devices);
|
|
1200
1201
|
* ```
|
|
1201
1202
|
*/
|
|
1202
1203
|
async getMfaDevices() {
|
|
@@ -1205,12 +1206,19 @@ class AuthService {
|
|
|
1205
1206
|
/**
|
|
1206
1207
|
* Setup MFA device (authenticated user).
|
|
1207
1208
|
*
|
|
1209
|
+
* Returns method-specific setup information:
|
|
1210
|
+
* - TOTP: { secret, qrCode, manualEntryKey }
|
|
1211
|
+
* - SMS: { maskedPhone } or { deviceId, autoCompleted: true }
|
|
1212
|
+
* - Email: { maskedEmail } or { deviceId, autoCompleted: true }
|
|
1213
|
+
* - Passkey: WebAuthn registration options
|
|
1214
|
+
*
|
|
1208
1215
|
* @param method - MFA method to set up
|
|
1209
|
-
* @returns Promise of setup data
|
|
1216
|
+
* @returns Promise of setup data response
|
|
1210
1217
|
*
|
|
1211
1218
|
* @example
|
|
1212
1219
|
* ```typescript
|
|
1213
|
-
* const
|
|
1220
|
+
* const result = await this.auth.setupMfaDevice('totp');
|
|
1221
|
+
* console.log('QR Code:', result.setupData.qrCode);
|
|
1214
1222
|
* ```
|
|
1215
1223
|
*/
|
|
1216
1224
|
async setupMfaDevice(method) {
|
|
@@ -1219,14 +1227,63 @@ class AuthService {
|
|
|
1219
1227
|
/**
|
|
1220
1228
|
* Verify MFA setup (authenticated user).
|
|
1221
1229
|
*
|
|
1222
|
-
*
|
|
1223
|
-
* @param setupData - Setup data from setupMfaDevice
|
|
1224
|
-
* @param deviceName - Optional device name
|
|
1225
|
-
* @returns Promise with device ID
|
|
1230
|
+
* Completes MFA device setup by verifying the setup data. The structure of `setupData` varies by method:
|
|
1226
1231
|
*
|
|
1227
|
-
*
|
|
1232
|
+
* **TOTP:**
|
|
1233
|
+
* - Requires both `secret` (from `getSetupData()` response) and `code` (from authenticator app)
|
|
1234
|
+
* - Example: `{ secret: 'JBSWY3DPEHPK3PXP', code: '123456' }`
|
|
1235
|
+
*
|
|
1236
|
+
* **SMS:**
|
|
1237
|
+
* - Requires `phoneNumber` and `code` (verification code sent to phone)
|
|
1238
|
+
* - Example: `{ phoneNumber: '+1234567890', code: '123456' }`
|
|
1239
|
+
*
|
|
1240
|
+
* **Email:**
|
|
1241
|
+
* - Requires `code` (verification code sent to email)
|
|
1242
|
+
* - Example: `{ code: '123456' }`
|
|
1243
|
+
*
|
|
1244
|
+
* **Passkey:**
|
|
1245
|
+
* - Requires `credential` (WebAuthn credential from registration) and `expectedChallenge`
|
|
1246
|
+
* - Example: `{ credential: {...}, expectedChallenge: '...' }`
|
|
1247
|
+
*
|
|
1248
|
+
* @param method - MFA method ('totp', 'sms', 'email', 'passkey')
|
|
1249
|
+
* @param setupData - Method-specific setup verification data
|
|
1250
|
+
* @param deviceName - Optional device name (can also be included in setupData for some methods)
|
|
1251
|
+
* @returns Promise with device ID of the created MFA device
|
|
1252
|
+
*
|
|
1253
|
+
* @example TOTP Setup
|
|
1228
1254
|
* ```typescript
|
|
1229
|
-
*
|
|
1255
|
+
* // Step 1: Get setup data
|
|
1256
|
+
* const setupData = await this.auth.setupMfaDevice('totp');
|
|
1257
|
+
* // Returns: { setupData: { secret: 'JBSWY3DPEHPK3PXP', qrCode: '...', ... } }
|
|
1258
|
+
*
|
|
1259
|
+
* // Step 2: User scans QR code and enters code from authenticator app
|
|
1260
|
+
* const code = '123456'; // From authenticator app
|
|
1261
|
+
*
|
|
1262
|
+
* // Step 3: Verify setup (requires both secret and code)
|
|
1263
|
+
* const result = await this.auth.verifyMfaSetup('totp', {
|
|
1264
|
+
* secret: setupData.setupData.secret,
|
|
1265
|
+
* code: code,
|
|
1266
|
+
* }, 'Google Authenticator');
|
|
1267
|
+
* // Returns: { deviceId: 123 }
|
|
1268
|
+
* ```
|
|
1269
|
+
*
|
|
1270
|
+
* @example SMS Setup
|
|
1271
|
+
* ```typescript
|
|
1272
|
+
* const result = await this.auth.verifyMfaSetup('sms', {
|
|
1273
|
+
* phoneNumber: '+1234567890', // Phone number receiving the code
|
|
1274
|
+
* code: '123456', // Code sent to phone
|
|
1275
|
+
* }, 'My iPhone');
|
|
1276
|
+
* ```
|
|
1277
|
+
*
|
|
1278
|
+
* @example Passkey Setup
|
|
1279
|
+
* ```typescript
|
|
1280
|
+
* const credential = await navigator.credentials.create({
|
|
1281
|
+
* publicKey: setupData.setupData.options
|
|
1282
|
+
* });
|
|
1283
|
+
* const result = await this.auth.verifyMfaSetup('passkey', {
|
|
1284
|
+
* credential: credential,
|
|
1285
|
+
* expectedChallenge: setupData.setupData.challenge,
|
|
1286
|
+
* }, 'MacBook Pro');
|
|
1230
1287
|
* ```
|
|
1231
1288
|
*/
|
|
1232
1289
|
async verifyMfaSetup(method, setupData, deviceName) {
|
|
@@ -1753,7 +1810,7 @@ function createNAuthAuthHttpInterceptor(params) {
|
|
|
1753
1810
|
// JSON mode: we need the new access token to retry + unblock queued requests.
|
|
1754
1811
|
const newToken = tokenDelivery === 'json' ? response.accessToken : 'success';
|
|
1755
1812
|
if (tokenDelivery === 'json' && (!newToken || newToken === 'success')) {
|
|
1756
|
-
//
|
|
1813
|
+
// WARNING: Without an access token we cannot safely retry requests in JSON mode.
|
|
1757
1814
|
throw new Error('Token refresh did not return an access token');
|
|
1758
1815
|
}
|
|
1759
1816
|
refreshTokenSubject.next(newToken ?? 'success');
|