@nauth-toolkit/core 0.1.0 → 0.1.5
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/LICENSE +90 -0
- package/README.md +9 -0
- package/package.json +8 -3
- package/jest.config.js +0 -15
- package/jest.setup.ts +0 -6
- package/src/adapters/database-columns.ts +0 -165
- package/src/adapters/express.adapter.ts +0 -385
- package/src/adapters/fastify.adapter.ts +0 -416
- package/src/adapters/index.ts +0 -16
- package/src/adapters/storage.factory.ts +0 -143
- package/src/bootstrap.ts +0 -374
- package/src/dto/auth-challenge.dto.ts +0 -231
- package/src/dto/auth-response.dto.ts +0 -253
- package/src/dto/challenge-response.dto.ts +0 -234
- package/src/dto/change-password-request.dto.ts +0 -50
- package/src/dto/change-password-response.dto.ts +0 -29
- package/src/dto/change-password.dto.ts +0 -57
- package/src/dto/error-response.dto.ts +0 -136
- package/src/dto/get-available-methods.dto.ts +0 -55
- package/src/dto/get-challenge-data-response.dto.ts +0 -28
- package/src/dto/get-challenge-data.dto.ts +0 -69
- package/src/dto/get-client-info.dto.ts +0 -104
- package/src/dto/get-device-token-response.dto.ts +0 -25
- package/src/dto/get-events-by-type.dto.ts +0 -76
- package/src/dto/get-ip-address-response.dto.ts +0 -24
- package/src/dto/get-mfa-status.dto.ts +0 -94
- package/src/dto/get-risk-assessment-history.dto.ts +0 -39
- package/src/dto/get-session-id-response.dto.ts +0 -25
- package/src/dto/get-setup-data-response.dto.ts +0 -31
- package/src/dto/get-setup-data.dto.ts +0 -75
- package/src/dto/get-suspicious-activity.dto.ts +0 -42
- package/src/dto/get-user-agent-response.dto.ts +0 -23
- package/src/dto/get-user-auth-history.dto.ts +0 -95
- package/src/dto/get-user-by-email.dto.ts +0 -61
- package/src/dto/get-user-by-id.dto.ts +0 -46
- package/src/dto/get-user-devices.dto.ts +0 -53
- package/src/dto/get-user-response.dto.ts +0 -17
- package/src/dto/has-provider.dto.ts +0 -56
- package/src/dto/index.ts +0 -57
- package/src/dto/is-trusted-device-response.dto.ts +0 -34
- package/src/dto/list-providers-response.dto.ts +0 -23
- package/src/dto/login.dto.ts +0 -95
- package/src/dto/logout-all-response.dto.ts +0 -24
- package/src/dto/logout-all.dto.ts +0 -65
- package/src/dto/logout-response.dto.ts +0 -25
- package/src/dto/logout.dto.ts +0 -64
- package/src/dto/refresh-token.dto.ts +0 -36
- package/src/dto/remove-devices.dto.ts +0 -85
- package/src/dto/resend-code-response.dto.ts +0 -32
- package/src/dto/resend-code.dto.ts +0 -51
- package/src/dto/reset-password.dto.ts +0 -115
- package/src/dto/respond-challenge.dto.ts +0 -272
- package/src/dto/set-mfa-exemption.dto.ts +0 -112
- package/src/dto/set-must-change-password-response.dto.ts +0 -27
- package/src/dto/set-must-change-password.dto.ts +0 -46
- package/src/dto/set-preferred-method.dto.ts +0 -80
- package/src/dto/setup-mfa.dto.ts +0 -98
- package/src/dto/signup.dto.ts +0 -174
- package/src/dto/social-auth.dto.ts +0 -422
- package/src/dto/trust-device-response.dto.ts +0 -30
- package/src/dto/trust-device.dto.ts +0 -9
- package/src/dto/update-user-attributes-request.dto.ts +0 -51
- package/src/dto/user-response.dto.ts +0 -138
- package/src/dto/user-update.dto.ts +0 -222
- package/src/dto/verify-email.dto.ts +0 -313
- package/src/dto/verify-mfa-code.dto.ts +0 -103
- package/src/dto/verify-phone-by-sub.dto.ts +0 -78
- package/src/dto/verify-phone.dto.ts +0 -245
- package/src/entities/auth-audit.entity.ts +0 -232
- package/src/entities/challenge-session.entity.ts +0 -116
- package/src/entities/index.ts +0 -29
- package/src/entities/login-attempt.entity.ts +0 -64
- package/src/entities/mfa-device.entity.ts +0 -151
- package/src/entities/rate-limit.entity.ts +0 -44
- package/src/entities/session.entity.ts +0 -180
- package/src/entities/social-account.entity.ts +0 -96
- package/src/entities/storage-lock.entity.ts +0 -39
- package/src/entities/trusted-device.entity.ts +0 -112
- package/src/entities/user.entity.ts +0 -243
- package/src/entities/verification-token.entity.ts +0 -141
- package/src/enums/auth-audit-event-type.enum.ts +0 -360
- package/src/enums/error-codes.enum.ts +0 -420
- package/src/enums/mfa-method.enum.ts +0 -97
- package/src/enums/risk-factor.enum.ts +0 -111
- package/src/exceptions/nauth.exception.ts +0 -231
- package/src/handlers/auth.handler.ts +0 -260
- package/src/handlers/client-info.handler.ts +0 -101
- package/src/handlers/csrf.handler.ts +0 -156
- package/src/handlers/token-delivery.handler.ts +0 -118
- package/src/index.ts +0 -118
- package/src/interfaces/client-info.interface.ts +0 -85
- package/src/interfaces/config.interface.ts +0 -2135
- package/src/interfaces/entities.interface.ts +0 -226
- package/src/interfaces/index.ts +0 -15
- package/src/interfaces/logger.interface.ts +0 -283
- package/src/interfaces/mfa-provider.interface.ts +0 -154
- package/src/interfaces/oauth.interface.ts +0 -148
- package/src/interfaces/provider.interface.ts +0 -47
- package/src/interfaces/social-auth-provider.interface.ts +0 -131
- package/src/interfaces/storage-adapter.interface.ts +0 -82
- package/src/interfaces/template.interface.ts +0 -510
- package/src/interfaces/token-verifier.interface.ts +0 -110
- package/src/internal.ts +0 -178
- package/src/platform/interfaces.ts +0 -299
- package/src/schemas/auth-config.schema.ts +0 -646
- package/src/services/adaptive-mfa-decision.service.spec.ts +0 -1058
- package/src/services/adaptive-mfa-decision.service.ts +0 -457
- package/src/services/auth-audit.service.spec.ts +0 -675
- package/src/services/auth-audit.service.ts +0 -558
- package/src/services/auth-challenge-helper.service.spec.ts +0 -3227
- package/src/services/auth-challenge-helper.service.ts +0 -825
- package/src/services/auth-flow-context-builder.service.ts +0 -520
- package/src/services/auth-flow-rules.ts +0 -202
- package/src/services/auth-flow-state-definitions.ts +0 -190
- package/src/services/auth-flow-state-machine.service.ts +0 -207
- package/src/services/auth-flow-state-machine.types.ts +0 -316
- package/src/services/auth.service.spec.ts +0 -4195
- package/src/services/auth.service.ts +0 -3727
- package/src/services/challenge.service.spec.ts +0 -1363
- package/src/services/challenge.service.ts +0 -696
- package/src/services/client-info.service.spec.ts +0 -572
- package/src/services/client-info.service.ts +0 -374
- package/src/services/csrf.service.ts +0 -54
- package/src/services/email-verification.service.spec.ts +0 -1229
- package/src/services/email-verification.service.ts +0 -578
- package/src/services/geo-location.service.spec.ts +0 -603
- package/src/services/geo-location.service.ts +0 -599
- package/src/services/index.ts +0 -13
- package/src/services/jwt.service.spec.ts +0 -882
- package/src/services/jwt.service.ts +0 -621
- package/src/services/mfa-base.service.spec.ts +0 -246
- package/src/services/mfa-base.service.ts +0 -611
- package/src/services/mfa.service.spec.ts +0 -693
- package/src/services/mfa.service.ts +0 -960
- package/src/services/password.service.spec.ts +0 -166
- package/src/services/password.service.ts +0 -309
- package/src/services/phone-verification.service.spec.ts +0 -1120
- package/src/services/phone-verification.service.ts +0 -751
- package/src/services/risk-detection.service.spec.ts +0 -1292
- package/src/services/risk-detection.service.ts +0 -1012
- package/src/services/risk-scoring.service.spec.ts +0 -204
- package/src/services/risk-scoring.service.ts +0 -131
- package/src/services/session.service.spec.ts +0 -1293
- package/src/services/session.service.ts +0 -803
- package/src/services/social-account.service.spec.ts +0 -725
- package/src/services/social-auth-base.service.spec.ts +0 -418
- package/src/services/social-auth-base.service.ts +0 -581
- package/src/services/social-auth.service.spec.ts +0 -238
- package/src/services/social-auth.service.ts +0 -436
- package/src/services/social-provider-registry.service.spec.ts +0 -238
- package/src/services/social-provider-registry.service.ts +0 -122
- package/src/services/trusted-device.service.spec.ts +0 -505
- package/src/services/trusted-device.service.ts +0 -339
- package/src/storage/account-lockout-storage.service.spec.ts +0 -310
- package/src/storage/account-lockout-storage.service.ts +0 -89
- package/src/storage/index.ts +0 -3
- package/src/storage/memory-storage.adapter.ts +0 -443
- package/src/storage/rate-limit-storage.service.spec.ts +0 -247
- package/src/storage/rate-limit-storage.service.ts +0 -38
- package/src/templates/html-template.engine.spec.ts +0 -161
- package/src/templates/html-template.engine.ts +0 -688
- package/src/templates/index.ts +0 -7
- package/src/utils/common-passwords.spec.ts +0 -230
- package/src/utils/common-passwords.ts +0 -170
- package/src/utils/context-storage.ts +0 -188
- package/src/utils/cookie-names.util.ts +0 -67
- package/src/utils/cookies.util.ts +0 -94
- package/src/utils/index.ts +0 -12
- package/src/utils/ip-extractor.spec.ts +0 -330
- package/src/utils/ip-extractor.ts +0 -220
- package/src/utils/nauth-logger.spec.ts +0 -388
- package/src/utils/nauth-logger.ts +0 -215
- package/src/utils/pii-redactor.spec.ts +0 -130
- package/src/utils/pii-redactor.ts +0 -288
- package/src/utils/setup/get-repositories.ts +0 -140
- package/src/utils/setup/init-services.ts +0 -422
- package/src/utils/setup/init-social.ts +0 -189
- package/src/utils/setup/init-storage.ts +0 -94
- package/src/utils/setup/register-mfa.ts +0 -165
- package/src/utils/setup/run-nauth-migrations.ts +0 -61
- package/src/utils/token-delivery-policy.ts +0 -38
- package/src/validators/template.validator.ts +0 -219
- package/tsconfig.json +0 -37
- package/tsconfig.lint.json +0 -6
package/src/dto/login.dto.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { IsString, MinLength, MaxLength, IsOptional } from 'class-validator';
|
|
2
|
-
import { Transform } from 'class-transformer';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* DTO for user login with security-focused validation
|
|
6
|
-
*
|
|
7
|
-
* Security:
|
|
8
|
-
* - Identifier validated (email, username, or phone)
|
|
9
|
-
* - Password length enforced
|
|
10
|
-
* - Input sanitization applied
|
|
11
|
-
* - DeviceId validated if provided
|
|
12
|
-
*/
|
|
13
|
-
export class LoginDTO {
|
|
14
|
-
/**
|
|
15
|
-
* Login identifier (email, username, or phone)
|
|
16
|
-
*
|
|
17
|
-
* Validation:
|
|
18
|
-
* - At least 1 character
|
|
19
|
-
* - Max 255 characters (prevents attacks)
|
|
20
|
-
*
|
|
21
|
-
* Sanitization:
|
|
22
|
-
* - Trimmed
|
|
23
|
-
* - Lowercased if it looks like email
|
|
24
|
-
*/
|
|
25
|
-
@IsString({ message: 'Identifier must be a string' })
|
|
26
|
-
@MinLength(1, { message: 'Identifier is required' })
|
|
27
|
-
@MaxLength(255, { message: 'Identifier must not exceed 255 characters' })
|
|
28
|
-
@Transform(({ value }) => {
|
|
29
|
-
if (typeof value === 'string') {
|
|
30
|
-
const trimmed = value.trim();
|
|
31
|
-
// If it contains @, treat as email and lowercase
|
|
32
|
-
if (trimmed.includes('@')) {
|
|
33
|
-
return trimmed.toLowerCase();
|
|
34
|
-
}
|
|
35
|
-
return trimmed;
|
|
36
|
-
}
|
|
37
|
-
return value;
|
|
38
|
-
})
|
|
39
|
-
identifier!: string; // email, username, or phone
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* User password
|
|
43
|
-
*
|
|
44
|
-
* Validation:
|
|
45
|
-
* - At least 1 character (lenient for login)
|
|
46
|
-
* - Max 128 characters (prevents DoS)
|
|
47
|
-
*
|
|
48
|
-
* Note: NOT trimmed (passwords can have spaces)
|
|
49
|
-
*/
|
|
50
|
-
@IsString({ message: 'Password must be a string' })
|
|
51
|
-
@MinLength(1, { message: 'Password is required' })
|
|
52
|
-
@MaxLength(128, { message: 'Password must not exceed 128 characters' })
|
|
53
|
-
password!: string;
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Optional device name for session identification
|
|
57
|
-
*
|
|
58
|
-
* Validation:
|
|
59
|
-
* - Max 255 characters (matches DB constraint: varchar(255))
|
|
60
|
-
*
|
|
61
|
-
* Sanitization:
|
|
62
|
-
* - Trimmed
|
|
63
|
-
*/
|
|
64
|
-
@IsOptional()
|
|
65
|
-
@IsString({ message: 'DeviceName must be a string' })
|
|
66
|
-
@MaxLength(255, { message: 'DeviceName must not exceed 255 characters' })
|
|
67
|
-
@Transform(({ value }) => {
|
|
68
|
-
if (typeof value === 'string') {
|
|
69
|
-
return value.trim();
|
|
70
|
-
}
|
|
71
|
-
return value;
|
|
72
|
-
})
|
|
73
|
-
deviceName?: string;
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Optional device type
|
|
77
|
-
*
|
|
78
|
-
* Validation:
|
|
79
|
-
* - Must be one of: mobile, desktop, tablet
|
|
80
|
-
* - Max 50 characters (matches DB constraint: varchar(50))
|
|
81
|
-
*
|
|
82
|
-
* Sanitization:
|
|
83
|
-
* - Trimmed and lowercased
|
|
84
|
-
*/
|
|
85
|
-
@IsOptional()
|
|
86
|
-
@IsString({ message: 'DeviceType must be a string' })
|
|
87
|
-
@MaxLength(50, { message: 'DeviceType must not exceed 50 characters' })
|
|
88
|
-
@Transform(({ value }) => {
|
|
89
|
-
if (typeof value === 'string') {
|
|
90
|
-
return value.trim().toLowerCase();
|
|
91
|
-
}
|
|
92
|
-
return value;
|
|
93
|
-
})
|
|
94
|
-
deviceType?: 'mobile' | 'desktop' | 'tablet';
|
|
95
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Logout All Response DTO
|
|
3
|
-
*
|
|
4
|
-
* Response DTO for logging out from all sessions.
|
|
5
|
-
* No validators needed - this is generated internally by the library.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* const result = await authService.logoutAll({ sub: 'user-uuid' });
|
|
10
|
-
* // Returns: { revokedCount: 5 }
|
|
11
|
-
* ```
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Response DTO for logout all sessions
|
|
16
|
-
*/
|
|
17
|
-
export class LogoutAllResponseDTO {
|
|
18
|
-
/**
|
|
19
|
-
* Number of sessions revoked
|
|
20
|
-
*
|
|
21
|
-
* @example 5
|
|
22
|
-
*/
|
|
23
|
-
revokedCount!: number;
|
|
24
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Logout All DTO
|
|
3
|
-
*
|
|
4
|
-
* Request DTO for logging out a user from all sessions (global logout).
|
|
5
|
-
*
|
|
6
|
-
* Security:
|
|
7
|
-
* - User sub validated (UUID)
|
|
8
|
-
* - Prevents unauthorized logout attempts
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* const result = await authService.logoutAll({
|
|
13
|
-
* sub: 'user-uuid'
|
|
14
|
-
* });
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
import { IsUUID, IsOptional, IsBoolean } from 'class-validator';
|
|
19
|
-
import { Transform } from 'class-transformer';
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Request DTO for logout all sessions
|
|
23
|
-
*/
|
|
24
|
-
export class LogoutAllDTO {
|
|
25
|
-
/**
|
|
26
|
-
* User's unique identifier (UUID v4)
|
|
27
|
-
*
|
|
28
|
-
* Validation:
|
|
29
|
-
* - Must be a valid UUID v4 format
|
|
30
|
-
* - Matches DB constraint: char(36) or uuid
|
|
31
|
-
*
|
|
32
|
-
* Sanitization:
|
|
33
|
-
* - Trimmed
|
|
34
|
-
* - Lowercased for consistency
|
|
35
|
-
*
|
|
36
|
-
* @example "a21b654c-2746-4168-acee-c175083a65cd"
|
|
37
|
-
*/
|
|
38
|
-
@IsUUID('4', { message: 'User sub must be a valid UUID v4 format' })
|
|
39
|
-
@Transform(({ value }) => {
|
|
40
|
-
if (typeof value === 'string') {
|
|
41
|
-
return value.trim().toLowerCase();
|
|
42
|
-
}
|
|
43
|
-
return value;
|
|
44
|
-
})
|
|
45
|
-
sub!: string;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Whether to also forget/revoke all trusted devices
|
|
49
|
-
*
|
|
50
|
-
* If true, all trusted devices for this user will be revoked,
|
|
51
|
-
* requiring MFA on next login from any device.
|
|
52
|
-
*
|
|
53
|
-
* Default: false (devices remain trusted)
|
|
54
|
-
*
|
|
55
|
-
* @example false
|
|
56
|
-
*/
|
|
57
|
-
@IsOptional()
|
|
58
|
-
@IsBoolean()
|
|
59
|
-
@Transform(({ value }) => {
|
|
60
|
-
if (value === 'true' || value === '1') return true;
|
|
61
|
-
if (value === 'false' || value === '0') return false;
|
|
62
|
-
return value;
|
|
63
|
-
})
|
|
64
|
-
forgetDevices?: boolean;
|
|
65
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Logout Response DTO
|
|
3
|
-
*
|
|
4
|
-
* Response DTO for logging out from a specific session.
|
|
5
|
-
* No validators needed - this is generated internally by the library.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* await authService.logout({ forgetMe: false });
|
|
10
|
-
* // Returns: { success: true }
|
|
11
|
-
* ```
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Response DTO for logout
|
|
16
|
-
*/
|
|
17
|
-
export class LogoutResponseDTO {
|
|
18
|
-
/**
|
|
19
|
-
* Success indicator
|
|
20
|
-
* Always true on successful logout
|
|
21
|
-
*
|
|
22
|
-
* @example true
|
|
23
|
-
*/
|
|
24
|
-
success!: boolean;
|
|
25
|
-
}
|
package/src/dto/logout.dto.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Logout DTO
|
|
3
|
-
*
|
|
4
|
-
* Request DTO for logging out a user from the current authenticated session.
|
|
5
|
-
*
|
|
6
|
-
* Security:
|
|
7
|
-
* - Session ID is automatically extracted from JWT token context (via ClientInfoService)
|
|
8
|
-
* - User sub validated (UUID) - optional, for additional verification
|
|
9
|
-
* - Prevents unauthorized logout attempts
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* await authService.logout({
|
|
14
|
-
* forgetMe: false
|
|
15
|
-
* });
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import { IsOptional, IsBoolean, IsUUID } from 'class-validator';
|
|
20
|
-
import { Transform } from 'class-transformer';
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Request DTO for logout
|
|
24
|
-
*/
|
|
25
|
-
export class LogoutDTO {
|
|
26
|
-
/**
|
|
27
|
-
* User's unique identifier (UUID v4) - Optional
|
|
28
|
-
*
|
|
29
|
-
* If provided, validates that the authenticated user matches this sub.
|
|
30
|
-
* Session ID is automatically extracted from JWT token context.
|
|
31
|
-
*
|
|
32
|
-
* Validation:
|
|
33
|
-
* - Must be a valid UUID v4 format if provided
|
|
34
|
-
* - Matches DB constraint: char(36) or uuid
|
|
35
|
-
*
|
|
36
|
-
* Sanitization:
|
|
37
|
-
* - Trimmed
|
|
38
|
-
* - Lowercased for consistency
|
|
39
|
-
*
|
|
40
|
-
* @example "a21b654c-2746-4168-acee-c175083a65cd"
|
|
41
|
-
*/
|
|
42
|
-
@IsOptional()
|
|
43
|
-
@IsUUID('4', { message: 'User sub must be a valid UUID v4 format' })
|
|
44
|
-
@Transform(({ value }) => {
|
|
45
|
-
if (typeof value === 'string') {
|
|
46
|
-
return value.trim().toLowerCase();
|
|
47
|
-
}
|
|
48
|
-
return value;
|
|
49
|
-
})
|
|
50
|
-
sub?: string;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* If true, also removes trusted device
|
|
54
|
-
*
|
|
55
|
-
* Validation:
|
|
56
|
-
* - Must be a boolean if present
|
|
57
|
-
* - Default: false
|
|
58
|
-
*
|
|
59
|
-
* @example false
|
|
60
|
-
*/
|
|
61
|
-
@IsOptional()
|
|
62
|
-
@IsBoolean({ message: 'forgetMe must be a boolean' })
|
|
63
|
-
forgetMe?: boolean;
|
|
64
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { IsString, MinLength, MaxLength } from 'class-validator';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Refresh Token DTO
|
|
5
|
-
*
|
|
6
|
-
* Used for refreshing access tokens with a valid refresh token.
|
|
7
|
-
*
|
|
8
|
-
* Security:
|
|
9
|
-
* - Token length validated (prevents DoS)
|
|
10
|
-
* - JWT tokens can be long, but we validate input length
|
|
11
|
-
* - Token is validated in service layer for format and signature
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* POST /auth/refresh
|
|
16
|
-
* {
|
|
17
|
-
* "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
|
|
18
|
-
* }
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export class RefreshTokenDTO {
|
|
22
|
-
/**
|
|
23
|
-
* JWT refresh token
|
|
24
|
-
*
|
|
25
|
-
* Validation:
|
|
26
|
-
* - Must be a string
|
|
27
|
-
* - Min 10 characters (minimum valid JWT length)
|
|
28
|
-
* - Max 2048 characters (prevents DoS, typical JWT is 200-500 chars)
|
|
29
|
-
*
|
|
30
|
-
* Note: Token format and signature validated in service layer
|
|
31
|
-
*/
|
|
32
|
-
@IsString({ message: 'Refresh token must be a string' })
|
|
33
|
-
@MinLength(10, { message: 'Refresh token is required' })
|
|
34
|
-
@MaxLength(2048, { message: 'Refresh token must not exceed 2048 characters' })
|
|
35
|
-
refreshToken!: string;
|
|
36
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DTO for removing MFA devices
|
|
3
|
-
*
|
|
4
|
-
* Used to remove all MFA devices of a specific method type for a user.
|
|
5
|
-
* Automatically disables MFA if this was the last device.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* const result = await mfaService.removeDevices({
|
|
10
|
-
* userSub: 'user-uuid',
|
|
11
|
-
* methodType: 'totp'
|
|
12
|
-
* });
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import { IsEnum, IsString, IsUUID, MaxLength } from 'class-validator';
|
|
17
|
-
import { Transform } from 'class-transformer';
|
|
18
|
-
import { MFAMethod } from '../enums/mfa-method.enum';
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* DTO for removing MFA devices
|
|
22
|
-
*/
|
|
23
|
-
export class RemoveDevicesDTO {
|
|
24
|
-
/**
|
|
25
|
-
* User's unique identifier (UUID v4)
|
|
26
|
-
*
|
|
27
|
-
* Validation:
|
|
28
|
-
* - Must be a valid UUID v4 format
|
|
29
|
-
* - Matches DB constraint: char(36) or uuid
|
|
30
|
-
*
|
|
31
|
-
* Sanitization:
|
|
32
|
-
* - Trimmed
|
|
33
|
-
* - Lowercased for consistency
|
|
34
|
-
*
|
|
35
|
-
* @example "a21b654c-2746-4168-acee-c175083a65cd"
|
|
36
|
-
*/
|
|
37
|
-
@IsUUID('4', { message: 'User sub must be a valid UUID v4 format' })
|
|
38
|
-
@Transform(({ value }) => {
|
|
39
|
-
if (typeof value === 'string') {
|
|
40
|
-
return value.trim().toLowerCase();
|
|
41
|
-
}
|
|
42
|
-
return value;
|
|
43
|
-
})
|
|
44
|
-
userSub!: string;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* MFA method type to remove
|
|
48
|
-
*
|
|
49
|
-
* Validation:
|
|
50
|
-
* - Must be one of: totp, sms, email, passkey
|
|
51
|
-
* - Max 50 characters
|
|
52
|
-
*
|
|
53
|
-
* Sanitization:
|
|
54
|
-
* - Trimmed and lowercased
|
|
55
|
-
*
|
|
56
|
-
* @example "totp"
|
|
57
|
-
*/
|
|
58
|
-
@IsString({ message: 'Method type must be a string' })
|
|
59
|
-
@IsEnum([MFAMethod.TOTP, MFAMethod.SMS, MFAMethod.EMAIL, MFAMethod.PASSKEY], {
|
|
60
|
-
message: 'Method type must be one of: totp, sms, email, passkey',
|
|
61
|
-
})
|
|
62
|
-
@MaxLength(50, { message: 'Method type must not exceed 50 characters' })
|
|
63
|
-
@Transform(({ value }) => {
|
|
64
|
-
if (typeof value === 'string') {
|
|
65
|
-
return value.trim().toLowerCase();
|
|
66
|
-
}
|
|
67
|
-
return value;
|
|
68
|
-
})
|
|
69
|
-
methodType!: string;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Response DTO for removing devices
|
|
74
|
-
*/
|
|
75
|
-
export class RemoveDevicesResponseDTO {
|
|
76
|
-
/**
|
|
77
|
-
* Number of devices deleted
|
|
78
|
-
*/
|
|
79
|
-
deletedCount!: number;
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Whether MFA was disabled (if this was the last device)
|
|
83
|
-
*/
|
|
84
|
-
mfaDisabled!: boolean;
|
|
85
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Resend Code Response DTO
|
|
3
|
-
*
|
|
4
|
-
* Response DTO for resending verification codes.
|
|
5
|
-
* No validators needed - this is generated internally by the library.
|
|
6
|
-
*
|
|
7
|
-
* Security:
|
|
8
|
-
* - Email/phone masked for privacy
|
|
9
|
-
* - Only shows destination, not full details
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* const result = await authService.resendCode({ session: 'session-uuid' });
|
|
14
|
-
* // Returns: { destination: 'u***r@example.com' }
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Response DTO for resend code
|
|
20
|
-
*/
|
|
21
|
-
export class ResendCodeResponseDTO {
|
|
22
|
-
/**
|
|
23
|
-
* Masked destination where code was sent
|
|
24
|
-
*
|
|
25
|
-
* Format:
|
|
26
|
-
* - Email: "u***r@example.com"
|
|
27
|
-
* - Phone: "+1***5678"
|
|
28
|
-
*
|
|
29
|
-
* @example "u***r@example.com"
|
|
30
|
-
*/
|
|
31
|
-
destination!: string;
|
|
32
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DTO for resending verification code
|
|
3
|
-
*
|
|
4
|
-
* Used to resend email/SMS verification codes during challenges:
|
|
5
|
-
* - Email verification (VERIFY_EMAIL)
|
|
6
|
-
* - Phone verification (VERIFY_PHONE)
|
|
7
|
-
* - MFA verification (MFA_REQUIRED with SMS/Email method)
|
|
8
|
-
*
|
|
9
|
-
* Security:
|
|
10
|
-
* - Session token length limited (prevents DoS)
|
|
11
|
-
* - Rate limiting enforced in service layer
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* const result = await authService.resendCode({
|
|
16
|
-
* session: 'challenge-session-token'
|
|
17
|
-
* });
|
|
18
|
-
* // Returns: { destination: 'u***r@example.com' }
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
import { IsUUID } from 'class-validator';
|
|
23
|
-
import { Transform } from 'class-transformer';
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* DTO for resending verification code
|
|
27
|
-
*/
|
|
28
|
-
export class ResendCodeDTO {
|
|
29
|
-
/**
|
|
30
|
-
* Challenge session token (UUID v4)
|
|
31
|
-
*
|
|
32
|
-
* Validation:
|
|
33
|
-
* - Must be a valid UUID v4 format
|
|
34
|
-
* - Generated using randomUUID() in challenge service
|
|
35
|
-
* - Matches DB constraint: varchar(255) but UUID format enforced
|
|
36
|
-
*
|
|
37
|
-
* Sanitization:
|
|
38
|
-
* - Trimmed
|
|
39
|
-
* - Lowercased for consistency
|
|
40
|
-
*
|
|
41
|
-
* @example "a21b654c-2746-4168-acee-c175083a65cd"
|
|
42
|
-
*/
|
|
43
|
-
@IsUUID('4', { message: 'Session token must be a valid UUID v4 format' })
|
|
44
|
-
@Transform(({ value }) => {
|
|
45
|
-
if (typeof value === 'string') {
|
|
46
|
-
return value.trim().toLowerCase();
|
|
47
|
-
}
|
|
48
|
-
return value;
|
|
49
|
-
})
|
|
50
|
-
session!: string;
|
|
51
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { IsString, MinLength, MaxLength, IsNotEmpty } from 'class-validator';
|
|
2
|
-
import { Transform } from 'class-transformer';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Reset Password Request DTO
|
|
6
|
-
*
|
|
7
|
-
* Used to request a password reset token via email or phone.
|
|
8
|
-
*
|
|
9
|
-
* Security:
|
|
10
|
-
* - Identifier validated (email or phone)
|
|
11
|
-
* - Input sanitization applied
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* POST /auth/reset-password/request
|
|
16
|
-
* {
|
|
17
|
-
* "identifier": "user@example.com"
|
|
18
|
-
* }
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export class ResetPasswordRequestDTO {
|
|
22
|
-
/**
|
|
23
|
-
* User identifier (email or phone)
|
|
24
|
-
*
|
|
25
|
-
* Validation:
|
|
26
|
-
* - Must be a string
|
|
27
|
-
* - Min 1 character
|
|
28
|
-
* - Max 255 characters (matches DB constraint for email)
|
|
29
|
-
*
|
|
30
|
-
* Sanitization:
|
|
31
|
-
* - Trimmed
|
|
32
|
-
* - Lowercased if email format detected
|
|
33
|
-
*/
|
|
34
|
-
@IsString({ message: 'Identifier must be a string' })
|
|
35
|
-
@IsNotEmpty({ message: 'Identifier is required' })
|
|
36
|
-
@MinLength(1, { message: 'Identifier is required' })
|
|
37
|
-
@MaxLength(255, { message: 'Identifier must not exceed 255 characters' })
|
|
38
|
-
@Transform(({ value }) => {
|
|
39
|
-
if (typeof value === 'string') {
|
|
40
|
-
const trimmed = value.trim();
|
|
41
|
-
// If it contains @, treat as email and lowercase
|
|
42
|
-
if (trimmed.includes('@')) {
|
|
43
|
-
return trimmed.toLowerCase();
|
|
44
|
-
}
|
|
45
|
-
return trimmed;
|
|
46
|
-
}
|
|
47
|
-
return value;
|
|
48
|
-
})
|
|
49
|
-
identifier!: string; // email or phone
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Reset Password DTO
|
|
54
|
-
*
|
|
55
|
-
* Used to reset password with a valid reset token.
|
|
56
|
-
*
|
|
57
|
-
* Security:
|
|
58
|
-
* - Token length validated (matches DB constraint: varchar(255))
|
|
59
|
-
* - Password strength enforced (8-128 chars)
|
|
60
|
-
* - Token format validated in service layer
|
|
61
|
-
*
|
|
62
|
-
* @example
|
|
63
|
-
* ```typescript
|
|
64
|
-
* POST /auth/reset-password
|
|
65
|
-
* {
|
|
66
|
-
* "token": "reset-token-from-email",
|
|
67
|
-
* "newPassword": "NewSecurePassword123!"
|
|
68
|
-
* }
|
|
69
|
-
* ```
|
|
70
|
-
*/
|
|
71
|
-
export class ResetPasswordDTO {
|
|
72
|
-
/**
|
|
73
|
-
* Password reset token from email
|
|
74
|
-
*
|
|
75
|
-
* Validation:
|
|
76
|
-
* - Must be a string
|
|
77
|
-
* - Min 1 character (prevents empty strings)
|
|
78
|
-
* - Max 255 characters (matches DB constraint: varchar(255))
|
|
79
|
-
*
|
|
80
|
-
* Sanitization:
|
|
81
|
-
* - Trimmed
|
|
82
|
-
*
|
|
83
|
-
* Note: Token format and validity validated in service layer
|
|
84
|
-
*/
|
|
85
|
-
@IsString({ message: 'Token must be a string' })
|
|
86
|
-
@IsNotEmpty({ message: 'Token is required' })
|
|
87
|
-
@MinLength(1, { message: 'Token is required' })
|
|
88
|
-
@MaxLength(255, { message: 'Token must not exceed 255 characters' })
|
|
89
|
-
@Transform(({ value }) => {
|
|
90
|
-
if (typeof value === 'string') {
|
|
91
|
-
return value.trim();
|
|
92
|
-
}
|
|
93
|
-
return value;
|
|
94
|
-
})
|
|
95
|
-
token!: string;
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* New password
|
|
99
|
-
*
|
|
100
|
-
* Validation:
|
|
101
|
-
* - Must be a string
|
|
102
|
-
* - Min 8 characters (security requirement)
|
|
103
|
-
* - Max 128 characters (prevents DoS via bcrypt)
|
|
104
|
-
*
|
|
105
|
-
* Note: NOT trimmed (passwords can have leading/trailing spaces)
|
|
106
|
-
* Additional checks in service layer:
|
|
107
|
-
* - Password strength (if configured)
|
|
108
|
-
* - Password history (prevent reuse)
|
|
109
|
-
*/
|
|
110
|
-
@IsString({ message: 'New password must be a string' })
|
|
111
|
-
@IsNotEmpty({ message: 'New password is required' })
|
|
112
|
-
@MinLength(8, { message: 'Password must be at least 8 characters' })
|
|
113
|
-
@MaxLength(128, { message: 'Password must not exceed 128 characters' })
|
|
114
|
-
newPassword!: string;
|
|
115
|
-
}
|