@dax-crafta/auth 1.3.4 → 1.3.6
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 +175 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# @dax-crafta/auth
|
|
2
|
+
|
|
3
|
+
A powerful, flexible, and secure authentication system for Node.js applications. Built with enterprise-grade security features while maintaining developer-friendly simplicity.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@dax-crafta/auth)
|
|
6
|
+
[](https://github.com/daxp472/dax-crafta/auth/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- 🔐 **Comprehensive Authentication**
|
|
11
|
+
- Email/Password authentication
|
|
12
|
+
- Social login (Google, Facebook, GitHub)
|
|
13
|
+
- JWT-based session management
|
|
14
|
+
- Refresh token rotation
|
|
15
|
+
|
|
16
|
+
- 👥 **Advanced Role-Based Access Control (RBAC)**
|
|
17
|
+
- Custom role creation
|
|
18
|
+
- Granular permissions
|
|
19
|
+
- Resource-based access control
|
|
20
|
+
- Role hierarchy support
|
|
21
|
+
|
|
22
|
+
- 🔒 **Enterprise Security**
|
|
23
|
+
- Multi-factor authentication (MFA/2FA)
|
|
24
|
+
- Password policies and strength validation
|
|
25
|
+
- Account lockout protection
|
|
26
|
+
- Brute force prevention
|
|
27
|
+
|
|
28
|
+
- 📧 **Email Features**
|
|
29
|
+
- Email verification
|
|
30
|
+
- Password reset
|
|
31
|
+
- Login notifications
|
|
32
|
+
- Custom email templates
|
|
33
|
+
|
|
34
|
+
- 📝 **Audit Logging**
|
|
35
|
+
- Detailed activity tracking
|
|
36
|
+
- Security event logging
|
|
37
|
+
- User session monitoring
|
|
38
|
+
|
|
39
|
+
## Quick Start
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npm install @dax-crafta/auth
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
```javascript
|
|
46
|
+
const { crafta } = require('crafta');
|
|
47
|
+
const { auth } = require('@dax-crafta/auth');
|
|
48
|
+
|
|
49
|
+
const app = crafta();
|
|
50
|
+
|
|
51
|
+
// Basic setup
|
|
52
|
+
auth({
|
|
53
|
+
strategy: 'jwt',
|
|
54
|
+
fields: ['email', 'password'],
|
|
55
|
+
emailVerification: true
|
|
56
|
+
})(app);
|
|
57
|
+
|
|
58
|
+
app.listen(3000);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Configuration
|
|
62
|
+
|
|
63
|
+
```javascript
|
|
64
|
+
auth({
|
|
65
|
+
// Authentication Strategy
|
|
66
|
+
strategy: 'jwt',
|
|
67
|
+
|
|
68
|
+
// User Fields
|
|
69
|
+
fields: ['name', 'email', 'password', 'age'],
|
|
70
|
+
|
|
71
|
+
// Routes Configuration
|
|
72
|
+
routes: {
|
|
73
|
+
register: '/register',
|
|
74
|
+
login: '/login',
|
|
75
|
+
verify: '/verify',
|
|
76
|
+
forgotPassword: '/forgot-password',
|
|
77
|
+
resetPassword: '/reset-password',
|
|
78
|
+
refreshToken: '/refresh-token',
|
|
79
|
+
profile: '/profile',
|
|
80
|
+
twoFactor: '/2fa'
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
// Security Settings
|
|
84
|
+
maxLoginAttempts: 5,
|
|
85
|
+
emailVerification: true,
|
|
86
|
+
loginAlerts: true,
|
|
87
|
+
|
|
88
|
+
// Password Policy
|
|
89
|
+
passwordPolicy: {
|
|
90
|
+
minLength: 8,
|
|
91
|
+
requireUppercase: true,
|
|
92
|
+
requireNumbers: true,
|
|
93
|
+
requireSpecialChars: true,
|
|
94
|
+
expiryDays: 90
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
// Email Configuration
|
|
98
|
+
smtp: {
|
|
99
|
+
host: 'smtp.example.com',
|
|
100
|
+
port: 587,
|
|
101
|
+
auth: {
|
|
102
|
+
user: 'your-email@example.com',
|
|
103
|
+
pass: 'your-password'
|
|
104
|
+
},
|
|
105
|
+
from: 'noreply@example.com'
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
// Social Login
|
|
109
|
+
social: {
|
|
110
|
+
google: {
|
|
111
|
+
clientID: 'your-client-id',
|
|
112
|
+
clientSecret: 'your-client-secret',
|
|
113
|
+
callbackURL: 'http://localhost:3000/auth/google/callback'
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
})(app);
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Role-Based Access Control
|
|
120
|
+
|
|
121
|
+
```javascript
|
|
122
|
+
// Create a custom role
|
|
123
|
+
const adminRole = await roleService.createRole({
|
|
124
|
+
name: 'admin',
|
|
125
|
+
permissions: [{
|
|
126
|
+
resource: 'users',
|
|
127
|
+
actions: ['create', 'read', 'update', 'delete']
|
|
128
|
+
}]
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// Check permissions
|
|
132
|
+
const canAccess = await roleService.checkPermission('admin', 'users', 'create');
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Multi-Factor Authentication
|
|
136
|
+
|
|
137
|
+
```javascript
|
|
138
|
+
// Enable 2FA for a user
|
|
139
|
+
const { secret, qrCode } = await mfaService.generateSecret(
|
|
140
|
+
'user@example.com',
|
|
141
|
+
'MyApp'
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
// Verify 2FA token
|
|
145
|
+
const isValid = mfaService.verifyToken(token, secret);
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Audit Logging
|
|
149
|
+
|
|
150
|
+
```javascript
|
|
151
|
+
// Log user activity
|
|
152
|
+
await auditService.logActivity({
|
|
153
|
+
userId: user.id,
|
|
154
|
+
action: 'login',
|
|
155
|
+
ipAddress: req.ip,
|
|
156
|
+
userAgent: req.headers['user-agent'],
|
|
157
|
+
status: 'success'
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
// Get user activity history
|
|
161
|
+
const activities = await auditService.getUserActivity(userId);
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Security Best Practices
|
|
165
|
+
|
|
166
|
+
- Use HTTPS in production
|
|
167
|
+
- Set secure cookie options
|
|
168
|
+
- Configure CORS appropriately
|
|
169
|
+
- Regularly rotate refresh tokens
|
|
170
|
+
- Monitor failed login attempts
|
|
171
|
+
- Implement rate limiting
|
|
172
|
+
|
|
173
|
+
## License
|
|
174
|
+
|
|
175
|
+
MIT © Dax Crafta
|