You're tasked with building a secure, modular authentication and organization context API using Golang and tools like Gin, Uber Fx, Redis, and JWT. Your goal is to demonstrate solid backend engineering with dependency injection, token management, and rate limiting.
-
Seed Users/Orgs: Must be created via hardcoded fixtures in code
-
Reference Stack: Golang, Gin, Redis, Uber Fx, JWT, Viper
-
Sample JWT Claims:
{ "user_id": "uuid", "org_id": "uuid", "exp": 1712345678 }
Use the following tools:
- β Golang
- β Gin
- β Uber Fx
- β Redis
- β JWT (access & refresh)
- β bcrypt
- β stretchr/testify (unit testing)
- β Viper (for configuration management)
-
Input:
email,password -
On success:
- Return
access_token(JWT) - Return
refresh_token(JWT or UUID) - Store refresh token in Redis with 7-day TTL
- Return
-
Rate limit: 5 requests/min per IP
-
Input:
refresh_token -
On valid token:
- Issue a new access token
- (Bonus: rotate refresh token)
- Input: refresh token (or in header)
- Deletes refresh token from Redis
- Authenticated route
- Requires valid access token
- Returns:
{
"user": { "id": "uuid", "name": "Sohel" },
"current_org": { "id": "uuid", "name": "Tenbyte" },
"orgs": [
{ "id": "uuid", "name": "Tenbyte" },
{ "id": "uuid", "name": "OpenResty" }
]
}
- Input:
org_id - Authenticated route
- Switches active org for the user
- Save selected org in Redis or use in JWT claims
Seed 2 orgs + 2 users per org:
// Sample Org
{
ID: "uuid-1", Name: "Tenbyte"
}
// Sample User
{
Name: "Sohel",
Email: "[email protected]",
Password: "hashed:123456",
Orgs: [Tenbyte]
}Use in-memory DB or a mock repository layer.
- Access Token: short-lived (e.g., 15 min)
- Refresh Token: long-lived (e.g., 7 days)
- Store refresh tokens in Redis
- JWT claims must include
user_idandorg_id
Write tests for:
- Login
- Refresh token flow
- Logout
- Org switch
- Middleware (auth, rate limit)
Use mocks where needed.
-
Use feature branches:
feature/auth-loginfeature/token-refreshfeature/org-switch
-
Follow conventional commits
-
Push to a public GitHub repo
-
Include:
-
.env.example -
README.mdwith:- Setup instructions
- API examples
- Seed credentials
-
| Area | Expectation |
|---|---|
| Code Quality | Idiomatic, clean, modular |
| Token Handling | Secure JWT with proper expiration and Redis |
| Org Context | Can list and switch orgs securely |
| Rate Limiting | Working with Redis |
| Testing | Clear and meaningful test coverage |
| Docs | Simple to run, clear examples |