Skip to content

Add JWT authentication system with secure token generation and protected endpoints#22

Closed
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-095bdfab-5b2b-4de5-b564-c334f4ead596
Closed

Add JWT authentication system with secure token generation and protected endpoints#22
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-095bdfab-5b2b-4de5-b564-c334f4ead596

Conversation

Copy link

Copilot AI commented Aug 23, 2025

This PR implements a complete JWT-based authentication system as requested in the issue. The system provides secure token generation and protected endpoint access using industry-standard JWT tokens.

New Features

Authentication Endpoints

  • POST /api/v1/auth/login - Login endpoint that generates JWT tokens

    • Accepts username/password credentials (admin/password123)
    • Returns JWT token with 24-hour expiration
    • Proper error handling for invalid credentials (401 Unauthorized)
  • GET /api/v1/test/protected - Protected test endpoint requiring authentication

    • Requires valid Bearer token in Authorization header
    • Returns user information and timestamp
    • Demonstrates JWT middleware functionality

Security Implementation

  • JWT tokens signed using HS256 algorithm
  • Secure token validation middleware
  • Proper error handling for missing/invalid tokens
  • 24-hour token expiration for security

Example Usage

# Login to get token
curl -X POST http://localhost:3030/api/v1/auth/login \
  -H "Content-Type: application/json" \
  -d '{"username": "admin", "password": "password123"}'

# Use token to access protected endpoint
curl -X GET http://localhost:3030/api/v1/test/protected \
  -H "Authorization: Bearer <jwt_token>"

Technical Details

Dependencies Added

  • jsonwebtoken - JWT token generation and validation
  • chrono - Date/time handling for token expiration

New Components

  • Authentication Models - LoginRequest, TokenResponse, Claims
  • JWT Middleware - Token validation and extraction
  • Auth Controller - Login and protected endpoint handlers
  • Error Handling - Proper 401 responses for authentication failures

Documentation

  • Full OpenAPI/Swagger documentation for all new endpoints
  • Security schemas defined for Bearer token authentication
  • Complete integration test suite (5 new tests covering all scenarios)

Testing

All existing functionality remains unchanged and tested. New comprehensive test coverage includes:

  • Valid credential login
  • Invalid credential rejection
  • Protected endpoint access with valid token
  • Proper 401 responses for missing/invalid tokens
  • End-to-end authentication flow

The implementation follows the existing codebase patterns and maintains the clean architecture with proper separation of concerns.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…points

Co-authored-by: LuigimonSoft <7293391+LuigimonSoft@users.noreply.github.com>
Copilot AI changed the title [WIP] Agrega un endpoint para generar authenticacion el cual entrege un token seguro para poder acceder a un endpoint de prueba Add JWT authentication system with secure token generation and protected endpoints Aug 23, 2025
Copilot AI requested a review from LuigimonSoft August 23, 2025 02:39
@LuigimonSoft LuigimonSoft deleted the copilot/fix-095bdfab-5b2b-4de5-b564-c334f4ead596 branch August 24, 2025 04:14
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.

2 participants