Skip to content

Conversation

@xilucks
Copy link
Member

@xilucks xilucks commented Oct 5, 2025

📋 Summary

카카오/애플 소셜 로그인과 JWT 기반 인증 시스템을 구현했습니다.
사용자 계정 관리, 다중 소셜 계정 연동, 디바이스 기반 로그인을 지원합니다.

🎯 주요 기능

  1. 인증 시스템
  • JWT 토큰 기반 인증
    • Access Token (1시간 유효 - 우선 임시)
    • Refresh Token (7일 유효 - 우선 임시)
  • 토큰 관리 API
    • 토큰 갱신 (POST /api/auth/refresh)
    • 로그아웃 (POST /api/auth/logout)
  1. 소셜 로그인
  • 지원 플랫폼
    • 카카오 (KAKAO)
    • 애플 (APPLE)
  • 신뢰 기반 인증
    • 클라이언트에서 받은 providerId 기반 로그인
    • 기존 계정 자동 로그인 / 신규 회원가입
  • Apple 탈퇴 대응
    • appleAuthCode 저장 (향후 Apple 토큰 취소 API 호출용)
  1. 사용자 관리
  • 프로필 관리
    • 프로필 조회/수정
    • 닉네임, 프로필 이미지 변경
  • 다중 계정 연동
    • 하나의 계정에 여러 소셜 계정 연동 가능
    • 계정 연동/해제
    • 최소 1개 계정 보장 (마지막 계정 해제 방지)
  • 디바이스 로그인
    • OAuth 없이 디바이스 ID만으로 로그인 가능
    • 소셜 로그인 전 임시 계정 생성 시 활용
  1. 회원 탈퇴
  • Soft Delete 방식 (계정 상태를 DELETED로 변경)
  • Apple 계정 탈퇴 시 AuthCode 검증

🏗️ 아키텍처

erDiagram  
    User ||--o{ OAuthAccount : "has"    User ||--o{ DeviceAccount : "has"    User ||--o{ RefreshToken : "has"  
    User {        bigint id PK        varchar nickname        varchar profile_image_url        varchar status        timestamp created_at        timestamp updated_at    }  
    OAuthAccount {        bigint id PK        bigint user_id FK        varchar provider        varchar provider_id        varchar email        varchar apple_auth_code        timestamp created_at        timestamp updated_at    }  
    DeviceAccount {        bigint id PK        bigint user_id FK        varchar device_id        varchar device_type        timestamp created_at        timestamp updated_at    }  
    RefreshToken {        bigint id PK        bigint user_id FK        varchar token        timestamp expires_at        timestamp created_at        timestamp updated_at    }  
Loading

User (사용자)
├── OAuthAccount (소셜 계정) 1:N
├── DeviceAccount (디바이스) 1:N
└── RefreshToken (리프레시 토큰) 1:N

auth/
├── JwtTokenProvider - JWT 토큰 생성/검증
├── JwtAuthenticationFilter - JWT 인증 필터
├── SecurityConfig - Spring Security 설정
├── AuthController - 토큰 관리 API
└── AuthService - 토큰 갱신/로그아웃

user/
├── User, OAuthAccount, DeviceAccount - 도메인 모델
├── RefreshToken - 리프레시 토큰 (User 도메인으로 이동)
├── UserController - 사용자 API
├── UserService - 비즈니스 로직
└── AdminUserController - 관리자 API

📡 API 엔드포인트

인증 API (인증 불필요)

  • POST /api/users/auth/social - 소셜 로그인/회원가입
  • POST /api/users/auth/device - 디바이스 로그인
  • POST /api/auth/refresh - 토큰 갱신
  • POST /api/auth/logout - 로그아웃

사용자 API (인증 필요)

  • GET /api/users/{userId}/profile - 프로필 조회
  • PUT /api/users/{userId}/profile - 프로필 수정
  • POST /api/users/{userId}/oauth/link - 소셜 계정 연동
  • DELETE /api/users/{userId}/oauth/{provider} - 계정 연동 해제
  • DELETE /api/users/{userId} - 회원 탈퇴

관리자 API

  • GET /api/admin/users - 전체 사용자 조회
  • GET /api/admin/users/{userId} - 특정 사용자 상세 조회
  • 기타 통계 및 관리 API

📝 주요 변경사항

  1. 의존성 추가

implementation("org.springframework.boot:spring-boot-starter-security")
implementation("io.jsonwebtoken:jjwt-api:0.12.3")
runtimeOnly("io.jsonwebtoken:jjwt-impl:0.12.3")
runtimeOnly("io.jsonwebtoken:jjwt-jackson:0.12.3")

  1. 환경 변수 설정

jwt:
secret: ${JWT_SECRET}
access-token-expiration: 3600000 # 1시간
refresh-token-expiration: 604800000 # 7일

🧪 테스트 방법
curl 예제

소셜 로그인

curl -X POST http://localhost:8080/api/users/auth/social
-H "Content-Type: application/json"
-d '{
"provider": "KAKAO",
"providerId": "kakao_123",
"nickname": "테스트유저",
"deviceId": "device_001",
"deviceType": "IOS"
}'

프로필 조회

curl -X GET http://localhost:8080/api/users/1/profile
-H "Authorization: Bearer {accessToken}"

🔜 향후 개선 사항

  • OAuth 토큰 검증 (KakaoOAuthClient, AppleOAuthClient 구현)
  • Apple 탈퇴 시 토큰 취소 API 호출

@xilucks xilucks requested a review from jun108059 October 5, 2025 21:00
@xilucks xilucks self-assigned this Oct 5, 2025
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.

1 participant