@ofeklabs/horizon-auth 0.1.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 +359 -0
- package/dist/auth/auth.controller.d.ts +36 -0
- package/dist/auth/auth.controller.js +173 -0
- package/dist/auth/auth.controller.js.map +1 -0
- package/dist/auth/auth.module.d.ts +2 -0
- package/dist/auth/auth.module.js +55 -0
- package/dist/auth/auth.module.js.map +1 -0
- package/dist/auth/auth.service.d.ts +26 -0
- package/dist/auth/auth.service.js +180 -0
- package/dist/auth/auth.service.js.map +1 -0
- package/dist/auth/dto/login.dto.d.ts +4 -0
- package/dist/auth/dto/login.dto.js +25 -0
- package/dist/auth/dto/login.dto.js.map +1 -0
- package/dist/auth/dto/password-reset.dto.d.ts +10 -0
- package/dist/auth/dto/password-reset.dto.js +40 -0
- package/dist/auth/dto/password-reset.dto.js.map +1 -0
- package/dist/auth/dto/register.dto.d.ts +6 -0
- package/dist/auth/dto/register.dto.js +36 -0
- package/dist/auth/dto/register.dto.js.map +1 -0
- package/dist/auth/guards/jwt-auth.guard.d.ts +9 -0
- package/dist/auth/guards/jwt-auth.guard.js +37 -0
- package/dist/auth/guards/jwt-auth.guard.js.map +1 -0
- package/dist/auth/guards/roles.guard.d.ts +7 -0
- package/dist/auth/guards/roles.guard.js +39 -0
- package/dist/auth/guards/roles.guard.js.map +1 -0
- package/dist/auth/interfaces/token.interface.d.ts +20 -0
- package/dist/auth/interfaces/token.interface.js +3 -0
- package/dist/auth/interfaces/token.interface.js.map +1 -0
- package/dist/auth/jwks.controller.d.ts +14 -0
- package/dist/auth/jwks.controller.js +53 -0
- package/dist/auth/jwks.controller.js.map +1 -0
- package/dist/auth/services/password.service.d.ts +10 -0
- package/dist/auth/services/password.service.js +42 -0
- package/dist/auth/services/password.service.js.map +1 -0
- package/dist/auth/services/token.service.d.ts +16 -0
- package/dist/auth/services/token.service.js +91 -0
- package/dist/auth/services/token.service.js.map +1 -0
- package/dist/auth/strategies/jwt.strategy.d.ts +12 -0
- package/dist/auth/strategies/jwt.strategy.js +56 -0
- package/dist/auth/strategies/jwt.strategy.js.map +1 -0
- package/dist/common/decorators/current-tenant.decorator.d.ts +1 -0
- package/dist/common/decorators/current-tenant.decorator.js +9 -0
- package/dist/common/decorators/current-tenant.decorator.js.map +1 -0
- package/dist/common/decorators/current-user.decorator.d.ts +1 -0
- package/dist/common/decorators/current-user.decorator.js +9 -0
- package/dist/common/decorators/current-user.decorator.js.map +1 -0
- package/dist/common/decorators/public.decorator.d.ts +2 -0
- package/dist/common/decorators/public.decorator.js +8 -0
- package/dist/common/decorators/public.decorator.js.map +1 -0
- package/dist/common/decorators/roles.decorator.d.ts +2 -0
- package/dist/common/decorators/roles.decorator.js +8 -0
- package/dist/common/decorators/roles.decorator.js.map +1 -0
- package/dist/common/middleware/tenant-extractor.middleware.d.ts +9 -0
- package/dist/common/middleware/tenant-extractor.middleware.js +61 -0
- package/dist/common/middleware/tenant-extractor.middleware.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/horizon-auth-config.interface.d.ts +54 -0
- package/dist/lib/horizon-auth-config.interface.js +3 -0
- package/dist/lib/horizon-auth-config.interface.js.map +1 -0
- package/dist/lib/horizon-auth.module.d.ts +11 -0
- package/dist/lib/horizon-auth.module.js +117 -0
- package/dist/lib/horizon-auth.module.js.map +1 -0
- package/dist/prisma/prisma.module.d.ts +4 -0
- package/dist/prisma/prisma.module.js +33 -0
- package/dist/prisma/prisma.module.js.map +1 -0
- package/dist/prisma/prisma.service.d.ts +8 -0
- package/dist/prisma/prisma.service.js +42 -0
- package/dist/prisma/prisma.service.js.map +1 -0
- package/dist/redis/redis.module.d.ts +4 -0
- package/dist/redis/redis.module.js +33 -0
- package/dist/redis/redis.module.js.map +1 -0
- package/dist/redis/redis.service.d.ts +17 -0
- package/dist/redis/redis.service.js +83 -0
- package/dist/redis/redis.service.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/users/users.module.d.ts +2 -0
- package/dist/users/users.module.js +23 -0
- package/dist/users/users.module.js.map +1 -0
- package/dist/users/users.service.d.ts +15 -0
- package/dist/users/users.service.js +110 -0
- package/dist/users/users.service.js.map +1 -0
- package/package.json +78 -0
- package/prisma/schema.prisma +46 -0
package/README.md
ADDED
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
# @ofeklabs/horizon-auth
|
|
2
|
+
|
|
3
|
+
Production-ready NestJS authentication module with 2026 security standards. Add enterprise-grade authentication to your application in under 60 seconds.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🔐 **Modern Security**: Argon2id password hashing, RS256 JWT signing
|
|
8
|
+
- 🔄 **Refresh Token Rotation**: Automatic token rotation with reuse detection
|
|
9
|
+
- 🚫 **Redis Blacklisting**: Revoked token management with TTL
|
|
10
|
+
- 🏢 **Multi-Tenant Support**: Built-in tenant isolation
|
|
11
|
+
- 🌍 **Cross-Language**: JWKS endpoint for polyglot microservices
|
|
12
|
+
- ⚡ **Rate Limiting**: Built-in protection against brute force attacks
|
|
13
|
+
- 🎯 **Type-Safe**: Full TypeScript support
|
|
14
|
+
- 📦 **Zero Config**: Sensible defaults, fully customizable
|
|
15
|
+
|
|
16
|
+
## Quick Start (60 seconds)
|
|
17
|
+
|
|
18
|
+
### 1. Install
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @ofeklabs/horizon-auth @prisma/client ioredis passport passport-jwt
|
|
22
|
+
npm install -D prisma
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### 2. Generate RSA Keys
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# Generate private key
|
|
29
|
+
openssl genrsa -out private.pem 2048
|
|
30
|
+
|
|
31
|
+
# Generate public key
|
|
32
|
+
openssl rsa -in private.pem -pubout -out public.pem
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### 3. Configure Module
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
// app.module.ts
|
|
39
|
+
import { Module } from '@nestjs/common';
|
|
40
|
+
import { HorizonAuthModule } from '@ofeklabs/horizon-auth';
|
|
41
|
+
import { readFileSync } from 'fs';
|
|
42
|
+
import { join } from 'path';
|
|
43
|
+
|
|
44
|
+
@Module({
|
|
45
|
+
imports: [
|
|
46
|
+
HorizonAuthModule.forRoot({
|
|
47
|
+
database: {
|
|
48
|
+
url: process.env.DATABASE_URL,
|
|
49
|
+
},
|
|
50
|
+
redis: {
|
|
51
|
+
host: process.env.REDIS_HOST || 'localhost',
|
|
52
|
+
port: parseInt(process.env.REDIS_PORT) || 6379,
|
|
53
|
+
},
|
|
54
|
+
jwt: {
|
|
55
|
+
privateKey: readFileSync(join(__dirname, '../certs/private.pem'), 'utf8'),
|
|
56
|
+
publicKey: readFileSync(join(__dirname, '../certs/public.pem'), 'utf8'),
|
|
57
|
+
},
|
|
58
|
+
}),
|
|
59
|
+
],
|
|
60
|
+
})
|
|
61
|
+
export class AppModule {}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### 4. Set Up Database
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
# Start PostgreSQL and Redis
|
|
68
|
+
docker-compose up -d
|
|
69
|
+
|
|
70
|
+
# Run Prisma migrations
|
|
71
|
+
npx prisma migrate dev
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 5. Use in Controllers
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
import { Controller, Get, Post, Body, UseGuards } from '@nestjs/common';
|
|
78
|
+
import {
|
|
79
|
+
Public,
|
|
80
|
+
CurrentUser,
|
|
81
|
+
JwtAuthGuard,
|
|
82
|
+
Roles,
|
|
83
|
+
LoginDto,
|
|
84
|
+
RegisterDto,
|
|
85
|
+
} from '@ofeklabs/horizon-auth';
|
|
86
|
+
|
|
87
|
+
@Controller()
|
|
88
|
+
export class AppController {
|
|
89
|
+
// Public endpoint - no authentication required
|
|
90
|
+
@Public()
|
|
91
|
+
@Get()
|
|
92
|
+
getHello() {
|
|
93
|
+
return { message: 'Hello World' };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Protected endpoint - requires JWT
|
|
97
|
+
@UseGuards(JwtAuthGuard)
|
|
98
|
+
@Get('profile')
|
|
99
|
+
getProfile(@CurrentUser() user) {
|
|
100
|
+
return user;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Role-based access control
|
|
104
|
+
@UseGuards(JwtAuthGuard)
|
|
105
|
+
@Roles('admin')
|
|
106
|
+
@Get('admin')
|
|
107
|
+
adminOnly() {
|
|
108
|
+
return { message: 'Admin access granted' };
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## API Endpoints
|
|
114
|
+
|
|
115
|
+
The package automatically provides these endpoints:
|
|
116
|
+
|
|
117
|
+
### Authentication
|
|
118
|
+
|
|
119
|
+
- `POST /auth/register` - Register new user
|
|
120
|
+
- `POST /auth/login` - Login with email/password
|
|
121
|
+
- `POST /auth/refresh` - Refresh access token
|
|
122
|
+
- `POST /auth/logout` - Logout and revoke tokens
|
|
123
|
+
- `GET /auth/profile` - Get current user profile
|
|
124
|
+
|
|
125
|
+
### Password Management
|
|
126
|
+
|
|
127
|
+
- `POST /auth/password-reset/request` - Request password reset
|
|
128
|
+
- `POST /auth/password-reset/complete` - Complete password reset
|
|
129
|
+
- `POST /auth/verify-email` - Verify email address
|
|
130
|
+
|
|
131
|
+
### Cross-Language Support
|
|
132
|
+
|
|
133
|
+
- `GET /.well-known/jwks.json` - Public keys for JWT verification
|
|
134
|
+
|
|
135
|
+
## Configuration Options
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
interface HorizonAuthConfig {
|
|
139
|
+
// Required
|
|
140
|
+
database: {
|
|
141
|
+
url: string;
|
|
142
|
+
};
|
|
143
|
+
redis: {
|
|
144
|
+
host: string;
|
|
145
|
+
port: number;
|
|
146
|
+
password?: string;
|
|
147
|
+
db?: number;
|
|
148
|
+
};
|
|
149
|
+
jwt: {
|
|
150
|
+
privateKey: string; // RSA private key (PEM format)
|
|
151
|
+
publicKey: string; // RSA public key (PEM format)
|
|
152
|
+
accessTokenExpiry?: string; // Default: '15m'
|
|
153
|
+
refreshTokenExpiry?: string; // Default: '7d'
|
|
154
|
+
issuer?: string; // Default: 'horizon-auth'
|
|
155
|
+
audience?: string; // Default: 'horizon-api'
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// Optional
|
|
159
|
+
multiTenant?: {
|
|
160
|
+
enabled: boolean;
|
|
161
|
+
tenantIdExtractor?: 'header' | 'subdomain' | 'custom';
|
|
162
|
+
defaultTenantId?: string;
|
|
163
|
+
};
|
|
164
|
+
rateLimit?: {
|
|
165
|
+
login?: { limit: number; ttl: number };
|
|
166
|
+
register?: { limit: number; ttl: number };
|
|
167
|
+
passwordReset?: { limit: number; ttl: number };
|
|
168
|
+
};
|
|
169
|
+
guards?: {
|
|
170
|
+
applyJwtGuardGlobally?: boolean;
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Decorators
|
|
176
|
+
|
|
177
|
+
### @Public()
|
|
178
|
+
Mark routes as publicly accessible (skip authentication)
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
@Public()
|
|
182
|
+
@Get('public')
|
|
183
|
+
publicRoute() {
|
|
184
|
+
return { message: 'No auth required' };
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### @CurrentUser()
|
|
189
|
+
Inject authenticated user into controller
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
@Get('me')
|
|
193
|
+
getMe(@CurrentUser() user) {
|
|
194
|
+
return user;
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### @Roles(...roles)
|
|
199
|
+
Require specific roles for access
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
@Roles('admin', 'moderator')
|
|
203
|
+
@Get('admin')
|
|
204
|
+
adminRoute() {
|
|
205
|
+
return { message: 'Admin only' };
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### @CurrentTenant()
|
|
210
|
+
Get current tenant ID
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
@Get('tenant-data')
|
|
214
|
+
getTenantData(@CurrentTenant() tenantId: string) {
|
|
215
|
+
return { tenantId };
|
|
216
|
+
}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Multi-Tenant Configuration
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
HorizonAuthModule.forRoot({
|
|
223
|
+
// ... other config
|
|
224
|
+
multiTenant: {
|
|
225
|
+
enabled: true,
|
|
226
|
+
tenantIdExtractor: 'header', // or 'subdomain' or 'custom'
|
|
227
|
+
defaultTenantId: 'default',
|
|
228
|
+
},
|
|
229
|
+
});
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## Dev SSO Mode
|
|
233
|
+
|
|
234
|
+
For local development with multiple microservices:
|
|
235
|
+
|
|
236
|
+
```yaml
|
|
237
|
+
# docker-compose.dev-sso.yml
|
|
238
|
+
version: '3.8'
|
|
239
|
+
services:
|
|
240
|
+
auth-service:
|
|
241
|
+
build: .
|
|
242
|
+
ports:
|
|
243
|
+
- '3000:3000'
|
|
244
|
+
environment:
|
|
245
|
+
COOKIE_DOMAIN: '.localhost'
|
|
246
|
+
REDIS_HOST: redis
|
|
247
|
+
depends_on:
|
|
248
|
+
- postgres
|
|
249
|
+
- redis
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
All `*.localhost:3000` apps will share the same authentication session.
|
|
253
|
+
|
|
254
|
+
## Cross-Language Token Verification
|
|
255
|
+
|
|
256
|
+
### C# Example
|
|
257
|
+
|
|
258
|
+
```csharp
|
|
259
|
+
using Microsoft.IdentityModel.Tokens;
|
|
260
|
+
using System.IdentityModel.Tokens.Jwt;
|
|
261
|
+
|
|
262
|
+
var jwks = await httpClient.GetStringAsync("http://auth-service/.well-known/jwks.json");
|
|
263
|
+
var keys = JsonConvert.DeserializeObject<JsonWebKeySet>(jwks);
|
|
264
|
+
|
|
265
|
+
var tokenHandler = new JwtSecurityTokenHandler();
|
|
266
|
+
var validationParameters = new TokenValidationParameters
|
|
267
|
+
{
|
|
268
|
+
ValidateIssuerSigningKey = true,
|
|
269
|
+
IssuerSigningKeys = keys.Keys,
|
|
270
|
+
ValidateIssuer = true,
|
|
271
|
+
ValidIssuer = "horizon-auth",
|
|
272
|
+
ValidateAudience = true,
|
|
273
|
+
ValidAudience = "horizon-api"
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
var principal = tokenHandler.ValidateToken(token, validationParameters, out var validatedToken);
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### Python Example
|
|
280
|
+
|
|
281
|
+
```python
|
|
282
|
+
import jwt
|
|
283
|
+
import requests
|
|
284
|
+
|
|
285
|
+
# Fetch JWKS
|
|
286
|
+
jwks_url = "http://auth-service/.well-known/jwks.json"
|
|
287
|
+
jwks = requests.get(jwks_url).json()
|
|
288
|
+
|
|
289
|
+
# Verify token
|
|
290
|
+
token = "your-jwt-token"
|
|
291
|
+
decoded = jwt.decode(
|
|
292
|
+
token,
|
|
293
|
+
jwks,
|
|
294
|
+
algorithms=["RS256"],
|
|
295
|
+
issuer="horizon-auth",
|
|
296
|
+
audience="horizon-api"
|
|
297
|
+
)
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
## Security Best Practices
|
|
301
|
+
|
|
302
|
+
1. **Always use HTTPS in production**
|
|
303
|
+
2. **Store RSA keys securely** (environment variables, secrets manager)
|
|
304
|
+
3. **Enable rate limiting** to prevent brute force attacks
|
|
305
|
+
4. **Monitor security events** (failed logins, token reuse)
|
|
306
|
+
5. **Rotate JWT keys periodically**
|
|
307
|
+
6. **Use strong Redis passwords** in production
|
|
308
|
+
|
|
309
|
+
## Environment Variables
|
|
310
|
+
|
|
311
|
+
```env
|
|
312
|
+
# Database
|
|
313
|
+
DATABASE_URL=postgresql://user:password@localhost:5432/horizon_auth
|
|
314
|
+
|
|
315
|
+
# Redis
|
|
316
|
+
REDIS_HOST=localhost
|
|
317
|
+
REDIS_PORT=6379
|
|
318
|
+
REDIS_PASSWORD=your_redis_password
|
|
319
|
+
|
|
320
|
+
# Application
|
|
321
|
+
NODE_ENV=production
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
## Troubleshooting
|
|
325
|
+
|
|
326
|
+
### "Invalid or expired access token"
|
|
327
|
+
- Check that your JWT keys are correctly configured
|
|
328
|
+
- Verify token hasn't expired (default 15 minutes)
|
|
329
|
+
- Ensure token isn't blacklisted
|
|
330
|
+
|
|
331
|
+
### "Redis connection error"
|
|
332
|
+
- Verify Redis is running: `docker ps`
|
|
333
|
+
- Check Redis connection settings
|
|
334
|
+
- Test connection: `redis-cli ping`
|
|
335
|
+
|
|
336
|
+
### "Token reuse detected"
|
|
337
|
+
- This is a security feature - someone tried to reuse a revoked refresh token
|
|
338
|
+
- All user tokens have been revoked for security
|
|
339
|
+
- User needs to login again
|
|
340
|
+
|
|
341
|
+
## Migration from Existing Auth
|
|
342
|
+
|
|
343
|
+
See [MIGRATION.md](./MIGRATION.md) for guides on:
|
|
344
|
+
- Migrating from bcrypt to Argon2id
|
|
345
|
+
- Migrating from HS256 to RS256
|
|
346
|
+
- Database schema migration
|
|
347
|
+
|
|
348
|
+
## License
|
|
349
|
+
|
|
350
|
+
MIT
|
|
351
|
+
|
|
352
|
+
## Support
|
|
353
|
+
|
|
354
|
+
- GitHub Issues: https://github.com/OfekItzhaki/horizon-auth-platform/issues
|
|
355
|
+
- Documentation: https://github.com/OfekItzhaki/horizon-auth-platform
|
|
356
|
+
|
|
357
|
+
## Credits
|
|
358
|
+
|
|
359
|
+
Created by Ofek Itzhaki
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Response, Request } from 'express';
|
|
2
|
+
import { AuthService } from './auth.service';
|
|
3
|
+
import { RegisterDto } from './dto/register.dto';
|
|
4
|
+
import { LoginDto } from './dto/login.dto';
|
|
5
|
+
import { RequestPasswordResetDto, ResetPasswordDto, VerifyEmailDto } from './dto/password-reset.dto';
|
|
6
|
+
import { SafeUser } from '../users/users.service';
|
|
7
|
+
export declare class AuthController {
|
|
8
|
+
private readonly authService;
|
|
9
|
+
constructor(authService: AuthService);
|
|
10
|
+
register(registerDto: RegisterDto, response: Response): Promise<{
|
|
11
|
+
user: SafeUser;
|
|
12
|
+
accessToken: string;
|
|
13
|
+
}>;
|
|
14
|
+
login(loginDto: LoginDto, response: Response): Promise<{
|
|
15
|
+
user: SafeUser;
|
|
16
|
+
accessToken: string;
|
|
17
|
+
}>;
|
|
18
|
+
refresh(request: Request, response: Response): Promise<{
|
|
19
|
+
user: SafeUser;
|
|
20
|
+
accessToken: string;
|
|
21
|
+
}>;
|
|
22
|
+
logout(user: SafeUser, response: Response): Promise<{
|
|
23
|
+
message: string;
|
|
24
|
+
}>;
|
|
25
|
+
getProfile(user: SafeUser): Promise<SafeUser>;
|
|
26
|
+
requestPasswordReset(dto: RequestPasswordResetDto): Promise<{
|
|
27
|
+
message: string;
|
|
28
|
+
}>;
|
|
29
|
+
resetPassword(dto: ResetPasswordDto): Promise<{
|
|
30
|
+
message: string;
|
|
31
|
+
}>;
|
|
32
|
+
verifyEmail(dto: VerifyEmailDto): Promise<{
|
|
33
|
+
message: string;
|
|
34
|
+
}>;
|
|
35
|
+
private setRefreshTokenCookie;
|
|
36
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.AuthController = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const throttler_1 = require("@nestjs/throttler");
|
|
18
|
+
const auth_service_1 = require("./auth.service");
|
|
19
|
+
const register_dto_1 = require("./dto/register.dto");
|
|
20
|
+
const login_dto_1 = require("./dto/login.dto");
|
|
21
|
+
const password_reset_dto_1 = require("./dto/password-reset.dto");
|
|
22
|
+
const jwt_auth_guard_1 = require("./guards/jwt-auth.guard");
|
|
23
|
+
const public_decorator_1 = require("../common/decorators/public.decorator");
|
|
24
|
+
const current_user_decorator_1 = require("../common/decorators/current-user.decorator");
|
|
25
|
+
let AuthController = class AuthController {
|
|
26
|
+
constructor(authService) {
|
|
27
|
+
this.authService = authService;
|
|
28
|
+
}
|
|
29
|
+
async register(registerDto, response) {
|
|
30
|
+
const result = await this.authService.register(registerDto.email, registerDto.password, registerDto.fullName, registerDto.tenantId);
|
|
31
|
+
this.setRefreshTokenCookie(response, result.refreshToken);
|
|
32
|
+
return {
|
|
33
|
+
user: result.user,
|
|
34
|
+
accessToken: result.accessToken,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
async login(loginDto, response) {
|
|
38
|
+
const result = await this.authService.login(loginDto.email, loginDto.password);
|
|
39
|
+
this.setRefreshTokenCookie(response, result.refreshToken);
|
|
40
|
+
return {
|
|
41
|
+
user: result.user,
|
|
42
|
+
accessToken: result.accessToken,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
async refresh(request, response) {
|
|
46
|
+
const refreshToken = request.cookies?.refreshToken;
|
|
47
|
+
if (!refreshToken) {
|
|
48
|
+
throw new Error('Refresh token not found');
|
|
49
|
+
}
|
|
50
|
+
const result = await this.authService.refresh(refreshToken);
|
|
51
|
+
this.setRefreshTokenCookie(response, result.refreshToken);
|
|
52
|
+
return {
|
|
53
|
+
user: result.user,
|
|
54
|
+
accessToken: result.accessToken,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
async logout(user, response) {
|
|
58
|
+
await this.authService.logout(user.id);
|
|
59
|
+
response.clearCookie('refreshToken', {
|
|
60
|
+
httpOnly: true,
|
|
61
|
+
secure: process.env.NODE_ENV === 'production',
|
|
62
|
+
sameSite: 'strict',
|
|
63
|
+
});
|
|
64
|
+
return { message: 'Logged out successfully' };
|
|
65
|
+
}
|
|
66
|
+
async getProfile(user) {
|
|
67
|
+
return user;
|
|
68
|
+
}
|
|
69
|
+
async requestPasswordReset(dto) {
|
|
70
|
+
await this.authService.requestPasswordReset(dto.email);
|
|
71
|
+
return { message: 'If the email exists, a reset link will be sent' };
|
|
72
|
+
}
|
|
73
|
+
async resetPassword(dto) {
|
|
74
|
+
await this.authService.resetPassword(dto.token, dto.newPassword);
|
|
75
|
+
return { message: 'Password reset successfully' };
|
|
76
|
+
}
|
|
77
|
+
async verifyEmail(dto) {
|
|
78
|
+
await this.authService.verifyEmail(dto.token);
|
|
79
|
+
return { message: 'Email verified successfully' };
|
|
80
|
+
}
|
|
81
|
+
setRefreshTokenCookie(response, refreshToken) {
|
|
82
|
+
response.cookie('refreshToken', refreshToken, {
|
|
83
|
+
httpOnly: true,
|
|
84
|
+
secure: process.env.NODE_ENV === 'production',
|
|
85
|
+
sameSite: 'strict',
|
|
86
|
+
maxAge: 7 * 24 * 60 * 60 * 1000,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
exports.AuthController = AuthController;
|
|
91
|
+
__decorate([
|
|
92
|
+
(0, public_decorator_1.Public)(),
|
|
93
|
+
(0, throttler_1.Throttle)({ default: { limit: 3, ttl: 60000 } }),
|
|
94
|
+
(0, common_1.Post)('register'),
|
|
95
|
+
(0, common_1.HttpCode)(common_1.HttpStatus.CREATED),
|
|
96
|
+
__param(0, (0, common_1.Body)()),
|
|
97
|
+
__param(1, (0, common_1.Res)({ passthrough: true })),
|
|
98
|
+
__metadata("design:type", Function),
|
|
99
|
+
__metadata("design:paramtypes", [register_dto_1.RegisterDto, Object]),
|
|
100
|
+
__metadata("design:returntype", Promise)
|
|
101
|
+
], AuthController.prototype, "register", null);
|
|
102
|
+
__decorate([
|
|
103
|
+
(0, public_decorator_1.Public)(),
|
|
104
|
+
(0, throttler_1.Throttle)({ default: { limit: 5, ttl: 60000 } }),
|
|
105
|
+
(0, common_1.Post)('login'),
|
|
106
|
+
(0, common_1.HttpCode)(common_1.HttpStatus.OK),
|
|
107
|
+
__param(0, (0, common_1.Body)()),
|
|
108
|
+
__param(1, (0, common_1.Res)({ passthrough: true })),
|
|
109
|
+
__metadata("design:type", Function),
|
|
110
|
+
__metadata("design:paramtypes", [login_dto_1.LoginDto, Object]),
|
|
111
|
+
__metadata("design:returntype", Promise)
|
|
112
|
+
], AuthController.prototype, "login", null);
|
|
113
|
+
__decorate([
|
|
114
|
+
(0, public_decorator_1.Public)(),
|
|
115
|
+
(0, common_1.Post)('refresh'),
|
|
116
|
+
(0, common_1.HttpCode)(common_1.HttpStatus.OK),
|
|
117
|
+
__param(0, (0, common_1.Req)()),
|
|
118
|
+
__param(1, (0, common_1.Res)({ passthrough: true })),
|
|
119
|
+
__metadata("design:type", Function),
|
|
120
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
121
|
+
__metadata("design:returntype", Promise)
|
|
122
|
+
], AuthController.prototype, "refresh", null);
|
|
123
|
+
__decorate([
|
|
124
|
+
(0, common_1.UseGuards)(jwt_auth_guard_1.JwtAuthGuard),
|
|
125
|
+
(0, common_1.Post)('logout'),
|
|
126
|
+
(0, common_1.HttpCode)(common_1.HttpStatus.OK),
|
|
127
|
+
__param(0, (0, current_user_decorator_1.CurrentUser)()),
|
|
128
|
+
__param(1, (0, common_1.Res)({ passthrough: true })),
|
|
129
|
+
__metadata("design:type", Function),
|
|
130
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
131
|
+
__metadata("design:returntype", Promise)
|
|
132
|
+
], AuthController.prototype, "logout", null);
|
|
133
|
+
__decorate([
|
|
134
|
+
(0, common_1.UseGuards)(jwt_auth_guard_1.JwtAuthGuard),
|
|
135
|
+
(0, common_1.Get)('profile'),
|
|
136
|
+
__param(0, (0, current_user_decorator_1.CurrentUser)()),
|
|
137
|
+
__metadata("design:type", Function),
|
|
138
|
+
__metadata("design:paramtypes", [Object]),
|
|
139
|
+
__metadata("design:returntype", Promise)
|
|
140
|
+
], AuthController.prototype, "getProfile", null);
|
|
141
|
+
__decorate([
|
|
142
|
+
(0, public_decorator_1.Public)(),
|
|
143
|
+
(0, throttler_1.Throttle)({ default: { limit: 3, ttl: 3600000 } }),
|
|
144
|
+
(0, common_1.Post)('password-reset/request'),
|
|
145
|
+
(0, common_1.HttpCode)(common_1.HttpStatus.OK),
|
|
146
|
+
__param(0, (0, common_1.Body)()),
|
|
147
|
+
__metadata("design:type", Function),
|
|
148
|
+
__metadata("design:paramtypes", [password_reset_dto_1.RequestPasswordResetDto]),
|
|
149
|
+
__metadata("design:returntype", Promise)
|
|
150
|
+
], AuthController.prototype, "requestPasswordReset", null);
|
|
151
|
+
__decorate([
|
|
152
|
+
(0, public_decorator_1.Public)(),
|
|
153
|
+
(0, common_1.Post)('password-reset/complete'),
|
|
154
|
+
(0, common_1.HttpCode)(common_1.HttpStatus.OK),
|
|
155
|
+
__param(0, (0, common_1.Body)()),
|
|
156
|
+
__metadata("design:type", Function),
|
|
157
|
+
__metadata("design:paramtypes", [password_reset_dto_1.ResetPasswordDto]),
|
|
158
|
+
__metadata("design:returntype", Promise)
|
|
159
|
+
], AuthController.prototype, "resetPassword", null);
|
|
160
|
+
__decorate([
|
|
161
|
+
(0, public_decorator_1.Public)(),
|
|
162
|
+
(0, common_1.Post)('verify-email'),
|
|
163
|
+
(0, common_1.HttpCode)(common_1.HttpStatus.OK),
|
|
164
|
+
__param(0, (0, common_1.Body)()),
|
|
165
|
+
__metadata("design:type", Function),
|
|
166
|
+
__metadata("design:paramtypes", [password_reset_dto_1.VerifyEmailDto]),
|
|
167
|
+
__metadata("design:returntype", Promise)
|
|
168
|
+
], AuthController.prototype, "verifyEmail", null);
|
|
169
|
+
exports.AuthController = AuthController = __decorate([
|
|
170
|
+
(0, common_1.Controller)('auth'),
|
|
171
|
+
__metadata("design:paramtypes", [auth_service_1.AuthService])
|
|
172
|
+
], AuthController);
|
|
173
|
+
//# sourceMappingURL=auth.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.controller.js","sourceRoot":"","sources":["../../src/auth/auth.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAUwB;AACxB,iDAA6C;AAE7C,iDAA6C;AAC7C,qDAAiD;AACjD,+CAA2C;AAC3C,iEAAqG;AACrG,4DAAuD;AACvD,4EAA+D;AAC/D,wFAA0E;AAInE,IAAM,cAAc,GAApB,MAAM,cAAc;IACzB,YAA6B,WAAwB;QAAxB,gBAAW,GAAX,WAAW,CAAa;IAAG,CAAC;IAWnD,AAAN,KAAK,CAAC,QAAQ,CACJ,WAAwB,EACJ,QAAkB;QAE9C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,CAC5C,WAAW,CAAC,KAAK,EACjB,WAAW,CAAC,QAAQ,EACpB,WAAW,CAAC,QAAQ,EACpB,WAAW,CAAC,QAAQ,CACrB,CAAC;QAGF,IAAI,CAAC,qBAA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AAE,CAAA;;;;gDAE9B;AAWK;IAJL,IAAA,yBAAM,GAAE;IACR,IAAA,oBAAQ,EAAC,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC;IACjD,IAAA,aAAI,EAAC,wBAAwB,CAAC;IAC9B,IAAA,iBAAQ,EAAC,mBAAU,CAAC,EAAE,CAAC;IACI,WAAA,IAAA,aAAI,GAAE,CAAA;;qCAAM,4CAAuB;;0DAG9D;AASK;IAHL,IAAA,yBAAM,GAAE;IACR,IAAA,aAAI,EAAC,yBAAyB,CAAC;IAC/B,IAAA,iBAAQ,EAAC,mBAAU,CAAC,EAAE,CAAC;IACH,WAAA,IAAA,aAAI,GAAE,CAAA;;qCAAM,qCAAgB;;mDAGhD;AASK;IAHL,IAAA,yBAAM,GAAE;IACR,IAAA,aAAI,EAAC,cAAc,CAAC;IACpB,IAAA,iBAAQ,EAAC,mBAAU,CAAC,EAAE,CAAC;IACL,WAAA,IAAA,aAAI,GAAE,CAAA;;qCAAM,mCAAc;;iDAG5C;yBAxJU,cAAc;IAD1B,IAAA,mBAAU,EAAC,MAAM,CAAC;qCAEyB,0BAAW;GAD1C,cAAc,CAqK1B"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.AuthModule = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const jwt_1 = require("@nestjs/jwt");
|
|
12
|
+
const passport_1 = require("@nestjs/passport");
|
|
13
|
+
const throttler_1 = require("@nestjs/throttler");
|
|
14
|
+
const auth_service_1 = require("./auth.service");
|
|
15
|
+
const auth_controller_1 = require("./auth.controller");
|
|
16
|
+
const jwks_controller_1 = require("./jwks.controller");
|
|
17
|
+
const password_service_1 = require("./services/password.service");
|
|
18
|
+
const token_service_1 = require("./services/token.service");
|
|
19
|
+
const jwt_strategy_1 = require("./strategies/jwt.strategy");
|
|
20
|
+
const jwt_auth_guard_1 = require("./guards/jwt-auth.guard");
|
|
21
|
+
const roles_guard_1 = require("./guards/roles.guard");
|
|
22
|
+
const users_module_1 = require("../users/users.module");
|
|
23
|
+
const redis_module_1 = require("../redis/redis.module");
|
|
24
|
+
const prisma_module_1 = require("../prisma/prisma.module");
|
|
25
|
+
let AuthModule = class AuthModule {
|
|
26
|
+
};
|
|
27
|
+
exports.AuthModule = AuthModule;
|
|
28
|
+
exports.AuthModule = AuthModule = __decorate([
|
|
29
|
+
(0, common_1.Module)({
|
|
30
|
+
imports: [
|
|
31
|
+
passport_1.PassportModule,
|
|
32
|
+
jwt_1.JwtModule.register({}),
|
|
33
|
+
throttler_1.ThrottlerModule.forRoot([
|
|
34
|
+
{
|
|
35
|
+
ttl: 60000,
|
|
36
|
+
limit: 10,
|
|
37
|
+
},
|
|
38
|
+
]),
|
|
39
|
+
users_module_1.UsersModule,
|
|
40
|
+
redis_module_1.RedisModule,
|
|
41
|
+
prisma_module_1.PrismaModule,
|
|
42
|
+
],
|
|
43
|
+
controllers: [auth_controller_1.AuthController, jwks_controller_1.JwksController],
|
|
44
|
+
providers: [
|
|
45
|
+
auth_service_1.AuthService,
|
|
46
|
+
password_service_1.PasswordService,
|
|
47
|
+
token_service_1.TokenService,
|
|
48
|
+
jwt_strategy_1.JwtStrategy,
|
|
49
|
+
jwt_auth_guard_1.JwtAuthGuard,
|
|
50
|
+
roles_guard_1.RolesGuard,
|
|
51
|
+
],
|
|
52
|
+
exports: [auth_service_1.AuthService, jwt_auth_guard_1.JwtAuthGuard, roles_guard_1.RolesGuard],
|
|
53
|
+
})
|
|
54
|
+
], AuthModule);
|
|
55
|
+
//# sourceMappingURL=auth.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.module.js","sourceRoot":"","sources":["../../src/auth/auth.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,qCAAwC;AACxC,+CAAkD;AAClD,iDAAoD;AACpD,iDAA6C;AAC7C,uDAAmD;AACnD,uDAAmD;AACnD,kEAA8D;AAC9D,4DAAwD;AACxD,4DAAwD;AACxD,4DAAuD;AACvD,sDAAkD;AAClD,wDAAoD;AACpD,wDAAoD;AACpD,2DAAuD;AA2BhD,IAAM,UAAU,GAAhB,MAAM,UAAU;CAAG,CAAA;AAAb,gCAAU;qBAAV,UAAU;IAzBtB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,yBAAc;YACd,eAAS,CAAC,QAAQ,CAAC,EAAE,CAAC;YACtB,2BAAe,CAAC,OAAO,CAAC;gBACtB;oBACE,GAAG,EAAE,KAAK;oBACV,KAAK,EAAE,EAAE;iBACV;aACF,CAAC;YACF,0BAAW;YACX,0BAAW;YACX,4BAAY;SACb;QACD,WAAW,EAAE,CAAC,gCAAc,EAAE,gCAAc,CAAC;QAC7C,SAAS,EAAE;YACT,0BAAW;YACX,kCAAe;YACf,4BAAY;YACZ,0BAAW;YACX,6BAAY;YACZ,wBAAU;SACX;QACD,OAAO,EAAE,CAAC,0BAAW,EAAE,6BAAY,EAAE,wBAAU,CAAC;KACjD,CAAC;GACW,UAAU,CAAG"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { UsersService, SafeUser } from '../users/users.service';
|
|
2
|
+
import { PasswordService } from './services/password.service';
|
|
3
|
+
import { TokenService } from './services/token.service';
|
|
4
|
+
import { RedisService } from '../redis/redis.service';
|
|
5
|
+
import { PrismaService } from '../prisma/prisma.service';
|
|
6
|
+
export interface AuthResult {
|
|
7
|
+
user: SafeUser;
|
|
8
|
+
accessToken: string;
|
|
9
|
+
refreshToken: string;
|
|
10
|
+
}
|
|
11
|
+
export declare class AuthService {
|
|
12
|
+
private readonly usersService;
|
|
13
|
+
private readonly passwordService;
|
|
14
|
+
private readonly tokenService;
|
|
15
|
+
private readonly redisService;
|
|
16
|
+
private readonly prisma;
|
|
17
|
+
constructor(usersService: UsersService, passwordService: PasswordService, tokenService: TokenService, redisService: RedisService, prisma: PrismaService);
|
|
18
|
+
register(email: string, password: string, fullName?: string, tenantId?: string): Promise<AuthResult>;
|
|
19
|
+
login(email: string, password: string): Promise<AuthResult>;
|
|
20
|
+
refresh(refreshToken: string): Promise<AuthResult>;
|
|
21
|
+
logout(userId: string): Promise<void>;
|
|
22
|
+
private revokeAllUserTokens;
|
|
23
|
+
requestPasswordReset(email: string): Promise<void>;
|
|
24
|
+
resetPassword(token: string, newPassword: string): Promise<void>;
|
|
25
|
+
verifyEmail(token: string): Promise<void>;
|
|
26
|
+
}
|