Skip to content

[feature] 웹 로그인 기반 익스텐션 토큰 발급 API 추가 - #103

Merged
hyoinkang merged 5 commits into
mainfrom
feature/extension-token
Sep 1, 2026
Merged

[feature] 웹 로그인 기반 익스텐션 토큰 발급 API 추가#103
hyoinkang merged 5 commits into
mainfrom
feature/extension-token

Conversation

@hyoinkang

@hyoinkang hyoinkang commented Aug 29, 2026

Copy link
Copy Markdown
Collaborator

📌 개요

익스텐션이 웹 로그인 페이지를 거쳐 인증한 뒤, 웹 access token으로 별도의 익스텐션 전용 토큰쌍을 발급받을 수 있는 API를 추가합니다. 웹과 독립된 tokenFamily로 발급되어 한쪽을 로그아웃해도 다른 쪽에는 영향이 없습니다.

✅ 작업 내용 및 변경 사항

  • POST /auth/extension-token 추가 (웹 access token으로 인증)
  • 기존 issueTokens를 재사용해 새 tokenFamily로 발급 → 웹 세션과 독립적으로 회전/폐기
  • Swagger 문서화
  • refresh token에 jti 추가
  • 토큰에 purpose(primary/extension) claim 추가
  • PrimaryAuthGuard 추가

💬 리뷰어에게

리프레시토큰 스키마에 purpose를 추가해서 익스텐션 토큰 발급을 웹/앱 토큰에 대해서만 수행할 수 있도록 제한했습니다

🔗 관련 이슈

없음

🔍 상세 내용

플로우

익스텐션 → 웹 로그인 페이지 이동
→ 웹에서 로그인 완료 (웹 토큰쌍 발급)
→ 웹이 POST /auth/extension-token 호출 (Authorization: 웹 access token)
→ 새 tokenFamily로 별도 토큰쌍 발급
→ 웹이 익스텐션에 두 번째 토큰쌍 전달

로컬 테스트 완료

  • MASTER_ACCESS_TOKEN 인증 우회로 검증
  • POST /auth/extension-token 정상 발급 확인
  • 동일 유저로 연달아 3회 호출 → 각각 다른 tokenFamily로 정상 삽입 (jti 수정 전에는 같은 초에 호출 시 500 재현됨)
  • 발급받은 토큰쌍 중 하나를 /auth/refresh로 회전 → 이미 사용된 토큰 재사용 시 탈취로 감지되어 401, 그 사이 별도 family인 다른 토큰쌍은 영향 없이 정상 회전 (독립성 확인)
  • bun test 159 pass, tsc --noEmit / eslint 클린

@hyoinkang hyoinkang self-assigned this Aug 30, 2026
@hyoinkang
hyoinkang marked this pull request as ready for review August 30, 2026 08:00

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: edfb06410c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/modules/auth/auth.controller.ts Outdated
Comment thread src/modules/auth/auth.controller.ts Outdated
@ApiBearerAuth()
@ApiExtensionToken()
async issueExtensionToken(@CurrentUser() user: AuthUser) {
return this.authService.issueTokens(user.userId)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 탈퇴한 사용자의 토큰 재발급을 차단하세요

withdraw()는 기존 refresh token을 삭제하고 사용자에게 deletedAt만 설정하므로, 탈퇴 직전에 발급된 access token은 기본 15분 동안 계속 JwtAuthGuard를 통과합니다. 이 상태에서 해당 사용자가 이 엔드포인트를 호출하면 issueTokens()가 활성 사용자 여부를 확인하지 않고 새 refresh token을 저장하며, 사용자 행은 soft delete되어 FK도 그대로 유효하므로 탈퇴 후에도 30일짜리 세션을 다시 확보할 수 있습니다. 발급 전에 findActiveById()로 계정 상태를 검증하거나 guard에서 탈퇴 사용자를 거부해야 합니다.

AGENTS.md reference: AGENTS.md:L11-L11

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

탈퇴 반영하면 좋긴 한데 유저가 없어 P2 정도일듯

@ninaxlee ninaxlee left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

굿이에용

Comment thread src/modules/auth/auth.controller.ts Outdated
@ApiBearerAuth()
@ApiExtensionToken()
async issueExtensionToken(@CurrentUser() user: AuthUser) {
return this.authService.issueTokens(user.userId)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

탈퇴 반영하면 좋긴 한데 유저가 없어 P2 정도일듯

Comment thread src/modules/auth/auth.service.ts Outdated

private async issueTokens(
// 웹 세션(access token)으로 인증된 사용자에게 익스텐션 전용 토큰쌍을 새로
// 발급할 때(POST /auth/extension-token)도 컨트롤러에서 직접 호출한다. 새

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread src/modules/auth/auth.controller.ts Outdated
@hyoinkang
hyoinkang merged commit 4390477 into main Sep 1, 2026
1 check passed
@hyoinkang
hyoinkang deleted the feature/extension-token branch September 1, 2026 11:00
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.

3 participants