@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
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OAuth User Profile Interface
|
|
3
|
-
* Standardized user profile data from OAuth providers
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* ```typescript
|
|
7
|
-
* const profile: OAuthUserProfile = {
|
|
8
|
-
* id: 'google_123',
|
|
9
|
-
* email: 'user@gmail.com',
|
|
10
|
-
* firstName: 'John',
|
|
11
|
-
* lastName: 'Doe',
|
|
12
|
-
* picture: 'https://...',
|
|
13
|
-
* verified: true
|
|
14
|
-
* };
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
export interface OAuthUserProfile {
|
|
18
|
-
/**
|
|
19
|
-
* Provider's unique identifier for the user
|
|
20
|
-
* Examples: Google sub, Apple user ID, Facebook ID
|
|
21
|
-
*/
|
|
22
|
-
id: string;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* User's email address
|
|
26
|
-
* May be null if not provided by provider
|
|
27
|
-
*/
|
|
28
|
-
email?: string | null;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* User's first name
|
|
32
|
-
* May be null if not provided by provider
|
|
33
|
-
*/
|
|
34
|
-
firstName?: string | null;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* User's last name
|
|
38
|
-
* May be null if not provided by provider
|
|
39
|
-
*/
|
|
40
|
-
lastName?: string | null;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* User's profile picture URL
|
|
44
|
-
* May be null if not provided by provider
|
|
45
|
-
*/
|
|
46
|
-
picture?: string | null;
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Whether the email is verified by the provider
|
|
50
|
-
* @default false
|
|
51
|
-
*/
|
|
52
|
-
verified?: boolean;
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Additional provider-specific data
|
|
56
|
-
* Contains raw response from OAuth provider
|
|
57
|
-
*/
|
|
58
|
-
raw?: Record<string, unknown>;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* OAuth Client Interface
|
|
63
|
-
* Defines the contract for OAuth provider clients
|
|
64
|
-
*
|
|
65
|
-
* @example
|
|
66
|
-
* ```typescript
|
|
67
|
-
* class GoogleOAuthClient implements OAuthClient {
|
|
68
|
-
* async getUserProfile(accessToken: string): Promise<OAuthUserProfile> {
|
|
69
|
-
* // Implementation for Google
|
|
70
|
-
* }
|
|
71
|
-
* }
|
|
72
|
-
* ```
|
|
73
|
-
*/
|
|
74
|
-
export interface OAuthClient {
|
|
75
|
-
/**
|
|
76
|
-
* Get user profile from OAuth provider using access token
|
|
77
|
-
*
|
|
78
|
-
* @param accessToken - OAuth access token
|
|
79
|
-
* @returns User profile data
|
|
80
|
-
* @throws {Error} When API call fails or token is invalid
|
|
81
|
-
*
|
|
82
|
-
* @example
|
|
83
|
-
* ```typescript
|
|
84
|
-
* const profile = await oauthClient.getUserProfile(accessToken);
|
|
85
|
-
* console.log(profile.email); // user@example.com
|
|
86
|
-
* ```
|
|
87
|
-
*/
|
|
88
|
-
getUserProfile(accessToken: string): Promise<OAuthUserProfile>;
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Exchange authorization code for access token
|
|
92
|
-
*
|
|
93
|
-
* @param code - Authorization code from OAuth callback
|
|
94
|
-
* @param redirectUri - Redirect URI used in OAuth flow
|
|
95
|
-
* @returns Access token and optional refresh token
|
|
96
|
-
* @throws {Error} When token exchange fails
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* ```typescript
|
|
100
|
-
* const tokens = await oauthClient.exchangeCodeForToken(code, redirectUri);
|
|
101
|
-
* console.log(tokens.accessToken); // access_token_here
|
|
102
|
-
* ```
|
|
103
|
-
*/
|
|
104
|
-
exchangeCodeForToken(
|
|
105
|
-
code: string,
|
|
106
|
-
redirectUri: string,
|
|
107
|
-
): Promise<{
|
|
108
|
-
accessToken: string;
|
|
109
|
-
refreshToken?: string;
|
|
110
|
-
expiresIn?: number;
|
|
111
|
-
}>;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* OAuth Configuration Interface
|
|
116
|
-
* Configuration for OAuth clients
|
|
117
|
-
*
|
|
118
|
-
* @example
|
|
119
|
-
* ```typescript
|
|
120
|
-
* const config: OAuthConfig = {
|
|
121
|
-
* clientId: 'google_client_id',
|
|
122
|
-
* clientSecret: 'google_client_secret',
|
|
123
|
-
* redirectUri: 'https://myapp.com/auth/google/callback'
|
|
124
|
-
* };
|
|
125
|
-
* ```
|
|
126
|
-
*/
|
|
127
|
-
export interface OAuthConfig {
|
|
128
|
-
/**
|
|
129
|
-
* OAuth client ID
|
|
130
|
-
*/
|
|
131
|
-
clientId: string;
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* OAuth client secret
|
|
135
|
-
*/
|
|
136
|
-
clientSecret: string;
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* OAuth redirect URI
|
|
140
|
-
*/
|
|
141
|
-
redirectUri: string;
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* OAuth scopes
|
|
145
|
-
* @default ['openid', 'email', 'profile']
|
|
146
|
-
*/
|
|
147
|
-
scopes?: string[];
|
|
148
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Email provider interface for sending emails
|
|
3
|
-
*/
|
|
4
|
-
export interface EmailProvider {
|
|
5
|
-
/**
|
|
6
|
-
* Send email verification code/link
|
|
7
|
-
* @param to - Recipient email address
|
|
8
|
-
* @param code - Verification code (e.g., "123456")
|
|
9
|
-
* @param link - Optional verification link (only sent if provided by consumer app)
|
|
10
|
-
*/
|
|
11
|
-
sendVerificationEmail(to: string, code: string, link?: string): Promise<void>;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Send password reset email
|
|
15
|
-
*/
|
|
16
|
-
sendPasswordResetEmail(to: string, token: string, link: string): Promise<void>;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Send welcome email
|
|
20
|
-
*/
|
|
21
|
-
sendWelcomeEmail(to: string, name: string): Promise<void>;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Send account lockout notification
|
|
25
|
-
*/
|
|
26
|
-
sendLockoutEmail?(to: string, reason: string, duration: number): Promise<void>;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Send new device login notification
|
|
30
|
-
*/
|
|
31
|
-
sendNewDeviceEmail?(to: string, deviceInfo: any, location?: any): Promise<void>;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* SMS provider interface for sending text messages
|
|
36
|
-
*/
|
|
37
|
-
export interface SMSProvider {
|
|
38
|
-
/**
|
|
39
|
-
* Send OTP code via SMS
|
|
40
|
-
*/
|
|
41
|
-
sendOTP(phone: string, code: string): Promise<void>;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Send verification code
|
|
45
|
-
*/
|
|
46
|
-
sendVerificationCode?(phone: string, code: string): Promise<void>;
|
|
47
|
-
}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { AuthResponseDTO } from '../dto';
|
|
2
|
-
import { OAuthUserProfile } from '../interfaces/oauth.interface';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Social Auth Provider Service Interface
|
|
6
|
-
*
|
|
7
|
-
* Defines the contract for social authentication provider services.
|
|
8
|
-
* Each provider (Google, Apple, Facebook, etc.) must implement this interface
|
|
9
|
-
* to be registered with the core SocialAuthService.
|
|
10
|
-
*
|
|
11
|
-
* This allows for:
|
|
12
|
-
* - Modular provider imports (only install what you need)
|
|
13
|
-
* - Consistent API across all providers
|
|
14
|
-
* - Proper NestJS dependency injection
|
|
15
|
-
* - Easy addition of new providers without modifying core code
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```typescript
|
|
19
|
-
* @Injectable()
|
|
20
|
-
* export class GoogleSocialAuthService implements ISocialAuthProviderService {
|
|
21
|
-
* readonly providerName = 'google';
|
|
22
|
-
*
|
|
23
|
-
* async getAuthUrl(state?: string): Promise<string> {
|
|
24
|
-
* // Generate Google OAuth URL
|
|
25
|
-
* }
|
|
26
|
-
*
|
|
27
|
-
* async handleCallback(code: string, state: string): Promise<AuthResponseDTO> {
|
|
28
|
-
* // Handle Google OAuth callback
|
|
29
|
-
* }
|
|
30
|
-
*
|
|
31
|
-
* async verifyToken(idToken: string, accessToken?: string, profileData?: any): Promise<AuthResponseDTO> {
|
|
32
|
-
* // Verify Google ID token
|
|
33
|
-
* }
|
|
34
|
-
* }
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
export interface ISocialAuthProviderService {
|
|
38
|
-
/**
|
|
39
|
-
* Provider name (e.g., 'google', 'apple', 'facebook')
|
|
40
|
-
* Used as the key in the provider registry
|
|
41
|
-
*/
|
|
42
|
-
readonly providerName: string;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Generate OAuth authorization URL for this provider
|
|
46
|
-
*
|
|
47
|
-
* @param state - Optional state parameter for CSRF protection
|
|
48
|
-
* @returns Authorization URL to redirect user to
|
|
49
|
-
* @throws {BadRequestException} When provider is not properly configured
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```typescript
|
|
53
|
-
* const authUrl = await provider.getAuthUrl('random-state-123');
|
|
54
|
-
* // Redirect user to authUrl
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
|
-
getAuthUrl(state?: string): Promise<string>;
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Handle OAuth callback and authenticate user
|
|
61
|
-
*
|
|
62
|
-
* Exchanges authorization code for access token, fetches user profile,
|
|
63
|
-
* and returns unified authentication response with JWT tokens.
|
|
64
|
-
*
|
|
65
|
-
* @param code - Authorization code from OAuth callback
|
|
66
|
-
* @param state - State parameter from OAuth callback (for CSRF protection)
|
|
67
|
-
* @returns Unified authentication response with tokens and user info
|
|
68
|
-
* @throws {BadRequestException} When callback is invalid
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```typescript
|
|
72
|
-
* const result = await provider.handleCallback(code, state);
|
|
73
|
-
* console.log(result.accessToken); // JWT access token
|
|
74
|
-
* console.log(result.user.email); // User email
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
handleCallback(code: string, state: string): Promise<AuthResponseDTO>;
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Verify social authentication token from native mobile apps
|
|
81
|
-
*
|
|
82
|
-
* Handles authentication tokens from native mobile apps (iOS/Android)
|
|
83
|
-
* that use native SDKs (Google Sign-In SDK, Apple Sign In, etc.)
|
|
84
|
-
*
|
|
85
|
-
* @param idToken - ID token from native SDK
|
|
86
|
-
* @param accessToken - Optional access token from native SDK
|
|
87
|
-
* @param profileData - Optional profile data from native SDK (for name extraction)
|
|
88
|
-
* @returns Unified authentication response with tokens and user info
|
|
89
|
-
* @throws {BadRequestException} When token is invalid
|
|
90
|
-
*
|
|
91
|
-
* @example
|
|
92
|
-
* ```typescript
|
|
93
|
-
* const result = await provider.verifyToken(idToken, accessToken, profileData);
|
|
94
|
-
* return result; // Same format as login/signup
|
|
95
|
-
* ```
|
|
96
|
-
*/
|
|
97
|
-
verifyToken(idToken: string, accessToken?: string, profileData?: any): Promise<AuthResponseDTO>;
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Link social account to existing user
|
|
101
|
-
*
|
|
102
|
-
* Used when an authenticated user wants to link a social account
|
|
103
|
-
* to their existing account.
|
|
104
|
-
*
|
|
105
|
-
* @param userId - User ID (sub)
|
|
106
|
-
* @param code - Authorization code from OAuth callback
|
|
107
|
-
* @param state - State parameter from OAuth callback
|
|
108
|
-
* @returns Success message
|
|
109
|
-
* @throws {NotFoundException} When user is not found
|
|
110
|
-
* @throws {ConflictException} When account is already linked
|
|
111
|
-
*
|
|
112
|
-
* @example
|
|
113
|
-
* ```typescript
|
|
114
|
-
* await provider.linkAccount(userId, code, state);
|
|
115
|
-
* ```
|
|
116
|
-
*/
|
|
117
|
-
linkAccount(userId: string, code: string, state: string): Promise<{ message: string }>;
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Get OAuth user profile from callback
|
|
121
|
-
*
|
|
122
|
-
* Internal method used by handleCallback to extract user profile.
|
|
123
|
-
* Exposed for advanced use cases.
|
|
124
|
-
*
|
|
125
|
-
* @param code - Authorization code from OAuth callback
|
|
126
|
-
* @param state - State parameter from OAuth callback
|
|
127
|
-
* @returns OAuth user profile
|
|
128
|
-
* @private
|
|
129
|
-
*/
|
|
130
|
-
getUserProfileFromCallback(code: string, state: string): Promise<OAuthUserProfile>;
|
|
131
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Storage adapter interface for shared state management
|
|
3
|
-
* Critical for multi-server deployments
|
|
4
|
-
*/
|
|
5
|
-
export interface StorageAdapter {
|
|
6
|
-
/**
|
|
7
|
-
* Initialize the storage adapter
|
|
8
|
-
*/
|
|
9
|
-
initialize(): Promise<void>;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Check if adapter is healthy
|
|
13
|
-
*/
|
|
14
|
-
isHealthy(): Promise<boolean>;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Basic key-value operations
|
|
18
|
-
*/
|
|
19
|
-
get(key: string): Promise<string | null>;
|
|
20
|
-
set(key: string, value: string, ttlSeconds?: number, options?: { nx?: boolean }): Promise<string | null | void>;
|
|
21
|
-
del(key: string): Promise<void>;
|
|
22
|
-
exists(key: string): Promise<boolean>;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Atomic operations
|
|
26
|
-
*/
|
|
27
|
-
incr(key: string, ttlSeconds?: number): Promise<number>;
|
|
28
|
-
decr(key: string): Promise<number>;
|
|
29
|
-
expire(key: string, ttl: number): Promise<void>;
|
|
30
|
-
ttl(key: string): Promise<number>;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Hash operations (for complex data structures)
|
|
34
|
-
*/
|
|
35
|
-
hget(key: string, field: string): Promise<string | null>;
|
|
36
|
-
hset(key: string, field: string, value: string): Promise<void>;
|
|
37
|
-
hgetall(key: string): Promise<Record<string, string>>;
|
|
38
|
-
hdel(key: string, ...fields: string[]): Promise<number>;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* List operations (for token families)
|
|
42
|
-
*/
|
|
43
|
-
lpush(key: string, value: string): Promise<void>;
|
|
44
|
-
lrange(key: string, start: number, stop: number): Promise<string[]>;
|
|
45
|
-
llen(key: string): Promise<number>;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Pattern operations
|
|
49
|
-
*/
|
|
50
|
-
keys(pattern: string): Promise<string[]>;
|
|
51
|
-
scan(cursor: number, pattern: string, count: number): Promise<[number, string[]]>;
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Cleanup and disconnect
|
|
55
|
-
*/
|
|
56
|
-
cleanup(): Promise<void>;
|
|
57
|
-
disconnect(): Promise<void>;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Rate limiting specific operations
|
|
62
|
-
*/
|
|
63
|
-
export interface RateLimitStorage {
|
|
64
|
-
incrementRateLimit(identifier: string, endpoint: string, windowMs: number): Promise<number>;
|
|
65
|
-
getRateLimit(identifier: string, endpoint: string): Promise<number>;
|
|
66
|
-
resetRateLimit(identifier: string, endpoint: string): Promise<void>;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Account lockout specific operations
|
|
71
|
-
*
|
|
72
|
-
* SECURITY: Uses IP addresses instead of user identifiers to prevent
|
|
73
|
-
* attackers from locking out legitimate users by guessing their email/username.
|
|
74
|
-
*/
|
|
75
|
-
export interface AccountLockoutStorage {
|
|
76
|
-
recordFailedAttempt(ipAddress: string): Promise<number>;
|
|
77
|
-
getFailedAttempts(ipAddress: string): Promise<number>;
|
|
78
|
-
isAccountLocked(ipAddress: string): Promise<boolean>;
|
|
79
|
-
blockIpAdresss(ipAddress: string, duration: number, reason: string): Promise<void>;
|
|
80
|
-
unblockIPAdress(ipAddress: string): Promise<void>;
|
|
81
|
-
resetFailedAttempts(ipAddress: string): Promise<void>;
|
|
82
|
-
}
|