Backend (FastAPI): - Database migration for spaces, projects, task_statuses, tasks tables - SQLAlchemy models with relationships - Pydantic schemas for CRUD operations - Spaces API: CRUD with soft delete - Projects API: CRUD with auto-created default statuses - Tasks API: CRUD, status change, assign, subtask support - Permission middleware with Security Level filtering - Subtask depth limit (max 2 levels) Frontend (React + Vite): - Layout component with navigation - Spaces list page - Projects list page - Tasks list page with status management Fixes: - auth_client.py: use 'username' field for external API - config.py: extend JWT expiry to 7 days - auth/router.py: sync Redis session with JWT expiry Tests: 36 passed (unit + integration) E2E: All APIs verified with real authentication OpenSpec: add-task-management archived 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
78 lines
2.3 KiB
Python
78 lines
2.3 KiB
Python
import httpx
|
|
from typing import Optional
|
|
from app.core.config import settings
|
|
|
|
|
|
class AuthAPIError(Exception):
|
|
"""Exception raised when external auth API returns an error."""
|
|
def __init__(self, message: str, status_code: int = 400):
|
|
self.message = message
|
|
self.status_code = status_code
|
|
super().__init__(self.message)
|
|
|
|
|
|
class AuthAPIConnectionError(Exception):
|
|
"""Exception raised when unable to connect to auth API."""
|
|
pass
|
|
|
|
|
|
async def verify_credentials(email: str, password: str) -> dict:
|
|
"""
|
|
Verify user credentials against the external auth API.
|
|
|
|
Args:
|
|
email: User's email address
|
|
password: User's password
|
|
|
|
Returns:
|
|
dict: User info from auth API if successful
|
|
|
|
Raises:
|
|
AuthAPIError: If credentials are invalid
|
|
AuthAPIConnectionError: If unable to connect to auth API
|
|
"""
|
|
try:
|
|
async with httpx.AsyncClient(timeout=10.0) as client:
|
|
response = await client.post(
|
|
f"{settings.AUTH_API_URL}/api/auth/login",
|
|
json={"username": email, "password": password},
|
|
)
|
|
|
|
if response.status_code == 200:
|
|
return response.json()
|
|
elif response.status_code == 401:
|
|
raise AuthAPIError("Invalid credentials", 401)
|
|
else:
|
|
raise AuthAPIError(
|
|
f"Authentication failed: {response.text}",
|
|
response.status_code
|
|
)
|
|
except httpx.ConnectError:
|
|
raise AuthAPIConnectionError("Unable to connect to authentication service")
|
|
except httpx.TimeoutException:
|
|
raise AuthAPIConnectionError("Authentication service timeout")
|
|
|
|
|
|
async def validate_token(token: str) -> Optional[dict]:
|
|
"""
|
|
Validate a token with the external auth API.
|
|
|
|
Args:
|
|
token: The auth token to validate
|
|
|
|
Returns:
|
|
dict: Token payload if valid, None if invalid
|
|
"""
|
|
try:
|
|
async with httpx.AsyncClient(timeout=10.0) as client:
|
|
response = await client.get(
|
|
f"{settings.AUTH_API_URL}/api/auth/validate",
|
|
headers={"Authorization": f"Bearer {token}"},
|
|
)
|
|
|
|
if response.status_code == 200:
|
|
return response.json()
|
|
return None
|
|
except (httpx.ConnectError, httpx.TimeoutException):
|
|
return None
|