@ackplus/nest-auth 1.1.15 → 1.1.17
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 +82 -6
- package/package.json +1 -1
- package/src/lib/admin-console/static/index.html +4736 -432
- package/src/lib/auth/auth.module.d.ts.map +1 -1
- package/src/lib/auth/auth.module.js +2 -0
- package/src/lib/auth/controllers/auth.controller.d.ts +1 -0
- package/src/lib/auth/controllers/auth.controller.d.ts.map +1 -1
- package/src/lib/auth/controllers/auth.controller.js +19 -2
- package/src/lib/auth/dto/requests/verify-2fa.request.dto.d.ts +1 -0
- package/src/lib/auth/dto/requests/verify-2fa.request.dto.d.ts.map +1 -1
- package/src/lib/auth/dto/requests/verify-2fa.request.dto.js +8 -0
- package/src/lib/auth/entities/trusted-device.entity.d.ts +13 -0
- package/src/lib/auth/entities/trusted-device.entity.d.ts.map +1 -0
- package/src/lib/auth/entities/trusted-device.entity.js +51 -0
- package/src/lib/auth/index.d.ts +1 -0
- package/src/lib/auth/index.d.ts.map +1 -1
- package/src/lib/auth/index.js +1 -0
- package/src/lib/auth/services/auth.service.d.ts +1 -0
- package/src/lib/auth/services/auth.service.d.ts.map +1 -1
- package/src/lib/auth/services/auth.service.js +30 -1
- package/src/lib/auth/services/mfa.service.d.ts +5 -1
- package/src/lib/auth/services/mfa.service.d.ts.map +1 -1
- package/src/lib/auth/services/mfa.service.js +44 -1
- package/src/lib/auth.constants.d.ts +1 -0
- package/src/lib/auth.constants.d.ts.map +1 -1
- package/src/lib/auth.constants.js +2 -1
- package/src/lib/core/entities.d.ts +2 -1
- package/src/lib/core/entities.d.ts.map +1 -1
- package/src/lib/core/entities.js +2 -0
- package/src/lib/core/interfaces/mfa-options.interface.d.ts +3 -0
- package/src/lib/core/interfaces/mfa-options.interface.d.ts.map +1 -1
- package/src/lib/utils/cookie.helper.d.ts +78 -0
- package/src/lib/utils/cookie.helper.d.ts.map +1 -0
- package/src/lib/utils/cookie.helper.js +115 -0
package/README.md
CHANGED
|
@@ -1,11 +1,87 @@
|
|
|
1
|
-
# nest-auth
|
|
1
|
+
# @ackplus/nest-auth
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A comprehensive authentication and authorization module for NestJS applications, featuring:
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
- **Multi-tenant support** out of the box
|
|
6
|
+
- **Role-Based Access Control (RBAC)**
|
|
7
|
+
- **Session Management** with secure cookie or header-based tokens
|
|
8
|
+
- **Two-Factor Authentication (2FA)** (TOTP, SMS, Email)
|
|
9
|
+
- **Social Login** (Google, Facebook, Apple, GitHub)
|
|
10
|
+
- **Admin Console** UI for managing users and roles
|
|
11
|
+
- **Mobile-ready** API design
|
|
6
12
|
|
|
7
|
-
|
|
13
|
+
## Installation
|
|
8
14
|
|
|
9
|
-
|
|
15
|
+
```bash
|
|
16
|
+
npm install @ackplus/nest-auth
|
|
17
|
+
```
|
|
10
18
|
|
|
11
|
-
|
|
19
|
+
## Configuration
|
|
20
|
+
|
|
21
|
+
Import `NestAuthModule` in your `AppModule`. You can use `forRoot` or `forRootAsync`.
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { NestAuthModule } from '@ackplus/nest-auth';
|
|
25
|
+
|
|
26
|
+
@Module({
|
|
27
|
+
imports: [
|
|
28
|
+
NestAuthModule.forRootAsync({
|
|
29
|
+
useFactory: (configService: ConfigService) => ({
|
|
30
|
+
appName: 'My App',
|
|
31
|
+
jwt: {
|
|
32
|
+
secret: configService.get('JWT_SECRET'),
|
|
33
|
+
accessTokenExpiresIn: '15m',
|
|
34
|
+
refreshTokenExpiresIn: '7d',
|
|
35
|
+
},
|
|
36
|
+
mfa: {
|
|
37
|
+
enabled: true,
|
|
38
|
+
methods: ['totp', 'email'],
|
|
39
|
+
// Trusted device configuration
|
|
40
|
+
trustedDeviceDuration: '30d', // Duration to trust a device
|
|
41
|
+
trustDeviceStorageName: 'nest_auth_device_trust', // Cookie/Header name
|
|
42
|
+
},
|
|
43
|
+
// ... other options
|
|
44
|
+
}),
|
|
45
|
+
inject: [ConfigService],
|
|
46
|
+
}),
|
|
47
|
+
],
|
|
48
|
+
})
|
|
49
|
+
export class AppModule {}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Features
|
|
53
|
+
|
|
54
|
+
### Two-Factor Authentication (2FA)
|
|
55
|
+
|
|
56
|
+
The library supports TOTP (Authenticator apps), SMS, and Email-based 2FA.
|
|
57
|
+
|
|
58
|
+
#### Trusted Devices ("Remember Me")
|
|
59
|
+
|
|
60
|
+
Users can choose to trust their device during 2FA verification to skip 2FA on subsequent logins for a configured duration.
|
|
61
|
+
|
|
62
|
+
**Web Flow (Cookies):**
|
|
63
|
+
1. Login triggers 2FA (`isRequiresMfa: true`).
|
|
64
|
+
2. Call `/auth/verify-2fa` with `rememberDevice: true`.
|
|
65
|
+
3. Server sets a `nest_auth_device_trust` (or configured name) HTTP-only cookie.
|
|
66
|
+
4. Subsequent logins from the same browser will automatically skip 2FA.
|
|
67
|
+
|
|
68
|
+
**Mobile Flow (Headers):**
|
|
69
|
+
1. Login triggers 2FA (`isRequiresMfa: true`).
|
|
70
|
+
2. Call `/auth/verify-2fa` with `rememberDevice: true`.
|
|
71
|
+
3. Response body includes `trustToken`.
|
|
72
|
+
4. Store `trustToken` securely (e.g., Keychain/Keystore).
|
|
73
|
+
5. For subsequent logins, send the token in the request header:
|
|
74
|
+
```
|
|
75
|
+
x-nest-auth-trust-token: <your-trust-token>
|
|
76
|
+
```
|
|
77
|
+
*Note: The header name defaults to `nest_auth_device_trust` or whatever you configured in `trustDeviceStorageName`.*
|
|
78
|
+
|
|
79
|
+
### Admin Console
|
|
80
|
+
|
|
81
|
+
The library includes an embedded Admin Console UI for managing users, roles, and settings.
|
|
82
|
+
Access it at `/auth/admin`.
|
|
83
|
+
|
|
84
|
+
## API Documentation
|
|
85
|
+
|
|
86
|
+
The API documentation is available via Swagger UI at `/api` (if configured in your main application).
|
|
87
|
+
You can also download the OpenAPI specification JSON from the Admin Console or the Swagger UI.
|