Skip to content

Commit c3aaf82

Browse files
committed
feat(auth): add dedicated JWT token validation endpoint
- Implemented a new endpoint `/auth/validate` to validate JWT tokens for external services, returning essential user information. - Introduced a handler method `ValidateToken` in the user handler to manage token validation logic, including Redis blacklist checks. - Updated API documentation to include the new endpoint and its usage details. - Enhanced existing user management documentation to reflect the addition of the token validation feature.
1 parent dbd5cd5 commit c3aaf82

14 files changed

+1370
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ The following `make` commands are available for development, testing, building,
159159

160160
### User Management
161161
- `GET /profile` — Get user profile (protected)
162+
- `GET /auth/validate` — Validate JWT token for external services (protected)
162163

163164
### Activity Logs
164165
- `GET /activity-logs` — Get authenticated user's activity logs with pagination and filtering (protected)

cmd/api/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ func main() {
119119
protected.Use(middleware.AuthMiddleware())
120120
{
121121
protected.GET("/profile", userHandler.GetProfile)
122+
protected.GET("/auth/validate", userHandler.ValidateToken)
122123
protected.POST("/logout", userHandler.Logout)
123124

124125
// 2FA management routes

docker-compose.dev.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ services:
2222
redis:
2323
condition: service_healthy
2424
restart: unless-stopped
25+
networks:
26+
- default
27+
- shared-api-network
2528

2629
volumes:
2730
go_modules:
31+
32+
networks:
33+
shared-api-network:
34+
external: true

docker-compose.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ services:
1818
interval: 10s
1919
timeout: 5s
2020
retries: 5
21+
networks:
22+
- default
23+
- shared-api-network
2124

2225
# Redis Cache
2326
redis:
@@ -32,6 +35,9 @@ services:
3235
interval: 10s
3336
timeout: 5s
3437
retries: 5
38+
networks:
39+
- default
40+
- shared-api-network
3541

3642
# Redis Commander - Web UI for Redis Management
3743
redis-commander:
@@ -47,6 +53,8 @@ services:
4753
depends_on:
4854
- redis
4955
restart: unless-stopped
56+
networks:
57+
- default
5058

5159
# Go Auth API Application
5260
auth-api:
@@ -64,7 +72,14 @@ services:
6472
redis:
6573
condition: service_healthy
6674
restart: unless-stopped
75+
networks:
76+
- default
77+
- shared-api-network
6778

6879
volumes:
6980
postgres_data:
7081
redis_data:
82+
83+
networks:
84+
shared-api-network:
85+
external: true

docs/API.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,10 @@
4646
- Header: `Authorization: Bearer <token>`
4747
- Response: `{ "success": true, "data": { ...user... } }`
4848

49+
### Token Validation (for external services)
50+
- `GET /auth/validate`
51+
- Header: `Authorization: Bearer <token>`
52+
- Response: `{ "valid": true, "userID": "uuid", "email": "[email protected]" }`
53+
4954
---
5055
For more details, see the OpenAPI spec (if available) or code comments.

0 commit comments

Comments
 (0)