유튜브 인증 로직 수정

This commit is contained in:
skkim committed 2026-05-13 15:54:24 +09:00
1 parent ec3e0159e8
commit f47dd423c5
4 files changed
+26 -10

No files matched your search

+17 -5
View File
@@ -59,15 +59,18 @@ class SocialAccountService:
self,
user_uuid: str,
platform: SocialPlatform,
session: AsyncSession,
) -> SocialConnectResponse:
"""
소셜 계정 연동 시작
OAuth 인증 URL을 생성하고 state 토큰을 저장합니다.
기존 연동 계정에 refresh_token이 없으면 동의 화면을 강제 표시합니다.
Args:
user_uuid: 사용자 UUID
platform: 연동할 플랫폼
session: DB 세션
Returns:
SocialConnectResponse: OAuth 인증 URL 및 state 토큰
@@ -77,10 +80,19 @@ class SocialAccountService:
f"user_uuid: {user_uuid}, platform: {platform.value}"
)
# 1. state 토큰 생성 (CSRF 방지)
# 1. 기존 계정의 refresh_token 존재 여부 확인
existing_account = await self.get_account_by_platform(user_uuid, platform, session)
force_consent = not (existing_account and existing_account.refresh_token)
logger.debug(
f"[SOCIAL] OAuth prompt 결정 - force_consent: {force_consent}, "
f"has_account: {existing_account is not None}, "
f"has_refresh_token: {bool(existing_account and existing_account.refresh_token)}"
)
# 2. state 토큰 생성 (CSRF 방지)
state = secrets.token_urlsafe(32)
# 2. state를 Redis에 저장 (user_uuid 포함)
# 3. state를 Redis에 저장 (user_uuid 포함)
state_key = f"{self.STATE_KEY_PREFIX}{state}"
state_data = {
"user_uuid": user_uuid,
@@ -89,13 +101,13 @@ class SocialAccountService:
await redis_client.setex(
state_key,
social_oauth_settings.OAUTH_STATE_TTL_SECONDS,
json.dumps(state_data), # JSON으로 직렬화
json.dumps(state_data),
)
logger.debug(f"[SOCIAL] OAuth state 저장 - key: {state_key}")
# 3. OAuth 클라이언트에서 인증 URL 생성
# 4. OAuth 클라이언트에서 인증 URL 생성
oauth_client = get_oauth_client(platform)
auth_url = oauth_client.get_authorization_url(state)
auth_url = oauth_client.get_authorization_url(state, force_consent=force_consent)
logger.info(f"[SOCIAL] OAuth URL 생성 완료 - platform: {platform.value}")