@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.d.mts
CHANGED
|
@@ -44,6 +44,12 @@ interface RemoveMFADeviceResponse {
|
|
|
44
44
|
removedMethod: MFADeviceMethod;
|
|
45
45
|
mfaDisabled: boolean;
|
|
46
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Response from getting user MFA devices.
|
|
49
|
+
*/
|
|
50
|
+
interface GetMFADevicesResponse {
|
|
51
|
+
devices: MFADevice[];
|
|
52
|
+
}
|
|
47
53
|
/**
|
|
48
54
|
* MFA setup data returned by providers.
|
|
49
55
|
*/
|
|
@@ -726,6 +732,8 @@ interface NAuthAdminEndpoints {
|
|
|
726
732
|
logoutAll: string;
|
|
727
733
|
/** GET /users/:sub/mfa/status - Get MFA status */
|
|
728
734
|
getMfaStatus: string;
|
|
735
|
+
/** GET /users/:sub/mfa/devices - Get MFA devices */
|
|
736
|
+
getMfaDevices: string;
|
|
729
737
|
/** DELETE /mfa/devices/:deviceId - Remove a single MFA device by id */
|
|
730
738
|
removeMfaDeviceById: string;
|
|
731
739
|
/** POST /users/:sub/mfa/devices/:deviceId/preferred - Set preferred MFA device */
|
|
@@ -2524,21 +2532,22 @@ declare class AdminOperations {
|
|
|
2524
2532
|
*/
|
|
2525
2533
|
getMfaStatus(sub: string): Promise<MFAStatus>;
|
|
2526
2534
|
/**
|
|
2527
|
-
*
|
|
2535
|
+
* Get MFA devices for a user
|
|
2528
2536
|
*
|
|
2529
|
-
*
|
|
2530
|
-
* Remove MFA devices for a user
|
|
2537
|
+
* Returns all active MFA devices for a user including device id, name, type, and isPreferred status.
|
|
2531
2538
|
*
|
|
2532
2539
|
* @param sub - User UUID
|
|
2533
|
-
* @
|
|
2534
|
-
* @returns Success message
|
|
2540
|
+
* @returns Response containing array of MFA devices
|
|
2535
2541
|
* @throws {NAuthClientError} If operation fails
|
|
2536
2542
|
*
|
|
2537
2543
|
* @example
|
|
2538
2544
|
* ```typescript
|
|
2539
|
-
* await client.admin.
|
|
2545
|
+
* const result = await client.admin.getMfaDevices('user-uuid');
|
|
2546
|
+
* console.log('Devices:', result.devices);
|
|
2547
|
+
* // [{ id: 1, name: 'My Authenticator', type: 'totp', isPreferred: true, ... }]
|
|
2540
2548
|
* ```
|
|
2541
2549
|
*/
|
|
2550
|
+
getMfaDevices(sub: string): Promise<GetMFADevicesResponse>;
|
|
2542
2551
|
/**
|
|
2543
2552
|
* Remove a single MFA device by device ID (admin).
|
|
2544
2553
|
*
|
|
@@ -2970,14 +2979,96 @@ declare class NAuthClient {
|
|
|
2970
2979
|
getMfaStatus(): Promise<MFAStatus>;
|
|
2971
2980
|
/**
|
|
2972
2981
|
* Get MFA devices.
|
|
2982
|
+
*
|
|
2983
|
+
* @returns Promise of MFA devices response
|
|
2984
|
+
*
|
|
2985
|
+
* @example
|
|
2986
|
+
* ```typescript
|
|
2987
|
+
* const result = await client.getMfaDevices();
|
|
2988
|
+
* console.log('Devices:', result.devices);
|
|
2989
|
+
* ```
|
|
2973
2990
|
*/
|
|
2974
|
-
getMfaDevices(): Promise<
|
|
2991
|
+
getMfaDevices(): Promise<GetMFADevicesResponse>;
|
|
2975
2992
|
/**
|
|
2976
2993
|
* Setup MFA device (authenticated user).
|
|
2994
|
+
*
|
|
2995
|
+
* Returns method-specific setup information:
|
|
2996
|
+
* - TOTP: { secret, qrCode, manualEntryKey }
|
|
2997
|
+
* - SMS: { maskedPhone } or { deviceId, autoCompleted: true }
|
|
2998
|
+
* - Email: { maskedEmail } or { deviceId, autoCompleted: true }
|
|
2999
|
+
* - Passkey: WebAuthn registration options
|
|
3000
|
+
*
|
|
3001
|
+
* @param method - MFA method to set up
|
|
3002
|
+
* @returns Promise of setup data response
|
|
3003
|
+
*
|
|
3004
|
+
* @example
|
|
3005
|
+
* ```typescript
|
|
3006
|
+
* const result = await client.setupMfaDevice('totp');
|
|
3007
|
+
* console.log('QR Code:', result.setupData.qrCode);
|
|
3008
|
+
* ```
|
|
2977
3009
|
*/
|
|
2978
|
-
setupMfaDevice(method: string): Promise<
|
|
3010
|
+
setupMfaDevice(method: string): Promise<GetSetupDataResponse>;
|
|
2979
3011
|
/**
|
|
2980
3012
|
* Verify MFA setup (authenticated user).
|
|
3013
|
+
*
|
|
3014
|
+
* Completes MFA device setup by verifying the setup data. The structure of `setupData` varies by method:
|
|
3015
|
+
*
|
|
3016
|
+
* **TOTP:**
|
|
3017
|
+
* - Requires both `secret` (from `getSetupData()` response) and `code` (from authenticator app)
|
|
3018
|
+
* - Example: `{ secret: 'JBSWY3DPEHPK3PXP', code: '123456' }`
|
|
3019
|
+
*
|
|
3020
|
+
* **SMS:**
|
|
3021
|
+
* - Requires `phoneNumber` and `code` (verification code sent to phone)
|
|
3022
|
+
* - Example: `{ phoneNumber: '+1234567890', code: '123456' }`
|
|
3023
|
+
*
|
|
3024
|
+
* **Email:**
|
|
3025
|
+
* - Requires `code` (verification code sent to email)
|
|
3026
|
+
* - Example: `{ code: '123456' }`
|
|
3027
|
+
*
|
|
3028
|
+
* **Passkey:**
|
|
3029
|
+
* - Requires `credential` (WebAuthn credential from registration) and `expectedChallenge`
|
|
3030
|
+
* - Example: `{ credential: {...}, expectedChallenge: '...' }`
|
|
3031
|
+
*
|
|
3032
|
+
* @param method - MFA method ('totp', 'sms', 'email', 'passkey')
|
|
3033
|
+
* @param setupData - Method-specific setup verification data
|
|
3034
|
+
* @param deviceName - Optional device name (can also be included in setupData for some methods)
|
|
3035
|
+
* @returns Promise with device ID of the created MFA device
|
|
3036
|
+
*
|
|
3037
|
+
* @example TOTP Setup
|
|
3038
|
+
* ```typescript
|
|
3039
|
+
* // Step 1: Get setup data
|
|
3040
|
+
* const setupData = await client.setupMfaDevice('totp');
|
|
3041
|
+
* // Returns: { setupData: { secret: 'JBSWY3DPEHPK3PXP', qrCode: '...', ... } }
|
|
3042
|
+
*
|
|
3043
|
+
* // Step 2: User scans QR code and enters code from authenticator app
|
|
3044
|
+
* const code = '123456'; // From authenticator app
|
|
3045
|
+
*
|
|
3046
|
+
* // Step 3: Verify setup (requires both secret and code)
|
|
3047
|
+
* const result = await client.verifyMfaSetup('totp', {
|
|
3048
|
+
* secret: setupData.setupData.secret,
|
|
3049
|
+
* code: code,
|
|
3050
|
+
* }, 'Google Authenticator');
|
|
3051
|
+
* // Returns: { deviceId: 123 }
|
|
3052
|
+
* ```
|
|
3053
|
+
*
|
|
3054
|
+
* @example SMS Setup
|
|
3055
|
+
* ```typescript
|
|
3056
|
+
* const result = await client.verifyMfaSetup('sms', {
|
|
3057
|
+
* phoneNumber: '+1234567890', // Phone number receiving the code
|
|
3058
|
+
* code: '123456', // Code sent to phone
|
|
3059
|
+
* }, 'My iPhone');
|
|
3060
|
+
* ```
|
|
3061
|
+
*
|
|
3062
|
+
* @example Passkey Setup
|
|
3063
|
+
* ```typescript
|
|
3064
|
+
* const credential = await navigator.credentials.create({
|
|
3065
|
+
* publicKey: setupData.setupData.options
|
|
3066
|
+
* });
|
|
3067
|
+
* const result = await client.verifyMfaSetup('passkey', {
|
|
3068
|
+
* credential: credential,
|
|
3069
|
+
* expectedChallenge: setupData.setupData.challenge,
|
|
3070
|
+
* }, 'MacBook Pro');
|
|
3071
|
+
* ```
|
|
2981
3072
|
*/
|
|
2982
3073
|
verifyMfaSetup(method: string, setupData: Record<string, unknown>, deviceName?: string): Promise<{
|
|
2983
3074
|
deviceId: number;
|
|
@@ -2985,7 +3076,7 @@ declare class NAuthClient {
|
|
|
2985
3076
|
/**
|
|
2986
3077
|
* Remove ALL MFA devices for a specific method type.
|
|
2987
3078
|
*
|
|
2988
|
-
*
|
|
3079
|
+
* WARNING: This removes ALL devices of the specified method.
|
|
2989
3080
|
* For example, if you have 3 TOTP devices, this will remove all 3.
|
|
2990
3081
|
*
|
|
2991
3082
|
* **Prefer `removeMfaDeviceById()`** to remove individual devices.
|
|
@@ -3461,4 +3552,4 @@ declare class FetchAdapter implements HttpAdapter {
|
|
|
3461
3552
|
request<T>(config: HttpRequest): Promise<HttpResponse<T>>;
|
|
3462
3553
|
}
|
|
3463
3554
|
|
|
3464
|
-
export { type AdminAuditHistoryRequest, AdminOperations, type AdminResetPasswordRequest, type AdminResetPasswordResponse, type AdminSignupRequest, type AdminSignupResponse, type AdminSignupSocialRequest, type AdminSignupSocialResponse, type AuditHistoryResponse, type AuthAuditEvent, type AuthAuditEventStatus, AuthAuditEventType, AuthChallenge, type AuthChallengeEvent, type AuthErrorEvent, type AuthEvent, type AuthEventListener, type AuthEventType, type AuthLoginEvent, type AuthLogoutEvent, type AuthRefreshEvent, type AuthResponse, type AuthResponseContext, type AuthSessionExpiredEvent, type AuthSignupEvent, type AuthSuccessEvent, type AuthUser, type AuthUserSummary, type BackupCodesResponse, type BaseChallengeResponse, BrowserStorage, type ChallengeResponse, ChallengeRouter, type ChangePasswordRequest, type ConfirmForgotPasswordRequest, type ConfirmForgotPasswordResponse, type DateFilter, type DeleteUserResponse, type DisableUserResponse, type EnableUserResponse, EventEmitter, FetchAdapter, type ForceChangePasswordResponse, type ForgotPasswordRequest, type ForgotPasswordResponse, type GetChallengeDataRequest, type GetChallengeDataResponse, type GetSetupDataRequest, type GetSetupDataResponse, type GetUserSessionsResponse, type GetUsersRequest, type GetUsersResponse, type HttpAdapter, type HttpRequest, type HttpResponse, InMemoryStorage, type LinkedAccountsResponse, type LoginRequest, type LogoutAllRequest, type LogoutRequest, type MFAChallengeMethod, type MFACodeResponse, type MFADevice, type MFADeviceMethod, type MFAMethod, type MFAPasskeyResponse, type MFASetupData, type MFASetupResponse, type MFAStatus, type MfaRoutesConfig, type NAuthAdminEndpoints, NAuthClient, type NAuthClientConfig, NAuthClientError, type NAuthEndpoints, type NAuthError, NAuthErrorCode, type NAuthRedirectsConfig, type NAuthStorageAdapter, type OAuthCallbackEvent, type OAuthCompletedEvent, type OAuthErrorEvent, type OAuthStartedEvent, type RecaptchaConfig, type RecaptchaVersion, type RemoveMFADeviceResponse, type ResendCodeRequest, type ResetPasswordWithCodeRequest, type ResetPasswordWithCodeResponse, type ResolvedNAuthClientConfig, type SignupRequest, type SocialLoginOptions, type SocialProvider, type SocialVerifyRequest, type TokenDeliveryMode, type TokenResponse, type UpdateProfileRequest, type UserSessionInfo, type VerifyEmailResponse, type VerifyPhoneCodeResponse, type VerifyPhoneCollectResponse, defaultAdminEndpoints, defaultEndpoints, getChallengeInstructions, getMFAMethod, getMaskedDestination, isOTPChallenge, requiresPhoneCollection, resolveConfig };
|
|
3555
|
+
export { type AdminAuditHistoryRequest, AdminOperations, type AdminResetPasswordRequest, type AdminResetPasswordResponse, type AdminSignupRequest, type AdminSignupResponse, type AdminSignupSocialRequest, type AdminSignupSocialResponse, type AuditHistoryResponse, type AuthAuditEvent, type AuthAuditEventStatus, AuthAuditEventType, AuthChallenge, type AuthChallengeEvent, type AuthErrorEvent, type AuthEvent, type AuthEventListener, type AuthEventType, type AuthLoginEvent, type AuthLogoutEvent, type AuthRefreshEvent, type AuthResponse, type AuthResponseContext, type AuthSessionExpiredEvent, type AuthSignupEvent, type AuthSuccessEvent, type AuthUser, type AuthUserSummary, type BackupCodesResponse, type BaseChallengeResponse, BrowserStorage, type ChallengeResponse, ChallengeRouter, type ChangePasswordRequest, type ConfirmForgotPasswordRequest, type ConfirmForgotPasswordResponse, type DateFilter, type DeleteUserResponse, type DisableUserResponse, type EnableUserResponse, EventEmitter, FetchAdapter, type ForceChangePasswordResponse, type ForgotPasswordRequest, type ForgotPasswordResponse, type GetChallengeDataRequest, type GetChallengeDataResponse, type GetMFADevicesResponse, type GetSetupDataRequest, type GetSetupDataResponse, type GetUserSessionsResponse, type GetUsersRequest, type GetUsersResponse, type HttpAdapter, type HttpRequest, type HttpResponse, InMemoryStorage, type LinkedAccountsResponse, type LoginRequest, type LogoutAllRequest, type LogoutRequest, type MFAChallengeMethod, type MFACodeResponse, type MFADevice, type MFADeviceMethod, type MFAMethod, type MFAPasskeyResponse, type MFASetupData, type MFASetupResponse, type MFAStatus, type MfaRoutesConfig, type NAuthAdminEndpoints, NAuthClient, type NAuthClientConfig, NAuthClientError, type NAuthEndpoints, type NAuthError, NAuthErrorCode, type NAuthRedirectsConfig, type NAuthStorageAdapter, type OAuthCallbackEvent, type OAuthCompletedEvent, type OAuthErrorEvent, type OAuthStartedEvent, type RecaptchaConfig, type RecaptchaVersion, type RemoveMFADeviceResponse, type ResendCodeRequest, type ResetPasswordWithCodeRequest, type ResetPasswordWithCodeResponse, type ResolvedNAuthClientConfig, type SignupRequest, type SocialLoginOptions, type SocialProvider, type SocialVerifyRequest, type TokenDeliveryMode, type TokenResponse, type UpdateProfileRequest, type UserSessionInfo, type VerifyEmailResponse, type VerifyPhoneCodeResponse, type VerifyPhoneCollectResponse, defaultAdminEndpoints, defaultEndpoints, getChallengeInstructions, getMFAMethod, getMaskedDestination, isOTPChallenge, requiresPhoneCollection, resolveConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -44,6 +44,12 @@ interface RemoveMFADeviceResponse {
|
|
|
44
44
|
removedMethod: MFADeviceMethod;
|
|
45
45
|
mfaDisabled: boolean;
|
|
46
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Response from getting user MFA devices.
|
|
49
|
+
*/
|
|
50
|
+
interface GetMFADevicesResponse {
|
|
51
|
+
devices: MFADevice[];
|
|
52
|
+
}
|
|
47
53
|
/**
|
|
48
54
|
* MFA setup data returned by providers.
|
|
49
55
|
*/
|
|
@@ -726,6 +732,8 @@ interface NAuthAdminEndpoints {
|
|
|
726
732
|
logoutAll: string;
|
|
727
733
|
/** GET /users/:sub/mfa/status - Get MFA status */
|
|
728
734
|
getMfaStatus: string;
|
|
735
|
+
/** GET /users/:sub/mfa/devices - Get MFA devices */
|
|
736
|
+
getMfaDevices: string;
|
|
729
737
|
/** DELETE /mfa/devices/:deviceId - Remove a single MFA device by id */
|
|
730
738
|
removeMfaDeviceById: string;
|
|
731
739
|
/** POST /users/:sub/mfa/devices/:deviceId/preferred - Set preferred MFA device */
|
|
@@ -2524,21 +2532,22 @@ declare class AdminOperations {
|
|
|
2524
2532
|
*/
|
|
2525
2533
|
getMfaStatus(sub: string): Promise<MFAStatus>;
|
|
2526
2534
|
/**
|
|
2527
|
-
*
|
|
2535
|
+
* Get MFA devices for a user
|
|
2528
2536
|
*
|
|
2529
|
-
*
|
|
2530
|
-
* Remove MFA devices for a user
|
|
2537
|
+
* Returns all active MFA devices for a user including device id, name, type, and isPreferred status.
|
|
2531
2538
|
*
|
|
2532
2539
|
* @param sub - User UUID
|
|
2533
|
-
* @
|
|
2534
|
-
* @returns Success message
|
|
2540
|
+
* @returns Response containing array of MFA devices
|
|
2535
2541
|
* @throws {NAuthClientError} If operation fails
|
|
2536
2542
|
*
|
|
2537
2543
|
* @example
|
|
2538
2544
|
* ```typescript
|
|
2539
|
-
* await client.admin.
|
|
2545
|
+
* const result = await client.admin.getMfaDevices('user-uuid');
|
|
2546
|
+
* console.log('Devices:', result.devices);
|
|
2547
|
+
* // [{ id: 1, name: 'My Authenticator', type: 'totp', isPreferred: true, ... }]
|
|
2540
2548
|
* ```
|
|
2541
2549
|
*/
|
|
2550
|
+
getMfaDevices(sub: string): Promise<GetMFADevicesResponse>;
|
|
2542
2551
|
/**
|
|
2543
2552
|
* Remove a single MFA device by device ID (admin).
|
|
2544
2553
|
*
|
|
@@ -2970,14 +2979,96 @@ declare class NAuthClient {
|
|
|
2970
2979
|
getMfaStatus(): Promise<MFAStatus>;
|
|
2971
2980
|
/**
|
|
2972
2981
|
* Get MFA devices.
|
|
2982
|
+
*
|
|
2983
|
+
* @returns Promise of MFA devices response
|
|
2984
|
+
*
|
|
2985
|
+
* @example
|
|
2986
|
+
* ```typescript
|
|
2987
|
+
* const result = await client.getMfaDevices();
|
|
2988
|
+
* console.log('Devices:', result.devices);
|
|
2989
|
+
* ```
|
|
2973
2990
|
*/
|
|
2974
|
-
getMfaDevices(): Promise<
|
|
2991
|
+
getMfaDevices(): Promise<GetMFADevicesResponse>;
|
|
2975
2992
|
/**
|
|
2976
2993
|
* Setup MFA device (authenticated user).
|
|
2994
|
+
*
|
|
2995
|
+
* Returns method-specific setup information:
|
|
2996
|
+
* - TOTP: { secret, qrCode, manualEntryKey }
|
|
2997
|
+
* - SMS: { maskedPhone } or { deviceId, autoCompleted: true }
|
|
2998
|
+
* - Email: { maskedEmail } or { deviceId, autoCompleted: true }
|
|
2999
|
+
* - Passkey: WebAuthn registration options
|
|
3000
|
+
*
|
|
3001
|
+
* @param method - MFA method to set up
|
|
3002
|
+
* @returns Promise of setup data response
|
|
3003
|
+
*
|
|
3004
|
+
* @example
|
|
3005
|
+
* ```typescript
|
|
3006
|
+
* const result = await client.setupMfaDevice('totp');
|
|
3007
|
+
* console.log('QR Code:', result.setupData.qrCode);
|
|
3008
|
+
* ```
|
|
2977
3009
|
*/
|
|
2978
|
-
setupMfaDevice(method: string): Promise<
|
|
3010
|
+
setupMfaDevice(method: string): Promise<GetSetupDataResponse>;
|
|
2979
3011
|
/**
|
|
2980
3012
|
* Verify MFA setup (authenticated user).
|
|
3013
|
+
*
|
|
3014
|
+
* Completes MFA device setup by verifying the setup data. The structure of `setupData` varies by method:
|
|
3015
|
+
*
|
|
3016
|
+
* **TOTP:**
|
|
3017
|
+
* - Requires both `secret` (from `getSetupData()` response) and `code` (from authenticator app)
|
|
3018
|
+
* - Example: `{ secret: 'JBSWY3DPEHPK3PXP', code: '123456' }`
|
|
3019
|
+
*
|
|
3020
|
+
* **SMS:**
|
|
3021
|
+
* - Requires `phoneNumber` and `code` (verification code sent to phone)
|
|
3022
|
+
* - Example: `{ phoneNumber: '+1234567890', code: '123456' }`
|
|
3023
|
+
*
|
|
3024
|
+
* **Email:**
|
|
3025
|
+
* - Requires `code` (verification code sent to email)
|
|
3026
|
+
* - Example: `{ code: '123456' }`
|
|
3027
|
+
*
|
|
3028
|
+
* **Passkey:**
|
|
3029
|
+
* - Requires `credential` (WebAuthn credential from registration) and `expectedChallenge`
|
|
3030
|
+
* - Example: `{ credential: {...}, expectedChallenge: '...' }`
|
|
3031
|
+
*
|
|
3032
|
+
* @param method - MFA method ('totp', 'sms', 'email', 'passkey')
|
|
3033
|
+
* @param setupData - Method-specific setup verification data
|
|
3034
|
+
* @param deviceName - Optional device name (can also be included in setupData for some methods)
|
|
3035
|
+
* @returns Promise with device ID of the created MFA device
|
|
3036
|
+
*
|
|
3037
|
+
* @example TOTP Setup
|
|
3038
|
+
* ```typescript
|
|
3039
|
+
* // Step 1: Get setup data
|
|
3040
|
+
* const setupData = await client.setupMfaDevice('totp');
|
|
3041
|
+
* // Returns: { setupData: { secret: 'JBSWY3DPEHPK3PXP', qrCode: '...', ... } }
|
|
3042
|
+
*
|
|
3043
|
+
* // Step 2: User scans QR code and enters code from authenticator app
|
|
3044
|
+
* const code = '123456'; // From authenticator app
|
|
3045
|
+
*
|
|
3046
|
+
* // Step 3: Verify setup (requires both secret and code)
|
|
3047
|
+
* const result = await client.verifyMfaSetup('totp', {
|
|
3048
|
+
* secret: setupData.setupData.secret,
|
|
3049
|
+
* code: code,
|
|
3050
|
+
* }, 'Google Authenticator');
|
|
3051
|
+
* // Returns: { deviceId: 123 }
|
|
3052
|
+
* ```
|
|
3053
|
+
*
|
|
3054
|
+
* @example SMS Setup
|
|
3055
|
+
* ```typescript
|
|
3056
|
+
* const result = await client.verifyMfaSetup('sms', {
|
|
3057
|
+
* phoneNumber: '+1234567890', // Phone number receiving the code
|
|
3058
|
+
* code: '123456', // Code sent to phone
|
|
3059
|
+
* }, 'My iPhone');
|
|
3060
|
+
* ```
|
|
3061
|
+
*
|
|
3062
|
+
* @example Passkey Setup
|
|
3063
|
+
* ```typescript
|
|
3064
|
+
* const credential = await navigator.credentials.create({
|
|
3065
|
+
* publicKey: setupData.setupData.options
|
|
3066
|
+
* });
|
|
3067
|
+
* const result = await client.verifyMfaSetup('passkey', {
|
|
3068
|
+
* credential: credential,
|
|
3069
|
+
* expectedChallenge: setupData.setupData.challenge,
|
|
3070
|
+
* }, 'MacBook Pro');
|
|
3071
|
+
* ```
|
|
2981
3072
|
*/
|
|
2982
3073
|
verifyMfaSetup(method: string, setupData: Record<string, unknown>, deviceName?: string): Promise<{
|
|
2983
3074
|
deviceId: number;
|
|
@@ -2985,7 +3076,7 @@ declare class NAuthClient {
|
|
|
2985
3076
|
/**
|
|
2986
3077
|
* Remove ALL MFA devices for a specific method type.
|
|
2987
3078
|
*
|
|
2988
|
-
*
|
|
3079
|
+
* WARNING: This removes ALL devices of the specified method.
|
|
2989
3080
|
* For example, if you have 3 TOTP devices, this will remove all 3.
|
|
2990
3081
|
*
|
|
2991
3082
|
* **Prefer `removeMfaDeviceById()`** to remove individual devices.
|
|
@@ -3461,4 +3552,4 @@ declare class FetchAdapter implements HttpAdapter {
|
|
|
3461
3552
|
request<T>(config: HttpRequest): Promise<HttpResponse<T>>;
|
|
3462
3553
|
}
|
|
3463
3554
|
|
|
3464
|
-
export { type AdminAuditHistoryRequest, AdminOperations, type AdminResetPasswordRequest, type AdminResetPasswordResponse, type AdminSignupRequest, type AdminSignupResponse, type AdminSignupSocialRequest, type AdminSignupSocialResponse, type AuditHistoryResponse, type AuthAuditEvent, type AuthAuditEventStatus, AuthAuditEventType, AuthChallenge, type AuthChallengeEvent, type AuthErrorEvent, type AuthEvent, type AuthEventListener, type AuthEventType, type AuthLoginEvent, type AuthLogoutEvent, type AuthRefreshEvent, type AuthResponse, type AuthResponseContext, type AuthSessionExpiredEvent, type AuthSignupEvent, type AuthSuccessEvent, type AuthUser, type AuthUserSummary, type BackupCodesResponse, type BaseChallengeResponse, BrowserStorage, type ChallengeResponse, ChallengeRouter, type ChangePasswordRequest, type ConfirmForgotPasswordRequest, type ConfirmForgotPasswordResponse, type DateFilter, type DeleteUserResponse, type DisableUserResponse, type EnableUserResponse, EventEmitter, FetchAdapter, type ForceChangePasswordResponse, type ForgotPasswordRequest, type ForgotPasswordResponse, type GetChallengeDataRequest, type GetChallengeDataResponse, type GetSetupDataRequest, type GetSetupDataResponse, type GetUserSessionsResponse, type GetUsersRequest, type GetUsersResponse, type HttpAdapter, type HttpRequest, type HttpResponse, InMemoryStorage, type LinkedAccountsResponse, type LoginRequest, type LogoutAllRequest, type LogoutRequest, type MFAChallengeMethod, type MFACodeResponse, type MFADevice, type MFADeviceMethod, type MFAMethod, type MFAPasskeyResponse, type MFASetupData, type MFASetupResponse, type MFAStatus, type MfaRoutesConfig, type NAuthAdminEndpoints, NAuthClient, type NAuthClientConfig, NAuthClientError, type NAuthEndpoints, type NAuthError, NAuthErrorCode, type NAuthRedirectsConfig, type NAuthStorageAdapter, type OAuthCallbackEvent, type OAuthCompletedEvent, type OAuthErrorEvent, type OAuthStartedEvent, type RecaptchaConfig, type RecaptchaVersion, type RemoveMFADeviceResponse, type ResendCodeRequest, type ResetPasswordWithCodeRequest, type ResetPasswordWithCodeResponse, type ResolvedNAuthClientConfig, type SignupRequest, type SocialLoginOptions, type SocialProvider, type SocialVerifyRequest, type TokenDeliveryMode, type TokenResponse, type UpdateProfileRequest, type UserSessionInfo, type VerifyEmailResponse, type VerifyPhoneCodeResponse, type VerifyPhoneCollectResponse, defaultAdminEndpoints, defaultEndpoints, getChallengeInstructions, getMFAMethod, getMaskedDestination, isOTPChallenge, requiresPhoneCollection, resolveConfig };
|
|
3555
|
+
export { type AdminAuditHistoryRequest, AdminOperations, type AdminResetPasswordRequest, type AdminResetPasswordResponse, type AdminSignupRequest, type AdminSignupResponse, type AdminSignupSocialRequest, type AdminSignupSocialResponse, type AuditHistoryResponse, type AuthAuditEvent, type AuthAuditEventStatus, AuthAuditEventType, AuthChallenge, type AuthChallengeEvent, type AuthErrorEvent, type AuthEvent, type AuthEventListener, type AuthEventType, type AuthLoginEvent, type AuthLogoutEvent, type AuthRefreshEvent, type AuthResponse, type AuthResponseContext, type AuthSessionExpiredEvent, type AuthSignupEvent, type AuthSuccessEvent, type AuthUser, type AuthUserSummary, type BackupCodesResponse, type BaseChallengeResponse, BrowserStorage, type ChallengeResponse, ChallengeRouter, type ChangePasswordRequest, type ConfirmForgotPasswordRequest, type ConfirmForgotPasswordResponse, type DateFilter, type DeleteUserResponse, type DisableUserResponse, type EnableUserResponse, EventEmitter, FetchAdapter, type ForceChangePasswordResponse, type ForgotPasswordRequest, type ForgotPasswordResponse, type GetChallengeDataRequest, type GetChallengeDataResponse, type GetMFADevicesResponse, type GetSetupDataRequest, type GetSetupDataResponse, type GetUserSessionsResponse, type GetUsersRequest, type GetUsersResponse, type HttpAdapter, type HttpRequest, type HttpResponse, InMemoryStorage, type LinkedAccountsResponse, type LoginRequest, type LogoutAllRequest, type LogoutRequest, type MFAChallengeMethod, type MFACodeResponse, type MFADevice, type MFADeviceMethod, type MFAMethod, type MFAPasskeyResponse, type MFASetupData, type MFASetupResponse, type MFAStatus, type MfaRoutesConfig, type NAuthAdminEndpoints, NAuthClient, type NAuthClientConfig, NAuthClientError, type NAuthEndpoints, type NAuthError, NAuthErrorCode, type NAuthRedirectsConfig, type NAuthStorageAdapter, type OAuthCallbackEvent, type OAuthCompletedEvent, type OAuthErrorEvent, type OAuthStartedEvent, type RecaptchaConfig, type RecaptchaVersion, type RemoveMFADeviceResponse, type ResendCodeRequest, type ResetPasswordWithCodeRequest, type ResetPasswordWithCodeResponse, type ResolvedNAuthClientConfig, type SignupRequest, type SocialLoginOptions, type SocialProvider, type SocialVerifyRequest, type TokenDeliveryMode, type TokenResponse, type UpdateProfileRequest, type UserSessionInfo, type VerifyEmailResponse, type VerifyPhoneCodeResponse, type VerifyPhoneCollectResponse, defaultAdminEndpoints, defaultEndpoints, getChallengeInstructions, getMFAMethod, getMaskedDestination, isOTPChallenge, requiresPhoneCollection, resolveConfig };
|
package/dist/index.mjs
CHANGED
|
@@ -149,6 +149,7 @@ var defaultAdminEndpoints = {
|
|
|
149
149
|
getUserSessions: "/users/:sub/sessions",
|
|
150
150
|
logoutAll: "/users/:sub/logout-all",
|
|
151
151
|
getMfaStatus: "/users/:sub/mfa/status",
|
|
152
|
+
getMfaDevices: "/users/:sub/mfa/devices",
|
|
152
153
|
removeMfaDeviceById: "/mfa/devices/:deviceId",
|
|
153
154
|
setPreferredMfaDevice: "/users/:sub/mfa/devices/:deviceId/preferred",
|
|
154
155
|
setMfaExemption: "/mfa/exemption",
|
|
@@ -1109,21 +1110,25 @@ var AdminOperations = class {
|
|
|
1109
1110
|
return this.get(path);
|
|
1110
1111
|
}
|
|
1111
1112
|
/**
|
|
1112
|
-
*
|
|
1113
|
+
* Get MFA devices for a user
|
|
1113
1114
|
*
|
|
1114
|
-
*
|
|
1115
|
-
* Remove MFA devices for a user
|
|
1115
|
+
* Returns all active MFA devices for a user including device id, name, type, and isPreferred status.
|
|
1116
1116
|
*
|
|
1117
1117
|
* @param sub - User UUID
|
|
1118
|
-
* @
|
|
1119
|
-
* @returns Success message
|
|
1118
|
+
* @returns Response containing array of MFA devices
|
|
1120
1119
|
* @throws {NAuthClientError} If operation fails
|
|
1121
1120
|
*
|
|
1122
1121
|
* @example
|
|
1123
1122
|
* ```typescript
|
|
1124
|
-
* await client.admin.
|
|
1123
|
+
* const result = await client.admin.getMfaDevices('user-uuid');
|
|
1124
|
+
* console.log('Devices:', result.devices);
|
|
1125
|
+
* // [{ id: 1, name: 'My Authenticator', type: 'totp', isPreferred: true, ... }]
|
|
1125
1126
|
* ```
|
|
1126
1127
|
*/
|
|
1128
|
+
async getMfaDevices(sub) {
|
|
1129
|
+
const path = this.buildAdminUrl(this.adminEndpoints.getMfaDevices, { sub });
|
|
1130
|
+
return this.get(path);
|
|
1131
|
+
}
|
|
1127
1132
|
/**
|
|
1128
1133
|
* Remove a single MFA device by device ID (admin).
|
|
1129
1134
|
*
|
|
@@ -1728,7 +1733,8 @@ var NAuthClient = class {
|
|
|
1728
1733
|
*/
|
|
1729
1734
|
async respondToChallenge(response) {
|
|
1730
1735
|
if (this.selectedDeviceId !== void 0 && response.type === "MFA_REQUIRED" /* MFA_REQUIRED */ && (response.method === "totp" || response.method === "passkey")) {
|
|
1731
|
-
|
|
1736
|
+
const mfaResponse = response;
|
|
1737
|
+
mfaResponse.deviceId = this.selectedDeviceId;
|
|
1732
1738
|
}
|
|
1733
1739
|
if (response.type === "MFA_SETUP_REQUIRED" /* MFA_SETUP_REQUIRED */ && response.method === "totp") {
|
|
1734
1740
|
const setupData = response.setupData;
|
|
@@ -1966,18 +1972,100 @@ var NAuthClient = class {
|
|
|
1966
1972
|
}
|
|
1967
1973
|
/**
|
|
1968
1974
|
* Get MFA devices.
|
|
1975
|
+
*
|
|
1976
|
+
* @returns Promise of MFA devices response
|
|
1977
|
+
*
|
|
1978
|
+
* @example
|
|
1979
|
+
* ```typescript
|
|
1980
|
+
* const result = await client.getMfaDevices();
|
|
1981
|
+
* console.log('Devices:', result.devices);
|
|
1982
|
+
* ```
|
|
1969
1983
|
*/
|
|
1970
1984
|
async getMfaDevices() {
|
|
1971
1985
|
return this.get(this.config.endpoints.mfaDevices, true);
|
|
1972
1986
|
}
|
|
1973
1987
|
/**
|
|
1974
1988
|
* Setup MFA device (authenticated user).
|
|
1989
|
+
*
|
|
1990
|
+
* Returns method-specific setup information:
|
|
1991
|
+
* - TOTP: { secret, qrCode, manualEntryKey }
|
|
1992
|
+
* - SMS: { maskedPhone } or { deviceId, autoCompleted: true }
|
|
1993
|
+
* - Email: { maskedEmail } or { deviceId, autoCompleted: true }
|
|
1994
|
+
* - Passkey: WebAuthn registration options
|
|
1995
|
+
*
|
|
1996
|
+
* @param method - MFA method to set up
|
|
1997
|
+
* @returns Promise of setup data response
|
|
1998
|
+
*
|
|
1999
|
+
* @example
|
|
2000
|
+
* ```typescript
|
|
2001
|
+
* const result = await client.setupMfaDevice('totp');
|
|
2002
|
+
* console.log('QR Code:', result.setupData.qrCode);
|
|
2003
|
+
* ```
|
|
1975
2004
|
*/
|
|
1976
2005
|
async setupMfaDevice(method) {
|
|
1977
2006
|
return this.post(this.config.endpoints.mfaSetupData, { methodName: method }, true);
|
|
1978
2007
|
}
|
|
1979
2008
|
/**
|
|
1980
2009
|
* Verify MFA setup (authenticated user).
|
|
2010
|
+
*
|
|
2011
|
+
* Completes MFA device setup by verifying the setup data. The structure of `setupData` varies by method:
|
|
2012
|
+
*
|
|
2013
|
+
* **TOTP:**
|
|
2014
|
+
* - Requires both `secret` (from `getSetupData()` response) and `code` (from authenticator app)
|
|
2015
|
+
* - Example: `{ secret: 'JBSWY3DPEHPK3PXP', code: '123456' }`
|
|
2016
|
+
*
|
|
2017
|
+
* **SMS:**
|
|
2018
|
+
* - Requires `phoneNumber` and `code` (verification code sent to phone)
|
|
2019
|
+
* - Example: `{ phoneNumber: '+1234567890', code: '123456' }`
|
|
2020
|
+
*
|
|
2021
|
+
* **Email:**
|
|
2022
|
+
* - Requires `code` (verification code sent to email)
|
|
2023
|
+
* - Example: `{ code: '123456' }`
|
|
2024
|
+
*
|
|
2025
|
+
* **Passkey:**
|
|
2026
|
+
* - Requires `credential` (WebAuthn credential from registration) and `expectedChallenge`
|
|
2027
|
+
* - Example: `{ credential: {...}, expectedChallenge: '...' }`
|
|
2028
|
+
*
|
|
2029
|
+
* @param method - MFA method ('totp', 'sms', 'email', 'passkey')
|
|
2030
|
+
* @param setupData - Method-specific setup verification data
|
|
2031
|
+
* @param deviceName - Optional device name (can also be included in setupData for some methods)
|
|
2032
|
+
* @returns Promise with device ID of the created MFA device
|
|
2033
|
+
*
|
|
2034
|
+
* @example TOTP Setup
|
|
2035
|
+
* ```typescript
|
|
2036
|
+
* // Step 1: Get setup data
|
|
2037
|
+
* const setupData = await client.setupMfaDevice('totp');
|
|
2038
|
+
* // Returns: { setupData: { secret: 'JBSWY3DPEHPK3PXP', qrCode: '...', ... } }
|
|
2039
|
+
*
|
|
2040
|
+
* // Step 2: User scans QR code and enters code from authenticator app
|
|
2041
|
+
* const code = '123456'; // From authenticator app
|
|
2042
|
+
*
|
|
2043
|
+
* // Step 3: Verify setup (requires both secret and code)
|
|
2044
|
+
* const result = await client.verifyMfaSetup('totp', {
|
|
2045
|
+
* secret: setupData.setupData.secret,
|
|
2046
|
+
* code: code,
|
|
2047
|
+
* }, 'Google Authenticator');
|
|
2048
|
+
* // Returns: { deviceId: 123 }
|
|
2049
|
+
* ```
|
|
2050
|
+
*
|
|
2051
|
+
* @example SMS Setup
|
|
2052
|
+
* ```typescript
|
|
2053
|
+
* const result = await client.verifyMfaSetup('sms', {
|
|
2054
|
+
* phoneNumber: '+1234567890', // Phone number receiving the code
|
|
2055
|
+
* code: '123456', // Code sent to phone
|
|
2056
|
+
* }, 'My iPhone');
|
|
2057
|
+
* ```
|
|
2058
|
+
*
|
|
2059
|
+
* @example Passkey Setup
|
|
2060
|
+
* ```typescript
|
|
2061
|
+
* const credential = await navigator.credentials.create({
|
|
2062
|
+
* publicKey: setupData.setupData.options
|
|
2063
|
+
* });
|
|
2064
|
+
* const result = await client.verifyMfaSetup('passkey', {
|
|
2065
|
+
* credential: credential,
|
|
2066
|
+
* expectedChallenge: setupData.setupData.challenge,
|
|
2067
|
+
* }, 'MacBook Pro');
|
|
2068
|
+
* ```
|
|
1981
2069
|
*/
|
|
1982
2070
|
async verifyMfaSetup(method, setupData, deviceName) {
|
|
1983
2071
|
return this.post(
|
|
@@ -1991,7 +2079,7 @@ var NAuthClient = class {
|
|
|
1991
2079
|
/**
|
|
1992
2080
|
* Remove ALL MFA devices for a specific method type.
|
|
1993
2081
|
*
|
|
1994
|
-
*
|
|
2082
|
+
* WARNING: This removes ALL devices of the specified method.
|
|
1995
2083
|
* For example, if you have 3 TOTP devices, this will remove all 3.
|
|
1996
2084
|
*
|
|
1997
2085
|
* **Prefer `removeMfaDeviceById()`** to remove individual devices.
|