You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Added a comprehensive activity logging system to track user actions for security auditing and compliance.
- Introduced new endpoints for retrieving user activity logs with pagination and filtering.
- Implemented logging for various user actions including login, logout, registration, password changes, and 2FA events.
- Enhanced API documentation to include new activity log features and updated response formats.
- Created a dedicated service and repository for managing activity logs in the database.
- Updated user and social authentication handlers to log relevant activities.
- Added utility functions to extract client IP and user agent for logging purposes.
Copy file name to clipboardExpand all lines: README.md
+85Lines changed: 85 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,7 @@ A modern, production-ready Go REST API for authentication and authorization, fea
7
7
## 🚀 Features
8
8
- Secure user registration & login (JWT access/refresh tokens)
9
9
-**Two-Factor Authentication (2FA) with TOTP and recovery codes**
10
+
-**User Activity Logs with pagination and filtering**
10
11
- Social login: Google, Facebook, GitHub
11
12
- Email verification & password reset
12
13
- Role-based access control (middleware)
@@ -24,6 +25,7 @@ internal/ # Core logic
24
25
├── user/ # User management
25
26
├── social/ # Social authentication (OAuth2)
26
27
├── twofa/ # Two-Factor Authentication
28
+
├── log/ # Activity logging system
27
29
├── email/ # Email verification & password reset
28
30
├── middleware/ # JWT auth middleware
29
31
├── database/ # Database connection & migrations
@@ -158,6 +160,12 @@ The following `make` commands are available for development, testing, building,
158
160
### User Management
159
161
-`GET /profile` — Get user profile (protected)
160
162
163
+
### Activity Logs
164
+
-`GET /activity-logs` — Get authenticated user's activity logs with pagination and filtering (protected)
165
+
-`GET /activity-logs/:id` — Get specific activity log by ID (protected)
166
+
-`GET /activity-logs/event-types` — Get available event types for filtering (protected)
167
+
-`GET /admin/activity-logs` — Get all users' activity logs for admin use (protected)
168
+
161
169
## 📦 API Response Format
162
170
**Success:**
163
171
```json
@@ -193,6 +201,83 @@ The following `make` commands are available for development, testing, building,
193
201
3. Provider redirects back to callback endpoint
194
202
4. JWT tokens are issued for authenticated user
195
203
204
+
## 📋 Activity Logs
205
+
206
+
### Overview
207
+
The Activity Logs system provides comprehensive tracking of user actions for security auditing, compliance, and debugging purposes. All user activities are automatically logged with detailed context information.
208
+
209
+
### Tracked Events
210
+
The following events are automatically logged:
211
+
-`LOGIN` — User successfully logged in
212
+
-`LOGOUT` — User logged out
213
+
-`REGISTER` — New user registration
214
+
-`PASSWORD_CHANGE` — User changed their password
215
+
-`PASSWORD_RESET` — User reset their password
216
+
-`EMAIL_VERIFY` — User verified their email address
217
+
-`2FA_ENABLE` — User enabled two-factor authentication
218
+
-`2FA_DISABLE` — User disabled two-factor authentication
219
+
-`2FA_LOGIN` — User logged in using 2FA
220
+
-`TOKEN_REFRESH` — User refreshed their access token
221
+
-`SOCIAL_LOGIN` — User logged in via social media (Google, Facebook, GitHub)
222
+
-`PROFILE_ACCESS` — User accessed their profile
223
+
-`RECOVERY_CODE_USED` — User used a 2FA recovery code
224
+
-`RECOVERY_CODE_GEN` — User generated new 2FA recovery codes
225
+
226
+
### Features
227
+
-**Pagination**: Efficient handling of large datasets with configurable page sizes (1-100 items)
228
+
-**Filtering**: Filter by event type, date ranges (YYYY-MM-DD format)
229
+
-**Security**: Users can only access their own logs; admin endpoint for comprehensive access
230
+
-**Performance**: Optimized database queries with proper indexing on UserID, EventType, and Timestamp
231
+
-**Audit Trail**: IP addresses, user agents, and contextual details captured for forensic analysis
232
+
233
+
### API Examples
234
+
235
+
#### Get User's Recent Login Activities
236
+
```bash
237
+
curl -X GET "http://localhost:8080/activity-logs?event_type=LOGIN&limit=5" \
238
+
-H "Authorization: Bearer your-jwt-token"
239
+
```
240
+
241
+
#### Get Activities from Date Range
242
+
```bash
243
+
curl -X GET "http://localhost:8080/activity-logs?start_date=2024-01-01&end_date=2024-01-31&page=1&limit=20" \
244
+
-H "Authorization: Bearer your-jwt-token"
245
+
```
246
+
247
+
#### Get Available Event Types
248
+
```bash
249
+
curl -X GET "http://localhost:8080/activity-logs/event-types" \
0 commit comments