|
5 | 5 | ### Register |
6 | 6 | - `POST /register` |
7 | 7 | - Request: `{ "email": "[email protected]", "password": "..." }` |
8 | | -- Response: `{ "success": true, "data": { "token": "..." } }` |
| 8 | +- Response: `{ "message": "User registered successfully. Please check your email for verification." }` |
9 | 9 |
|
10 | 10 | ### Login |
11 | 11 | - `POST /login` |
12 | 12 | - Request: `{ "email": "[email protected]", "password": "..." }` |
13 | | -- Response: `{ "success": true, "data": { "token": "..." } }` |
| 13 | +- Response: `{ "access_token": "...", "refresh_token": "..." }` |
| 14 | +- If 2FA enabled: `{ "message": "2FA verification required", "temp_token": "..." }` |
14 | 15 |
|
15 | 16 | ### Logout |
16 | 17 | - `POST /logout` |
17 | 18 | - Header: `Authorization: Bearer <access_token>` |
18 | | -- Request: `{ "refresh_token": "..." }` |
| 19 | +- Request: `{ "refresh_token": "...", "access_token": "..." }` |
19 | 20 | - Response: `{ "message": "Successfully logged out" }` |
20 | 21 |
|
21 | 22 | ### Refresh Token |
22 | 23 | - `POST /refresh-token` |
23 | 24 | - Request: `{ "refresh_token": "..." }` |
24 | | -- Response: `{ "success": true, "data": { "token": "..." } }` |
| 25 | +- Response: `{ "access_token": "...", "refresh_token": "..." }` |
25 | 26 |
|
26 | 27 | ### Forgot Password |
27 | 28 | - `POST /forgot-password` |
28 | 29 | - Request: `{ "email": "[email protected]" }` |
29 | | -- Response: `{ "success": true }` |
| 30 | +- Response: `{ "message": "If an account with that email exists, a password reset link has been sent." }` |
30 | 31 |
|
31 | 32 | ### Reset Password |
32 | 33 | - `POST /reset-password` |
33 | 34 | - Request: `{ "token": "...", "new_password": "..." }` |
34 | | -- Response: `{ "success": true }` |
| 35 | +- Response: `{ "message": "Password has been reset successfully." }` |
35 | 36 |
|
36 | 37 | ### Email Verification |
37 | 38 | - `GET /verify-email?token=...` |
38 | | -- Response: `{ "success": true }` |
39 | | - |
40 | | -### Social Login |
41 | | -- `GET /auth/{provider}/login` |
42 | | -- `GET /auth/{provider}/callback` |
43 | | - |
44 | | -### Protected Profile |
45 | | -- `GET /profile` |
46 | | -- Header: `Authorization: Bearer <token>` |
47 | | -- Response: `{ "success": true, "data": { ...user... } }` |
| 39 | +- Response: `{ "message": "Email verified successfully!" }` |
48 | 40 |
|
49 | 41 | ### Token Validation (for external services) |
50 | 42 | - `GET /auth/validate` |
51 | 43 | - Header: `Authorization: Bearer <token>` |
52 | 44 | - Response: `{ "valid": true, "userID": "uuid", "email": "[email protected]" }` |
53 | 45 |
|
| 46 | +## Social Authentication Endpoints |
| 47 | + |
| 48 | +### Google OAuth2 |
| 49 | +- `GET /auth/google/login` - Initiate Google login |
| 50 | +- `GET /auth/google/callback` - Google callback handler |
| 51 | + |
| 52 | +### Facebook OAuth2 |
| 53 | +- `GET /auth/facebook/login` - Initiate Facebook login |
| 54 | +- `GET /auth/facebook/callback` - Facebook callback handler |
| 55 | + |
| 56 | +### GitHub OAuth2 |
| 57 | +- `GET /auth/github/login` - Initiate GitHub login |
| 58 | +- `GET /auth/github/callback` - GitHub callback handler |
| 59 | + |
| 60 | +## User Profile Endpoints (Protected) |
| 61 | + |
| 62 | +All profile endpoints require JWT authentication via `Authorization: Bearer <token>` header. |
| 63 | + |
| 64 | +### Get Profile |
| 65 | +- `GET /profile` |
| 66 | +- Response: User profile with social accounts |
| 67 | +```json |
| 68 | +{ |
| 69 | + "id": "uuid", |
| 70 | + |
| 71 | + "email_verified": true, |
| 72 | + "name": "John Doe", |
| 73 | + "first_name": "John", |
| 74 | + "last_name": "Doe", |
| 75 | + "profile_picture": "https://...", |
| 76 | + "locale": "en-US", |
| 77 | + "two_fa_enabled": false, |
| 78 | + "created_at": "2023-01-01T00:00:00Z", |
| 79 | + "updated_at": "2023-01-01T00:00:00Z", |
| 80 | + "social_accounts": [...] |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +### Update Profile |
| 85 | +- `PUT /profile` |
| 86 | +- Request (all fields optional): |
| 87 | +```json |
| 88 | +{ |
| 89 | + "name": "John Doe", |
| 90 | + "first_name": "John", |
| 91 | + "last_name": "Doe", |
| 92 | + "profile_picture": "https://example.com/avatar.jpg", |
| 93 | + "locale": "en-US" |
| 94 | +} |
| 95 | +``` |
| 96 | +- Response: Updated user profile (same format as GET /profile) |
| 97 | + |
| 98 | +### Update Email |
| 99 | +- `PUT /profile/email` |
| 100 | +- Request: |
| 101 | +```json |
| 102 | +{ |
| 103 | + |
| 104 | + "password": "currentpassword" |
| 105 | +} |
| 106 | +``` |
| 107 | +- Response: `{ "message": "Email updated successfully. Please check your new email for verification." }` |
| 108 | +- Note: Email verification required for new email address |
| 109 | + |
| 110 | +### Update Password |
| 111 | +- `PUT /profile/password` |
| 112 | +- Request: |
| 113 | +```json |
| 114 | +{ |
| 115 | + "current_password": "oldpassword123", |
| 116 | + "new_password": "newpassword123" |
| 117 | +} |
| 118 | +``` |
| 119 | +- Response: `{ "message": "Password updated successfully. All sessions have been logged out for security." }` |
| 120 | +- Note: All existing tokens will be revoked for security |
| 121 | + |
| 122 | +### Delete Account |
| 123 | +- `DELETE /profile` |
| 124 | +- Request: |
| 125 | +```json |
| 126 | +{ |
| 127 | + "password": "currentpassword", |
| 128 | + "confirm_deletion": true |
| 129 | +} |
| 130 | +``` |
| 131 | +- Response: `{ "message": "Account deleted successfully. We're sorry to see you go." }` |
| 132 | +- Note: This action is permanent and cannot be undone |
| 133 | + |
| 134 | +## Two-Factor Authentication Endpoints (Protected) |
| 135 | + |
| 136 | +### Generate 2FA Setup |
| 137 | +- `POST /2fa/generate` |
| 138 | +- Response: QR code and secret for TOTP setup |
| 139 | + |
| 140 | +### Verify 2FA Setup |
| 141 | +- `POST /2fa/verify-setup` |
| 142 | +- Request: `{ "code": "123456" }` |
| 143 | +- Response: Verification status |
| 144 | + |
| 145 | +### Enable 2FA |
| 146 | +- `POST /2fa/enable` |
| 147 | +- Request: `{ "code": "123456" }` |
| 148 | +- Response: Recovery codes |
| 149 | + |
| 150 | +### Disable 2FA |
| 151 | +- `POST /2fa/disable` |
| 152 | +- Request: `{ "code": "123456" }` |
| 153 | +- Response: `{ "message": "2FA disabled successfully" }` |
| 154 | + |
| 155 | +### Generate New Recovery Codes |
| 156 | +- `POST /2fa/recovery-codes` |
| 157 | +- Request: `{ "code": "123456" }` |
| 158 | +- Response: New recovery codes |
| 159 | + |
| 160 | +## Activity Log Endpoints (Protected) |
| 161 | + |
| 162 | +### Get User Activity Logs |
| 163 | +- `GET /activity-logs` |
| 164 | +- Query parameters: `page`, `limit`, `event_type`, `start_date`, `end_date` |
| 165 | +- Response: Paginated list of user's activity logs |
| 166 | + |
| 167 | +### Get Activity Log by ID |
| 168 | +- `GET /activity-logs/:id` |
| 169 | +- Response: Single activity log entry |
| 170 | + |
| 171 | +### Get Available Event Types |
| 172 | +- `GET /activity-logs/event-types` |
| 173 | +- Response: List of available event types for filtering |
| 174 | + |
| 175 | +## Admin Endpoints (Protected) |
| 176 | + |
| 177 | +### Get All Activity Logs (Admin only) |
| 178 | +- `GET /admin/activity-logs` |
| 179 | +- Query parameters: `page`, `limit`, `user_id`, `event_type`, `start_date`, `end_date` |
| 180 | +- Response: Paginated list of all users' activity logs |
| 181 | + |
| 182 | +--- |
| 183 | + |
| 184 | +## Event Types |
| 185 | + |
| 186 | +The following event types are logged in the activity log system: |
| 187 | + |
| 188 | +- `LOGIN` - User login |
| 189 | +- `LOGOUT` - User logout |
| 190 | +- `REGISTER` - User registration |
| 191 | +- `PASSWORD_CHANGE` - Password changed via profile |
| 192 | +- `PASSWORD_RESET` - Password reset via forgot password flow |
| 193 | +- `EMAIL_VERIFY` - Email verification completed |
| 194 | +- `EMAIL_CHANGE` - Email address changed |
| 195 | +- `2FA_ENABLE` - Two-factor authentication enabled |
| 196 | +- `2FA_DISABLE` - Two-factor authentication disabled |
| 197 | +- `2FA_LOGIN` - Login with 2FA verification |
| 198 | +- `TOKEN_REFRESH` - Access token refreshed |
| 199 | +- `SOCIAL_LOGIN` - Social authentication login |
| 200 | +- `PROFILE_ACCESS` - Profile accessed (GET /profile) |
| 201 | +- `PROFILE_UPDATE` - Profile updated |
| 202 | +- `ACCOUNT_DELETION` - Account deleted |
| 203 | +- `RECOVERY_CODE_USED` - 2FA recovery code used |
| 204 | +- `RECOVERY_CODE_GENERATE` - New recovery codes generated |
| 205 | + |
54 | 206 | --- |
55 | | -For more details, see the OpenAPI spec (if available) or code comments. |
| 207 | + |
| 208 | +For detailed API specifications including request/response schemas and authentication requirements, see the [Swagger documentation](http://localhost:8080/swagger/index.html) when the API is running. |
0 commit comments