[Sprint 02] feat: Implement HTTP authentication middleware #13

Closed
opened 2026-02-03 21:01:18 +00:00 by lmiranda · 1 comment
Owner

Summary

Create auth.py module to implement optional HTTP endpoint authentication.

Tasks

  • Create src/gitea_mcp_remote/auth.py
  • Implement AuthMiddleware class for HTTP auth
  • Support Bearer token authentication via Authorization header
  • Read expected token from config.AUTH_TOKEN
  • If AUTH_TOKEN not set, allow all requests (no auth)
  • If set, require matching Authorization: Bearer <token> header
  • Return 401 Unauthorized for invalid/missing token
  • Add logging for auth attempts (success/failure)

Acceptance Criteria

  • auth.py exists with AuthMiddleware class
  • Bearer token validation works correctly
  • No-auth mode works when AUTH_TOKEN unset
  • Clear error messages for auth failures
  • Logging captures auth events
  • Compatible with MCP HTTP transport spec

Dependencies

Blocked by: #11 (needs config to read AUTH_TOKEN)

Context

Optional security layer for the HTTP endpoint. If deploying publicly, set AUTH_TOKEN to require authentication.

References:

  • Corrective Rebuild specification
  • Step 6 of 14-step rebuild plan

Size: M (2-4 hours)

## Summary Create `auth.py` module to implement optional HTTP endpoint authentication. ## Tasks - [ ] Create `src/gitea_mcp_remote/auth.py` - [ ] Implement `AuthMiddleware` class for HTTP auth - [ ] Support Bearer token authentication via `Authorization` header - [ ] Read expected token from `config.AUTH_TOKEN` - [ ] If `AUTH_TOKEN` not set, allow all requests (no auth) - [ ] If set, require matching `Authorization: Bearer <token>` header - [ ] Return 401 Unauthorized for invalid/missing token - [ ] Add logging for auth attempts (success/failure) ## Acceptance Criteria - `auth.py` exists with `AuthMiddleware` class - Bearer token validation works correctly - No-auth mode works when `AUTH_TOKEN` unset - Clear error messages for auth failures - Logging captures auth events - Compatible with MCP HTTP transport spec ## Dependencies **Blocked by:** #11 (needs config to read AUTH_TOKEN) ## Context Optional security layer for the HTTP endpoint. If deploying publicly, set AUTH_TOKEN to require authentication. **References:** - Corrective Rebuild specification - Step 6 of 14-step rebuild plan **Size:** M (2-4 hours)
lmiranda added this to the Sprint 02: Corrective Rebuild milestone 2026-02-03 21:01:18 +00:00
lmiranda added the Size/MType/FeatureTech/PythonComponent/BackendPriority/High labels 2026-02-03 21:01:18 +00:00
Author
Owner

⚠️ Blocked By: #11

⚠️ **Blocked By:** #11
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: personal-projects/gitea-mcp-remote#13