[feat] solution/backend: 카카오 로그인 — 회원번호로 카톡 채널을 코드 없이 잇는다

★★ 챗봇 웹훅의 user.properties.appUserId 는 카카오 로그인의 회원번호와 **같은 값**이다
(카카오 공식 문서, 봇에 앱키가 물려 있을 때). 그래서 카카오로 로그인만 해 두면 채널에
말을 거는 순간 누구인지 알 수 있고, 6자리 코드 절차가 필요 없어진다.

- external/kakao_identity: 액세스 토큰을 카카오에 되물어 확인한다. ★ 응답의 app_id 를
  우리 앱과 대조하는 것이 구글의 aud 검사에 해당한다 — 이게 없으면 남의 앱 토큰으로
  우리 계정이 된다. 이름·이메일은 동의 항목이라 못 받아도 로그인은 되게 했다
- auth_service.kakao_login: google_login 과 같은 세 갈래. 이메일이 겹쳐도 자동으로
  잇지 않는다(DECISIONS 1 — 계정 선점)
- kakao_link_service.link_by_app_user_id: 자동 매칭. ★ 이미 다른 사장님에게 묶인
  카톡은 빼앗지 않는다 — 조용히 빼앗으면 앞사람이 남의 가게를 보게 된다
- ★ 코드 경로는 그대로 둔다: id/pw·구글 가입자에겐 appUserId 가 없고, 봇에 앱키가
  안 물린 환경에서는 값 자체가 안 온다

★ 함께 고친 것 — services/agent/tools.py 가 사라진 site_payload._DEFAULT_THEME 를
보고 있었다(c690862 템플릿 정의 통합에서 이름이 없어졌는데 이 한 줄만 남았다).
**대화의 섹션 기능이 통째로 죽어 있었고** 웹훅이 AttributeError 를 삼켜 "지금은
처리할 수 없어요" 로만 보였다 — common/template_catalog.industry_of 로 바꿨다.

test_kakao_link·test_kakao_webhook·test_agent_runtime·test_auth 194 passed
(신규 4: 자동 매칭·미가입자·빼앗지 않음·재진입). 남은 1건은 컨테이너에 실제
GOOGLE_CLIENT_ID 가 있어 나는 기존 실패다.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
HyeongBaeYangandClaude Opus 5 committed 2026-09-30 16:27:54 +09:00
1 parent 283970b2ba
commit ca0bea77a7
15 files changed
+373 -16

No files matched your search

+9 -1
View File
@@ -196,7 +196,7 @@ def _other_named(rows: list, current, utterance: str):
return None
async def handle(utterance: str, channel_user_key: str) -> dict:
async def handle(utterance: str, channel_user_key: str, app_user_id: str = '') -> dict:
"""대화 한 턴."""
utterance = (utterance or "").strip()
if not utterance:
@@ -204,6 +204,14 @@ async def handle(utterance: str, channel_user_key: str) -> dict:
row = await _link_row(channel_user_key)
# ★ 카카오 로그인으로 가입한 사장님은 **코드 없이** 이어진다 — appUserId 가 로그인
# 회원번호와 같은 값이라 그 자리에서 알아볼 수 있다(kakao_link_service 주석).
# ★ 코드 경로를 지우지 않는다: id/pw·구글 가입자에게는 이 값이 없고, 봇에 앱키가
# 안 물린 환경에서는 아예 오지 않는다 — 그때 유일한 길이다.
if row is None and app_user_id:
if await link_service.link_by_app_user_id(app_user_id, channel_user_key):
row = await _link_row(channel_user_key)
# ── 아직 연결되지 않은 발화자 ─────────────────────────────────────────
if row is None:
found = CODE_PATTERN.fullmatch(utterance.upper())
+6 -1
View File
@@ -20,6 +20,7 @@ from enum import Enum
from typing import Awaitable, Callable
from common.category_schema.loader import get_schema
from common.template_catalog import industry_of
from common.enums import ErrorType, PlaceCategory, SourceType
from common.models.gmodel import UserInfo
from crud.fact_crud import FactCRUD
@@ -280,7 +281,11 @@ async def _sections_of(ctx: ToolContext) -> tuple[list, dict]:
_fact, site_service = _services()
res = await site_service.get_site(ctx.user, ctx.place_id)
theme = dict((res.site.theme if res.site and res.site.theme else {}) or {})
spec = site_payload._DEFAULT_THEME[PlaceCategory(ctx.place.category).value]["sections"]
# ★ 업종 기본 섹션은 `common/template_catalog` 이 단일 출처다(templates.json).
# 예전 `site_payload._DEFAULT_THEME` 를 보던 자리인데, 템플릿 정의가 한 파일로 모이면서
# 그 이름이 사라졌다 — 여기만 남아 있어 대화의 섹션 기능이 통째로 죽어 있었다
# (실측 2026-09-30: AttributeError 를 웹훅이 삼켜 "지금은 처리할 수 없어요" 로만 보였다).
spec = industry_of(PlaceCategory(ctx.place.category).value)["sections"]
return site_payload._sections(theme.get("sections"), spec), theme