feat(backend): 로그아웃 + stateful 토큰 검증 (단일 세션 즉시 폐기)

- POST /v1/auth/logout: 저장된 access/refresh 토큰 행 삭제 → 즉시 로그아웃
- /me, refresh 에서 제시된 토큰을 저장된 토큰과 대조(불일치 시 TOKEN_REVOKED=1203)
  → 로그아웃/타기기 재로그인으로 교체된 토큰을 만료 전이라도 차단
- crud get_token 추가, ErrorType.TOKEN_REVOKED(1203) 추가, Res_Logout 프로토콜
- 로그아웃/단일세션 무효화 e2e 테스트 추가 (test_auth.py)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
민헌andClaude Opus 4.8 committed 2026-06-18 11:26:08 +09:00
1 parent 23cb8291bc
commit 698d4e72d4
6 files changed
+148 -13

No files matched your search

+26
View File
@@ -40,6 +40,10 @@ class IUserCRUD(ABC):
async def add_token(self, cdb: AsyncSession, token: supplier_user_tokens) -> ErrorType:
pass
@abstractmethod
async def get_token(self, cdb: AsyncSession, su_id, token_type: int) -> Tuple[ErrorType, str]:
pass
@abstractmethod
async def delete_tokens_by_su_id(self, cdb: AsyncSession, su_id) -> ErrorType:
pass
@@ -136,6 +140,28 @@ class UserCRUD(IUserCRUD):
LOG.e_no_callstack(ex)
return ErrorType.DB_RUN_FAILED
async def get_token(self, cdb: AsyncSession, su_id, token_type: int) -> Tuple[ErrorType, str]:
# 저장된 토큰(jwt 문자열)을 반환한다. stateful 검증(제시 토큰 ↔ 저장 토큰 대조)용.
try:
query = (
select(supplier_user_tokens.token["jwt"].astext)
.where(
supplier_user_tokens.su_id == su_id,
supplier_user_tokens.type == token_type,
supplier_user_tokens.deleted == False, # noqa: E712
)
.limit(1)
)
err_type, row_list = await DB_SESSION_MNG.execute(cdb, query)
if err_type != ErrorType.SUCCESS:
return err_type, None
if len(row_list) != 1:
return ErrorType.DB_INVALID_KEY, None
return ErrorType.SUCCESS, row_list[0]
except Exception as ex:
LOG.e_no_callstack(ex)
return ErrorType.DB_RUN_FAILED, None
async def delete_tokens_by_su_id(self, cdb: AsyncSession, su_id) -> ErrorType:
# 단일 세션: 로그인/로그아웃 시 해당 유저의 토큰 행을 모두 제거한다(하드 삭제, 누적 방지).
try: