@ambushsoftworks/nestjs-auth-graphql 0.6.7 → 0.8.0
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/README.md +205 -2
- package/dist/auth.module.d.ts +12 -2
- package/dist/auth.module.d.ts.map +1 -1
- package/dist/auth.module.js +38 -0
- package/dist/auth.module.js.map +1 -1
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +2 -1
- package/dist/constants.js.map +1 -1
- package/dist/decorators/current-realm.decorator.d.ts +2 -0
- package/dist/decorators/current-realm.decorator.d.ts.map +1 -0
- package/dist/decorators/current-realm.decorator.js +10 -0
- package/dist/decorators/current-realm.decorator.js.map +1 -0
- package/dist/dto/jwt-payload.interface.d.ts +1 -0
- package/dist/dto/jwt-payload.interface.d.ts.map +1 -1
- package/dist/exceptions/invalid-auth-config.exception.d.ts +4 -0
- package/dist/exceptions/invalid-auth-config.exception.d.ts.map +1 -0
- package/dist/exceptions/invalid-auth-config.exception.js +12 -0
- package/dist/exceptions/invalid-auth-config.exception.js.map +1 -0
- package/dist/guards/tenant.guard.d.ts.map +1 -1
- package/dist/guards/tenant.guard.js +9 -1
- package/dist/guards/tenant.guard.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces/auth-logger.interface.d.ts +2 -0
- package/dist/interfaces/auth-logger.interface.d.ts.map +1 -1
- package/dist/interfaces/auth-logger.interface.js +2 -0
- package/dist/interfaces/auth-logger.interface.js.map +1 -1
- package/dist/interfaces/brute-force-repository.interface.d.ts +1 -0
- package/dist/interfaces/brute-force-repository.interface.d.ts.map +1 -1
- package/dist/interfaces/jwt-payload-factory.interface.d.ts +1 -0
- package/dist/interfaces/jwt-payload-factory.interface.d.ts.map +1 -1
- package/dist/interfaces/realm-extractor.interface.d.ts +4 -0
- package/dist/interfaces/realm-extractor.interface.d.ts.map +1 -0
- package/dist/interfaces/realm-extractor.interface.js +3 -0
- package/dist/interfaces/realm-extractor.interface.js.map +1 -0
- package/dist/interfaces/tenant-extractor.interface.d.ts +1 -1
- package/dist/interfaces/tenant-extractor.interface.d.ts.map +1 -1
- package/dist/interfaces/user-repository.interface.d.ts +6 -5
- package/dist/interfaces/user-repository.interface.d.ts.map +1 -1
- package/dist/middleware/realm.middleware.d.ts +9 -0
- package/dist/middleware/realm.middleware.d.ts.map +1 -0
- package/dist/middleware/realm.middleware.js +51 -0
- package/dist/middleware/realm.middleware.js.map +1 -0
- package/dist/repositories/noop-brute-force.repository.d.ts +1 -0
- package/dist/repositories/noop-brute-force.repository.d.ts.map +1 -1
- package/dist/repositories/noop-brute-force.repository.js +4 -0
- package/dist/repositories/noop-brute-force.repository.js.map +1 -1
- package/dist/resolvers/base-auth.resolver.d.ts +4 -3
- package/dist/resolvers/base-auth.resolver.d.ts.map +1 -1
- package/dist/resolvers/base-auth.resolver.js +24 -12
- package/dist/resolvers/base-auth.resolver.js.map +1 -1
- package/dist/resolvers/oauth.controller.d.ts.map +1 -1
- package/dist/resolvers/oauth.controller.js +7 -4
- package/dist/resolvers/oauth.controller.js.map +1 -1
- package/dist/services/auth.service.d.ts +16 -10
- package/dist/services/auth.service.d.ts.map +1 -1
- package/dist/services/auth.service.js +67 -48
- package/dist/services/auth.service.js.map +1 -1
- package/dist/services/brute-force-protection.service.d.ts +14 -7
- package/dist/services/brute-force-protection.service.d.ts.map +1 -1
- package/dist/services/brute-force-protection.service.js +68 -14
- package/dist/services/brute-force-protection.service.js.map +1 -1
- package/dist/services/default-jwt-payload-factory.d.ts +1 -0
- package/dist/services/default-jwt-payload-factory.d.ts.map +1 -1
- package/dist/services/default-jwt-payload-factory.js +5 -1
- package/dist/services/default-jwt-payload-factory.js.map +1 -1
- package/dist/services/verification.service.d.ts +7 -7
- package/dist/services/verification.service.d.ts.map +1 -1
- package/dist/services/verification.service.js +17 -17
- package/dist/services/verification.service.js.map +1 -1
- package/dist/strategies/jwt.strategy.d.ts +3 -1
- package/dist/strategies/jwt.strategy.d.ts.map +1 -1
- package/dist/strategies/jwt.strategy.js +10 -1
- package/dist/strategies/jwt.strategy.js.map +1 -1
- package/dist/test-utils/mock-repositories.d.ts.map +1 -1
- package/dist/test-utils/mock-repositories.js +1 -0
- package/dist/test-utils/mock-repositories.js.map +1 -1
- package/dist/utils/ip-hash.d.ts +2 -0
- package/dist/utils/ip-hash.d.ts.map +1 -0
- package/dist/utils/ip-hash.js +11 -0
- package/dist/utils/ip-hash.js.map +1 -0
- package/examples/full-resolver-template.ts +305 -0
- package/package.json +2 -1
|
@@ -76,7 +76,8 @@ let OAuthController = OAuthController_1 = class OAuthController {
|
|
|
76
76
|
}
|
|
77
77
|
let result;
|
|
78
78
|
try {
|
|
79
|
-
|
|
79
|
+
const realm = request._realm;
|
|
80
|
+
result = await this.authService.handleSocialLogin('google', googleProfile, ipAddress, realm);
|
|
80
81
|
this.logger.log(`[OAUTH_CONTROLLER] Google Sign-In successful for user: ${result.user.id}`);
|
|
81
82
|
this.securityLogger.log(auth_logger_interface_1.SecurityEvent.OAUTH_SUCCESS, {
|
|
82
83
|
userId: result.user.id,
|
|
@@ -144,7 +145,8 @@ let OAuthController = OAuthController_1 = class OAuthController {
|
|
|
144
145
|
const facebookProfile = await this.facebookStrategy.verifyAccessToken(body.accessToken);
|
|
145
146
|
if (!facebookProfile.email) {
|
|
146
147
|
this.logger.warn(`[OAUTH_CONTROLLER] Facebook email missing for facebookId: ${facebookProfile.facebookId}`);
|
|
147
|
-
const
|
|
148
|
+
const realm = request._realm;
|
|
149
|
+
const existingUser = await this.userRepository.findByOAuthProvider('facebook', facebookProfile.facebookId, realm);
|
|
148
150
|
if (existingUser) {
|
|
149
151
|
this.logger.log(`[OAUTH_CONTROLLER] Found existing Facebook user by facebookId: ${existingUser.id}, using stored email: ${existingUser.email}`);
|
|
150
152
|
const profileWithStoredEmail = {
|
|
@@ -154,7 +156,7 @@ let OAuthController = OAuthController_1 = class OAuthController {
|
|
|
154
156
|
};
|
|
155
157
|
let result;
|
|
156
158
|
try {
|
|
157
|
-
result = await this.authService.handleSocialLogin('facebook', profileWithStoredEmail, ipAddress);
|
|
159
|
+
result = await this.authService.handleSocialLogin('facebook', profileWithStoredEmail, ipAddress, realm);
|
|
158
160
|
this.logger.log(`[OAUTH_CONTROLLER] Facebook Sign-In successful for existing user: ${result.user.id}`);
|
|
159
161
|
this.securityLogger.log(auth_logger_interface_1.SecurityEvent.OAUTH_SUCCESS, {
|
|
160
162
|
userId: result.user.id,
|
|
@@ -199,11 +201,12 @@ let OAuthController = OAuthController_1 = class OAuthController {
|
|
|
199
201
|
}
|
|
200
202
|
let result;
|
|
201
203
|
try {
|
|
204
|
+
const facebookRealm = request._realm;
|
|
202
205
|
result = await this.authService.handleSocialLogin('facebook', {
|
|
203
206
|
...facebookProfile,
|
|
204
207
|
email: facebookProfile.email,
|
|
205
208
|
emailVerified: facebookProfile.emailVerified,
|
|
206
|
-
}, ipAddress);
|
|
209
|
+
}, ipAddress, facebookRealm);
|
|
207
210
|
this.logger.log(`[OAUTH_CONTROLLER] Facebook Sign-In successful for user: ${result.user.id}`);
|
|
208
211
|
this.securityLogger.log(auth_logger_interface_1.SecurityEvent.OAUTH_SUCCESS, {
|
|
209
212
|
userId: result.user.id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth.controller.js","sourceRoot":"","sources":["../../src/resolvers/oauth.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CASwB;AACxB,iDAA6C;AAE7C,qDAAuD;AACvD,2DAAuD;AACvD,mEAA+D;AAC/D,uEAAmE;AACnE,+FAAyF;AACzF,yFAAmF;AACnF,qEAA2E;AAC3E,+EAAiF;AAGjF,4CAA4D;AAC5D,8DAA4D;AAE5D,MAAa,eAAe;CAI3B;AAJD,0CAIC;AADC;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,G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A,IAAA,aAAI,GAAE,CAAA;IACN,WAAA,IAAA,YAAG,GAAE,CAAA;;qCADQ,eAAe;;mDA0G9B;AAiDK;IAHL,IAAA,aAAI,EAAC,gBAAgB,CAAC;IACtB,IAAA,iBAAQ,EAAC,mBAAU,CAAC,EAAE,CAAC;IACvB,IAAA,oBAAQ,EAAC,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC;IAE9C,WAAA,IAAA,aAAI,GAAE,CAAA;IACN,WAAA,IAAA,YAAG,GAAE,CAAA;;qCADQ,iBAAiB;;qDAqNhC;0BA7YU,eAAe;IAD3B,IAAA,mBAAU,EAAC,MAAM,CAAC;IAUd,WAAA,IAAA,eAAM,EAAC,2BAAe,CAAC,CAAA;IAEvB,WAAA,IAAA,eAAM,EAAC,uBAAW,CAAC,CAAA;qCAPC,0BAAW;QACR,gCAAc;QACZ,oCAAgB;QACZ,4DAA2B;QACvB,sDAAwB;GARjD,eAAe,CAkZ3B"}
|
|
@@ -38,17 +38,17 @@ export declare class AuthService {
|
|
|
38
38
|
private readonly jwtPayloadFactory;
|
|
39
39
|
private static readonly DUMMY_HASH;
|
|
40
40
|
constructor(userRepository: IUserRepository<IAuthUser>, refreshTokenRepository: IRefreshTokenRepository, jwtService: JwtService, refreshTokenService: RefreshTokenService, bruteForceProtection: BruteForceProtectionService, verificationService: VerificationService, oauthLinkingTokenService: OAuthLinkingTokenService, facebookStrategy: FacebookStrategy, securityLogger: IAuthLogger, lifecycleHooks: IAuthLifecycleHooks<IAuthUser>, emailService: IEmailService, smsService: ISmsService, authModuleOptions: AuthModuleOptions, rateLimiter: IRateLimiter, jwtPayloadFactory?: IJwtPayloadFactory);
|
|
41
|
-
signup(email: string, password: string): Promise<{
|
|
41
|
+
signup(email: string, password: string, realm?: string): Promise<{
|
|
42
42
|
accessToken: string;
|
|
43
43
|
refreshToken: string;
|
|
44
44
|
user: IAuthUser;
|
|
45
45
|
}>;
|
|
46
|
-
login(email: string, password: string, ipAddress?: string): Promise<{
|
|
46
|
+
login(email: string, password: string, ipAddress?: string, realm?: string): Promise<{
|
|
47
47
|
accessToken: string;
|
|
48
48
|
refreshToken: string;
|
|
49
49
|
user: IAuthUser;
|
|
50
50
|
}>;
|
|
51
|
-
refreshToken(refreshToken: string, ipAddress?: string): Promise<{
|
|
51
|
+
refreshToken(refreshToken: string, ipAddress?: string, realm?: string): Promise<{
|
|
52
52
|
accessToken: string;
|
|
53
53
|
refreshToken: string;
|
|
54
54
|
user: IAuthUser;
|
|
@@ -60,15 +60,15 @@ export declare class AuthService {
|
|
|
60
60
|
success: boolean;
|
|
61
61
|
message: string;
|
|
62
62
|
}>;
|
|
63
|
-
verifyEmail(email: string, code: string): Promise<{
|
|
63
|
+
verifyEmail(email: string, code: string, realm?: string): Promise<{
|
|
64
64
|
success: boolean;
|
|
65
65
|
message: string;
|
|
66
66
|
}>;
|
|
67
|
-
resendVerificationEmail(email: string): Promise<{
|
|
67
|
+
resendVerificationEmail(email: string, realm?: string): Promise<{
|
|
68
68
|
success: boolean;
|
|
69
69
|
message: string;
|
|
70
70
|
}>;
|
|
71
|
-
sendPhoneVerification(userId: string, phoneNumber: string, countryCode?: string): Promise<{
|
|
71
|
+
sendPhoneVerification(userId: string, phoneNumber: string, countryCode?: string, realm?: string): Promise<{
|
|
72
72
|
success: boolean;
|
|
73
73
|
message: string;
|
|
74
74
|
phoneNumber?: string;
|
|
@@ -97,12 +97,12 @@ export declare class AuthService {
|
|
|
97
97
|
emailVerified: boolean;
|
|
98
98
|
firstName?: string;
|
|
99
99
|
lastName?: string;
|
|
100
|
-
}, _ipAddress?: string): Promise<{
|
|
100
|
+
}, _ipAddress?: string, realm?: string): Promise<{
|
|
101
101
|
accessToken: string;
|
|
102
102
|
refreshToken: string;
|
|
103
103
|
user: IAuthUser;
|
|
104
104
|
}>;
|
|
105
|
-
completeFacebookSignUp(fallbackToken: string, email: string, accessToken: string): Promise<{
|
|
105
|
+
completeFacebookSignUp(fallbackToken: string, email: string, accessToken: string, realm?: string): Promise<{
|
|
106
106
|
accessToken: string;
|
|
107
107
|
refreshToken: string;
|
|
108
108
|
user: IAuthUser;
|
|
@@ -113,17 +113,23 @@ export declare class AuthService {
|
|
|
113
113
|
user: IAuthUser;
|
|
114
114
|
alreadyUnlinked: boolean;
|
|
115
115
|
}>;
|
|
116
|
-
requestPasswordReset(email: string, ipAddress?: string): Promise<{
|
|
116
|
+
requestPasswordReset(email: string, ipAddress?: string, realm?: string): Promise<{
|
|
117
117
|
success: boolean;
|
|
118
118
|
message: string;
|
|
119
119
|
retryAfterSeconds?: number;
|
|
120
120
|
}>;
|
|
121
|
-
resetPassword(email: string, code: string, newPassword: string, ipAddress?: string): Promise<{
|
|
121
|
+
resetPassword(email: string, code: string, newPassword: string, ipAddress?: string, realm?: string): Promise<{
|
|
122
122
|
success: boolean;
|
|
123
123
|
message: string;
|
|
124
124
|
user: IAuthUser;
|
|
125
125
|
}>;
|
|
126
126
|
get cookieAuthEnabled(): boolean;
|
|
127
|
+
issueAuthSession(userId: string, res?: {
|
|
128
|
+
cookie: (name: string, value: string, options: Record<string, unknown>) => void;
|
|
129
|
+
}, realm?: string): Promise<{
|
|
130
|
+
accessToken: string;
|
|
131
|
+
refreshToken: string;
|
|
132
|
+
}>;
|
|
127
133
|
setAuthCookies(res: {
|
|
128
134
|
cookie: (name: string, value: string, options: Record<string, unknown>) => void;
|
|
129
135
|
}, accessToken: string, refreshToken: string): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.service.d.ts","sourceRoot":"","sources":["../../src/services/auth.service.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAOzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,wB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AO,CAAC,KAAK,IAAI,CAAA;KAAE,GAC7E,IAAI;IAiCP,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAWtC,OAAO,CAAC,aAAa;YAYP,yBAAyB;CAiBxC"}
|
|
@@ -85,7 +85,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
85
85
|
this.jwtPayloadFactory = jwtPayloadFactory || new default_jwt_payload_factory_1.DefaultJwtPayloadFactory();
|
|
86
86
|
this.passwordValidationService = new password_validation_service_1.PasswordValidationService(authModuleOptions?.passwordPolicy);
|
|
87
87
|
}
|
|
88
|
-
async signup(email, password) {
|
|
88
|
+
async signup(email, password, realm) {
|
|
89
89
|
const passwordHash = await bcrypt.hash(password, this.bcryptRounds);
|
|
90
90
|
let user;
|
|
91
91
|
try {
|
|
@@ -93,6 +93,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
93
93
|
email,
|
|
94
94
|
passwordHash,
|
|
95
95
|
authProvider: auth_user_interface_1.AuthProvider.EMAIL,
|
|
96
|
+
realm,
|
|
96
97
|
});
|
|
97
98
|
}
|
|
98
99
|
catch (error) {
|
|
@@ -134,7 +135,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
134
135
|
await this.lifecycleHooks.onSignup(user);
|
|
135
136
|
}
|
|
136
137
|
try {
|
|
137
|
-
const verificationCode = await this.verificationService.generateCode(user.email, 'email');
|
|
138
|
+
const verificationCode = await this.verificationService.generateCode(user.email, 'email', realm);
|
|
138
139
|
await this.emailService.sendVerificationEmail(user.email, verificationCode, 15);
|
|
139
140
|
await this.userRepository.update(user.id, {
|
|
140
141
|
emailVerificationSentAt: new Date(),
|
|
@@ -145,18 +146,18 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
145
146
|
const errorStack = error instanceof Error ? error.stack : undefined;
|
|
146
147
|
this.logger.error(`Failed to send verification email to ${user.email}`, errorStack);
|
|
147
148
|
}
|
|
148
|
-
const { accessToken, refreshToken } = await this.generateTokenPairAndStore(user);
|
|
149
|
+
const { accessToken, refreshToken } = await this.generateTokenPairAndStore(user, realm);
|
|
149
150
|
return { accessToken, refreshToken, user };
|
|
150
151
|
}
|
|
151
|
-
async login(email, password, ipAddress) {
|
|
152
|
+
async login(email, password, ipAddress, realm) {
|
|
152
153
|
this.logger.log(`[AUTH_SERVICE] Login started for email: ${email}`);
|
|
153
|
-
if (ipAddress && (await this.bruteForceProtection.checkIpRateLimit(ipAddress))) {
|
|
154
|
+
if (ipAddress && (await this.bruteForceProtection.checkIpRateLimit(ipAddress, realm))) {
|
|
154
155
|
throw new common_1.HttpException({
|
|
155
156
|
message: 'Too many login attempts from this IP address. Please try again later.',
|
|
156
157
|
code: 'RATE_LIMIT_EXCEEDED',
|
|
157
158
|
}, common_1.HttpStatus.TOO_MANY_REQUESTS);
|
|
158
159
|
}
|
|
159
|
-
const user = await this.userRepository.findByEmail(email);
|
|
160
|
+
const user = await this.userRepository.findByEmail(email, realm);
|
|
160
161
|
if (user && await this.bruteForceProtection.isAccountLockedById(user.id)) {
|
|
161
162
|
const remainingTime = await this.bruteForceProtection.getRemainingLockoutTimeById(user.id);
|
|
162
163
|
throw new account_locked_exception_1.AccountLockedException(remainingTime);
|
|
@@ -172,7 +173,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
172
173
|
this.lifecycleHooks.onAuthFailure(email, ipAddress, 'USER_NOT_FOUND');
|
|
173
174
|
}
|
|
174
175
|
if (ipAddress) {
|
|
175
|
-
await this.bruteForceProtection.recordFailedAttempt(email, ipAddress);
|
|
176
|
+
await this.bruteForceProtection.recordFailedAttempt(email, ipAddress, undefined, realm);
|
|
176
177
|
}
|
|
177
178
|
throw new common_1.UnauthorizedException('Invalid credentials');
|
|
178
179
|
}
|
|
@@ -191,11 +192,11 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
191
192
|
this.lifecycleHooks.onAuthFailure(email, ipAddress, 'INVALID_PASSWORD');
|
|
192
193
|
}
|
|
193
194
|
if (ipAddress) {
|
|
194
|
-
await this.bruteForceProtection.recordFailedAttempt(email, ipAddress, user.id);
|
|
195
|
+
await this.bruteForceProtection.recordFailedAttempt(email, ipAddress, user.id, realm);
|
|
195
196
|
}
|
|
196
197
|
throw new common_1.UnauthorizedException('Invalid credentials');
|
|
197
198
|
}
|
|
198
|
-
await this.bruteForceProtection.resetFailedAttempts(email);
|
|
199
|
+
await this.bruteForceProtection.resetFailedAttempts(email, realm);
|
|
199
200
|
this.securityLogger.log(auth_logger_interface_1.SecurityEvent.LOGIN_SUCCESS, {
|
|
200
201
|
userId: user.id,
|
|
201
202
|
email,
|
|
@@ -204,10 +205,10 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
204
205
|
if (this.lifecycleHooks.onLogin) {
|
|
205
206
|
await this.lifecycleHooks.onLogin(user);
|
|
206
207
|
}
|
|
207
|
-
const { accessToken, refreshToken } = await this.generateTokenPairAndStore(user);
|
|
208
|
+
const { accessToken, refreshToken } = await this.generateTokenPairAndStore(user, realm);
|
|
208
209
|
return { accessToken, refreshToken, user };
|
|
209
210
|
}
|
|
210
|
-
async refreshToken(refreshToken, ipAddress) {
|
|
211
|
+
async refreshToken(refreshToken, ipAddress, realm) {
|
|
211
212
|
try {
|
|
212
213
|
const refreshTokenHash = this.refreshTokenService.hashToken(refreshToken);
|
|
213
214
|
const cachedResult = this.refreshTokenService.getCachedRefreshResult(refreshTokenHash);
|
|
@@ -256,7 +257,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
256
257
|
});
|
|
257
258
|
throw new common_1.UnauthorizedException('User not found');
|
|
258
259
|
}
|
|
259
|
-
const { accessToken: newAccessToken, refreshToken: newRefreshToken, refreshTokenHash: newRefreshTokenHash, } = await this.generateTokenPairAndStore(user);
|
|
260
|
+
const { accessToken: newAccessToken, refreshToken: newRefreshToken, refreshTokenHash: newRefreshTokenHash, } = await this.generateTokenPairAndStore(user, realm);
|
|
260
261
|
await this.refreshTokenRepository.delete(storedToken.id);
|
|
261
262
|
await this.refreshTokenRepository.deleteExpired().catch((err) => {
|
|
262
263
|
this.logger.warn(`Failed to clean up expired refresh tokens: ${err instanceof Error ? err.message : String(err)}`);
|
|
@@ -354,8 +355,8 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
354
355
|
message: 'Password changed successfully. Please log in again with your new password.',
|
|
355
356
|
};
|
|
356
357
|
}
|
|
357
|
-
async verifyEmail(email, code) {
|
|
358
|
-
const user = await this.userRepository.findByEmail(email);
|
|
358
|
+
async verifyEmail(email, code, realm) {
|
|
359
|
+
const user = await this.userRepository.findByEmail(email, realm);
|
|
359
360
|
if (!user) {
|
|
360
361
|
throw new common_1.UnauthorizedException('Invalid email address');
|
|
361
362
|
}
|
|
@@ -365,7 +366,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
365
366
|
message: 'Email is already verified',
|
|
366
367
|
};
|
|
367
368
|
}
|
|
368
|
-
await this.verificationService.validateCode(email, 'email', code);
|
|
369
|
+
await this.verificationService.validateCode(email, 'email', code, realm);
|
|
369
370
|
await this.userRepository.markEmailVerified(user.id);
|
|
370
371
|
if (this.lifecycleHooks.onEmailVerified) {
|
|
371
372
|
await this.lifecycleHooks.onEmailVerified(user);
|
|
@@ -376,8 +377,8 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
376
377
|
message: 'Email successfully verified',
|
|
377
378
|
};
|
|
378
379
|
}
|
|
379
|
-
async resendVerificationEmail(email) {
|
|
380
|
-
const user = await this.userRepository.findByEmail(email);
|
|
380
|
+
async resendVerificationEmail(email, realm) {
|
|
381
|
+
const user = await this.userRepository.findByEmail(email, realm);
|
|
381
382
|
if (!user) {
|
|
382
383
|
throw new common_1.UnauthorizedException('Invalid email address');
|
|
383
384
|
}
|
|
@@ -396,8 +397,8 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
396
397
|
throw new VerificationEmailRateLimitException(retryAfterSeconds);
|
|
397
398
|
}
|
|
398
399
|
}
|
|
399
|
-
await this.verificationService.invalidateCode(email, 'email');
|
|
400
|
-
const verificationCode = await this.verificationService.generateCode(email, 'email');
|
|
400
|
+
await this.verificationService.invalidateCode(email, 'email', realm);
|
|
401
|
+
const verificationCode = await this.verificationService.generateCode(email, 'email', realm);
|
|
401
402
|
try {
|
|
402
403
|
await this.emailService.sendVerificationEmail(email, verificationCode, 15);
|
|
403
404
|
await this.userRepository.update(user.id, {
|
|
@@ -415,7 +416,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
415
416
|
throw new common_1.HttpException('Failed to send verification email. Please try again later.', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
|
|
416
417
|
}
|
|
417
418
|
}
|
|
418
|
-
async sendPhoneVerification(userId, phoneNumber, countryCode) {
|
|
419
|
+
async sendPhoneVerification(userId, phoneNumber, countryCode, realm) {
|
|
419
420
|
const user = await this.userRepository.findById(userId);
|
|
420
421
|
if (!user) {
|
|
421
422
|
throw new common_1.UnauthorizedException('User not found');
|
|
@@ -424,7 +425,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
424
425
|
if (!normalizedPhone) {
|
|
425
426
|
throw new common_1.BadRequestException('Invalid phone number format');
|
|
426
427
|
}
|
|
427
|
-
const existingUser = await this.userRepository.findByPhoneNumber(normalizedPhone);
|
|
428
|
+
const existingUser = await this.userRepository.findByPhoneNumber(normalizedPhone, realm);
|
|
428
429
|
if (existingUser && existingUser.id !== userId) {
|
|
429
430
|
throw new common_1.ConflictException('This phone number is already associated with another account');
|
|
430
431
|
}
|
|
@@ -602,23 +603,23 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
602
603
|
},
|
|
603
604
|
};
|
|
604
605
|
}
|
|
605
|
-
async handleSocialLogin(provider, profile, _ipAddress) {
|
|
606
|
+
async handleSocialLogin(provider, profile, _ipAddress, realm) {
|
|
606
607
|
this.logger.log(`[AUTH_SERVICE] Social login started for ${provider}: ${profile.email}`);
|
|
607
608
|
const providerIdField = `${provider}Id`;
|
|
608
609
|
const providerId = profile[providerIdField];
|
|
609
610
|
if (!providerId) {
|
|
610
611
|
throw new common_1.UnauthorizedException(`Missing ${providerIdField} in profile`);
|
|
611
612
|
}
|
|
612
|
-
let user = await this.userRepository.findByOAuthProvider(provider, providerId);
|
|
613
|
+
let user = await this.userRepository.findByOAuthProvider(provider, providerId, realm);
|
|
613
614
|
if (user) {
|
|
614
615
|
this.logger.log(`[AUTH_SERVICE] Existing OAuth user found: ${user.id}`);
|
|
615
616
|
if (this.lifecycleHooks.onLogin) {
|
|
616
617
|
await this.lifecycleHooks.onLogin(user);
|
|
617
618
|
}
|
|
618
|
-
const { accessToken, refreshToken } = await this.generateTokenPairAndStore(user);
|
|
619
|
+
const { accessToken, refreshToken } = await this.generateTokenPairAndStore(user, realm);
|
|
619
620
|
return { accessToken, refreshToken, user };
|
|
620
621
|
}
|
|
621
|
-
user = await this.userRepository.findByEmail(profile.email);
|
|
622
|
+
user = await this.userRepository.findByEmail(profile.email, realm);
|
|
622
623
|
if (user) {
|
|
623
624
|
this.logger.log(`[AUTH_SERVICE] Email exists for ${profile.email}, checking account linking`);
|
|
624
625
|
if (user.passwordHash) {
|
|
@@ -648,7 +649,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
648
649
|
if (this.lifecycleHooks.onLogin) {
|
|
649
650
|
await this.lifecycleHooks.onLogin(user);
|
|
650
651
|
}
|
|
651
|
-
const { accessToken, refreshToken } = await this.generateTokenPairAndStore(user);
|
|
652
|
+
const { accessToken, refreshToken } = await this.generateTokenPairAndStore(user, realm);
|
|
652
653
|
return { accessToken, refreshToken, user };
|
|
653
654
|
}
|
|
654
655
|
this.logger.log(`[AUTH_SERVICE] Creating new OAuth user for ${profile.email}`);
|
|
@@ -658,6 +659,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
658
659
|
passwordHash: null,
|
|
659
660
|
emailVerified: true,
|
|
660
661
|
authProvider: providerEnum,
|
|
662
|
+
realm,
|
|
661
663
|
};
|
|
662
664
|
userData[providerIdField] = providerId;
|
|
663
665
|
const newUser = await this.userRepository.create(userData);
|
|
@@ -666,10 +668,10 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
666
668
|
await this.lifecycleHooks.onSignup(newUser);
|
|
667
669
|
}
|
|
668
670
|
this.logger.log(`[AUTH_SERVICE] Lifecycle hooks completed for user: ${newUser.id}`);
|
|
669
|
-
const { accessToken, refreshToken } = await this.generateTokenPairAndStore(newUser);
|
|
671
|
+
const { accessToken, refreshToken } = await this.generateTokenPairAndStore(newUser, realm);
|
|
670
672
|
return { accessToken, refreshToken, user: newUser };
|
|
671
673
|
}
|
|
672
|
-
async completeFacebookSignUp(fallbackToken, email, accessToken) {
|
|
674
|
+
async completeFacebookSignUp(fallbackToken, email, accessToken, realm) {
|
|
673
675
|
this.logger.log(`[AUTH_SERVICE] ===== COMPLETE FACEBOOK SIGN-UP =====`);
|
|
674
676
|
this.logger.log(`[AUTH_SERVICE] Email: ${email}`);
|
|
675
677
|
let fallbackPayload;
|
|
@@ -699,7 +701,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
699
701
|
throw new oauth_exceptions_1.InvalidOAuthTokenException('facebook', 'Access token does not match Facebook account');
|
|
700
702
|
}
|
|
701
703
|
this.logger.log(`[AUTH_SERVICE] Facebook access token validated and matched facebookId: ${facebookId}`);
|
|
702
|
-
const existingUser = await this.userRepository.findByEmail(email);
|
|
704
|
+
const existingUser = await this.userRepository.findByEmail(email, realm);
|
|
703
705
|
if (existingUser) {
|
|
704
706
|
this.logger.log(`[AUTH_SERVICE] Email exists for ${email}, checking account linking...`);
|
|
705
707
|
if (existingUser.passwordHash) {
|
|
@@ -729,7 +731,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
729
731
|
if (this.lifecycleHooks.onLogin) {
|
|
730
732
|
await this.lifecycleHooks.onLogin(linkedUser);
|
|
731
733
|
}
|
|
732
|
-
const { accessToken: jwtAccessToken, refreshToken } = await this.generateTokenPairAndStore(linkedUser);
|
|
734
|
+
const { accessToken: jwtAccessToken, refreshToken } = await this.generateTokenPairAndStore(linkedUser, realm);
|
|
733
735
|
this.logger.log(`[AUTH_SERVICE] Facebook account linking complete for user: ${linkedUser.id}`);
|
|
734
736
|
return {
|
|
735
737
|
accessToken: jwtAccessToken,
|
|
@@ -745,6 +747,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
745
747
|
emailVerified: false,
|
|
746
748
|
createdAt: new Date(),
|
|
747
749
|
updatedAt: new Date(),
|
|
750
|
+
realm,
|
|
748
751
|
});
|
|
749
752
|
this.logger.log(`[AUTH_SERVICE] New Facebook user created: ${newUser.id}`);
|
|
750
753
|
if (this.lifecycleHooks.onSignup) {
|
|
@@ -752,7 +755,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
752
755
|
}
|
|
753
756
|
this.logger.log(`[AUTH_SERVICE] Lifecycle hooks completed for user: ${newUser.id}`);
|
|
754
757
|
try {
|
|
755
|
-
const verificationCode = await this.verificationService.generateCode(newUser.email, 'email');
|
|
758
|
+
const verificationCode = await this.verificationService.generateCode(newUser.email, 'email', realm);
|
|
756
759
|
await this.emailService.sendVerificationEmail(newUser.email, verificationCode, 15);
|
|
757
760
|
await this.userRepository.update(newUser.id, {
|
|
758
761
|
emailVerificationSentAt: new Date(),
|
|
@@ -764,7 +767,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
764
767
|
const errorStack = error instanceof Error ? error.stack : undefined;
|
|
765
768
|
this.logger.error(`[AUTH_SERVICE] Failed to send verification email to ${newUser.email}: ${errorMessage}`, errorStack);
|
|
766
769
|
}
|
|
767
|
-
const { accessToken: jwtAccessToken, refreshToken } = await this.generateTokenPairAndStore(newUser);
|
|
770
|
+
const { accessToken: jwtAccessToken, refreshToken } = await this.generateTokenPairAndStore(newUser, realm);
|
|
768
771
|
this.logger.log(`[AUTH_SERVICE] Facebook sign-up complete for user: ${newUser.id}`);
|
|
769
772
|
this.logger.log(`[AUTH_SERVICE] NOTE: Email verification required (check email for code)`);
|
|
770
773
|
return { accessToken: jwtAccessToken, refreshToken, user: newUser };
|
|
@@ -773,10 +776,10 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
773
776
|
this.logger.log(`[AUTH_SERVICE] Unlink ${provider} account for user: ${userId}`);
|
|
774
777
|
throw new Error('unlinkSocialAccount transaction not implemented - requires repository with transaction support. See README.md');
|
|
775
778
|
}
|
|
776
|
-
async requestPasswordReset(email, ipAddress) {
|
|
779
|
+
async requestPasswordReset(email, ipAddress, realm) {
|
|
777
780
|
const normalizedEmail = email.toLowerCase();
|
|
778
781
|
if (ipAddress && this.rateLimiter) {
|
|
779
|
-
const ipRateLimitKey = `password-reset:ip:${ipAddress}`;
|
|
782
|
+
const ipRateLimitKey = realm ? `${realm}:password-reset:ip:${ipAddress}` : `password-reset:ip:${ipAddress}`;
|
|
780
783
|
const ipLimit = await this.rateLimiter.checkRateLimit(ipRateLimitKey, 5, 3600000);
|
|
781
784
|
if (!ipLimit.allowed) {
|
|
782
785
|
const retryAfterSeconds = Math.ceil((ipLimit.resetAt.getTime() - Date.now()) / 1000);
|
|
@@ -786,7 +789,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
786
789
|
}
|
|
787
790
|
await this.rateLimiter.recordAttempt(ipRateLimitKey, 3600000);
|
|
788
791
|
}
|
|
789
|
-
const user = await this.userRepository.findByEmail(normalizedEmail);
|
|
792
|
+
const user = await this.userRepository.findByEmail(normalizedEmail, realm);
|
|
790
793
|
if (!user) {
|
|
791
794
|
this.securityLogger.log(auth_logger_interface_1.SecurityEvent.PASSWORD_RESET_REQUESTED, {
|
|
792
795
|
email: normalizedEmail,
|
|
@@ -798,8 +801,8 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
798
801
|
message: 'If an account exists with this email, a password reset code has been sent.',
|
|
799
802
|
};
|
|
800
803
|
}
|
|
801
|
-
if (await this.bruteForceProtection.isAccountLocked(normalizedEmail)) {
|
|
802
|
-
const remainingTime = await this.bruteForceProtection.getRemainingLockoutTime(normalizedEmail);
|
|
804
|
+
if (await this.bruteForceProtection.isAccountLocked(normalizedEmail, realm)) {
|
|
805
|
+
const remainingTime = await this.bruteForceProtection.getRemainingLockoutTime(normalizedEmail, realm);
|
|
803
806
|
throw new account_locked_exception_1.AccountLockedException(remainingTime);
|
|
804
807
|
}
|
|
805
808
|
if (user.passwordResetSentAt) {
|
|
@@ -818,8 +821,8 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
818
821
|
message: 'If an account exists with this email, a password reset code has been sent.',
|
|
819
822
|
};
|
|
820
823
|
}
|
|
821
|
-
await this.verificationService.invalidateCode(normalizedEmail, 'password-reset');
|
|
822
|
-
const code = await this.verificationService.generateCode(normalizedEmail, 'password-reset');
|
|
824
|
+
await this.verificationService.invalidateCode(normalizedEmail, 'password-reset', realm);
|
|
825
|
+
const code = await this.verificationService.generateCode(normalizedEmail, 'password-reset', realm);
|
|
823
826
|
try {
|
|
824
827
|
const resetUrl = `${process.env.FRONTEND_URL || 'https://app.example.com'}/reset-password`;
|
|
825
828
|
await this.emailService.sendPasswordResetEmail(normalizedEmail, code, resetUrl);
|
|
@@ -847,14 +850,14 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
847
850
|
};
|
|
848
851
|
}
|
|
849
852
|
}
|
|
850
|
-
async resetPassword(email, code, newPassword, ipAddress) {
|
|
853
|
+
async resetPassword(email, code, newPassword, ipAddress, realm) {
|
|
851
854
|
const normalizedEmail = email.toLowerCase();
|
|
852
|
-
const user = await this.userRepository.findByEmail(normalizedEmail);
|
|
855
|
+
const user = await this.userRepository.findByEmail(normalizedEmail, realm);
|
|
853
856
|
if (!user) {
|
|
854
857
|
throw new common_1.UnauthorizedException('Invalid email or verification code');
|
|
855
858
|
}
|
|
856
|
-
if (await this.bruteForceProtection.isAccountLocked(normalizedEmail)) {
|
|
857
|
-
const remainingTime = await this.bruteForceProtection.getRemainingLockoutTime(normalizedEmail);
|
|
859
|
+
if (await this.bruteForceProtection.isAccountLocked(normalizedEmail, realm)) {
|
|
860
|
+
const remainingTime = await this.bruteForceProtection.getRemainingLockoutTime(normalizedEmail, realm);
|
|
858
861
|
throw new account_locked_exception_1.AccountLockedException(remainingTime);
|
|
859
862
|
}
|
|
860
863
|
if (!user.passwordHash) {
|
|
@@ -865,7 +868,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
865
868
|
const { WeakPasswordException } = await Promise.resolve().then(() => __importStar(require('../exceptions/password-reset.exceptions')));
|
|
866
869
|
throw new WeakPasswordException(errors);
|
|
867
870
|
}
|
|
868
|
-
await this.verificationService.validateCode(normalizedEmail, 'password-reset', code);
|
|
871
|
+
await this.verificationService.validateCode(normalizedEmail, 'password-reset', code, realm);
|
|
869
872
|
const passwordHash = await bcrypt.hash(newPassword, this.bcryptRounds);
|
|
870
873
|
const updatedUser = await this.userRepository.updatePassword(user.id, passwordHash);
|
|
871
874
|
await this.refreshTokenRepository.deleteByUserId(user.id);
|
|
@@ -901,6 +904,22 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
901
904
|
get cookieAuthEnabled() {
|
|
902
905
|
return this.authModuleOptions?.features?.cookieAuth === true;
|
|
903
906
|
}
|
|
907
|
+
async issueAuthSession(userId, res, realm) {
|
|
908
|
+
const user = await this.userRepository.findById(userId);
|
|
909
|
+
if (!user) {
|
|
910
|
+
throw new common_1.UnauthorizedException('User not found');
|
|
911
|
+
}
|
|
912
|
+
const { accessToken, refreshToken } = await this.generateTokenPairAndStore(user, realm);
|
|
913
|
+
if (res && this.cookieAuthEnabled) {
|
|
914
|
+
this.setAuthCookies(res, accessToken, refreshToken);
|
|
915
|
+
}
|
|
916
|
+
this.securityLogger.log(auth_logger_interface_1.SecurityEvent.SESSION_ISSUED, {
|
|
917
|
+
userId,
|
|
918
|
+
realm,
|
|
919
|
+
method: 'issueAuthSession',
|
|
920
|
+
});
|
|
921
|
+
return { accessToken, refreshToken };
|
|
922
|
+
}
|
|
904
923
|
setAuthCookies(res, accessToken, refreshToken) {
|
|
905
924
|
if (!this.cookieAuthEnabled)
|
|
906
925
|
return;
|
|
@@ -937,12 +956,12 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
937
956
|
maskPhoneNumber(phone) {
|
|
938
957
|
return this.smsService.maskPhoneNumber(phone);
|
|
939
958
|
}
|
|
940
|
-
generateToken(user) {
|
|
941
|
-
const payload = this.jwtPayloadFactory.createPayload(user);
|
|
959
|
+
generateToken(user, realm) {
|
|
960
|
+
const payload = this.jwtPayloadFactory.createPayload(realm !== undefined ? { ...user, realm } : user);
|
|
942
961
|
return this.jwtService.sign(payload);
|
|
943
962
|
}
|
|
944
|
-
async generateTokenPairAndStore(user) {
|
|
945
|
-
const accessToken = this.generateToken(user);
|
|
963
|
+
async generateTokenPairAndStore(user, realm) {
|
|
964
|
+
const accessToken = this.generateToken(user, realm);
|
|
946
965
|
const { token: refreshToken, hash: refreshTokenHash } = this.refreshTokenService.generateToken();
|
|
947
966
|
await this.refreshTokenRepository.create({
|
|
948
967
|
userId: user.id,
|