refactor(auth): Use user_id as JWT sub and implement get_user_by_id

Switched from username to user_id as the primary identifier in JWT tokens to better support external authentication providers. Added get_user_by_id to HistoryManager and updated API dependencies and tests to reflect these changes.
This commit is contained in:
Yunxiao Xu
2026-02-11 16:41:27 -08:00
parent ceddacf9cb
commit b23fbce8d0
9 changed files with 31 additions and 15 deletions

View File

@@ -92,10 +92,10 @@ def test_oidc_callback_success():
def test_get_me_success():
"""Test getting current user with a valid token."""
from ea_chatbot.api.utils import create_access_token
token = create_access_token(data={"sub": "test@example.com", "user_id": "123"})
token = create_access_token(data={"sub": "123"})
with patch("ea_chatbot.api.dependencies.history_manager") as mock_hm:
mock_hm.get_user.return_value = User(id="123", username="test@example.com", display_name="Test")
mock_hm.get_user_by_id.return_value = User(id="123", username="test@example.com", display_name="Test")
response = client.get(
"/auth/me",