Skip to content

feat: implement JWT token blacklist and refresh token endpoint - #309

Merged
Leothosine merged 2 commits into
tosirano:mainfrom
Ibinola:feature/jwt-blacklist-refresh-token
Jul 21, 2026
Merged

feat: implement JWT token blacklist and refresh token endpoint#309
Leothosine merged 2 commits into
tosirano:mainfrom
Ibinola:feature/jwt-blacklist-refresh-token

Conversation

@Ibinola

@Ibinola Ibinola commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Added jti (JWT ID) claim to access tokens using uuid
  • Created TokenBlacklistService with Redis-backed storage for token revocation
  • Blacklist access token jti on logout with TTL matching remaining token lifetime
  • Updated JwtStrategy to check Redis blacklist before validating tokens
  • Issued long-lived refresh tokens on login and register
  • Added POST /api/auth/refresh endpoint for token rotation
  • Refresh tokens transmitted via httpOnly cookie (not response body)
  • Invalidate refresh token on logout and clear cookie
  • Refresh token validation with revocation support
  • Added moduleNameMapper for src/ path alias in Jest config

Testing

  • npm run build passes
  • npm test passes (10/10 tests)
  • Unit tests cover: token blacklisting, refresh token rotation, revoked token rejection, logout flow

Acceptance Criteria

  • Using a token after logout returns 401
  • POST /api/auth/refresh with a valid refresh token returns a new access token
  • Expired or tampered refresh tokens return 401
  • Refresh token transmitted via httpOnly cookie (not response body)
  • Integration tests cover: login -> logout -> use old token (401); login -> refresh -> use new token (200)

Closes #262

Ibinola and others added 2 commits July 21, 2026 10:27
- Add jti (JWT ID) claim to access tokens using uuid
- Create TokenBlacklistService with Redis-backed storage
- Blacklist access token jti on logout with TTL matching remaining token lifetime
- Update JwtStrategy to check Redis blacklist before validating tokens
- Issue long-lived refresh tokens on login and register
- Add POST /api/auth/refresh endpoint for token rotation
- Transmit refresh tokens via httpOnly cookie (not response body)
- Invalidate refresh token on logout and clear cookie
- Refresh token validation with revocation support
- Add moduleNameMapper for src/ path alias in Jest config
- Add 10 unit tests covering token blacklist and refresh flow

Closes tosirano#262
@Leothosine
Leothosine merged commit d24f38c into tosirano:main Jul 21, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BE-04] Implement JWT token blacklist and refresh token endpoint

2 participants