- Slack OAuth 설치 프로세스 분석 - Event URL 자동 설정 방안 (Manifest API) - slack_workspaces, slack_user_mapping 테이블 구조 현행화 - State 관리 개선 방안 제시
3.0 KiB
3.0 KiB
Slack 봇 설치 URL 및 Event 수신 구조 분석
작성일: 2025-09-02
작성자: 51123 서버 관리자
이슈: Slack 봇 설치 URL 직접 생성 및 Event URL 자동 설정 방안
1. 현황 분석
1.1 구현 완료 항목
- OAuth 엔드포인트:
/auth/slack/passport/install(app/providers/slack.py:387) - 콜백 처리:
/auth/slack/passport/callback(app/providers/slack.py:456) - Event 라우터:
/slack/events/router(app/api/slack_router.py:49) - 환경변수: SLACK_CLIENT_ID, SLACK_CLIENT_SECRET 설정됨
- DB 테이블: slack_workspaces, slack_user_mapping 정상 존재
1.2 문제점
- State 저장: 메모리 딕셔너리(oauth_states) 사용 → 직접 URL 생성 시 검증 실패
- workspace_id: 하드코딩 (app/providers/slack.py:422) → 실제 매핑 구현 필요
- Event URL: 봇 설치와 별개로 Slack App 설정에서 수동 등록 필요
2. 해결 방안
2.1 State 관리 개선
# 현재: 메모리 딕셔너리
oauth_states[state] = {...} # line 436
# 개선: Redis 사용 (이미 구현된 Redis 활용)
await redis_client.setex(f"oauth:state:{state}", 300, json.dumps(state_data))
2.2 Event URL 자동 설정 (Manifest API)
# 필요 환경변수
SLACK_APP_ID = "A..." # Slack App ID
SLACK_APP_CONFIG_TOKEN = "xapp-..." # apps.manifest:write 스코프
# Manifest 업데이트 (봇 설치 콜백 후 1회)
manifest = {
"settings": {
"event_subscriptions": {
"request_url": "https://auth.ro-being.com/slack/events/router",
"bot_events": ["app_mention", "message.channels", "message.groups", "message.im"]
}
}
}
2.3 직접 URL 생성
# OAuth URL 구조
https://slack.com/oauth/v2/authorize?
client_id=9073915808149.9085704341778&
scope=chat:write,channels:read,channels:history,groups:read,groups:history,im:read,im:history,users:read,team:read,files:read,app_mentions:read&
redirect_uri=https://auth.ro-being.com/auth/slack/passport/callback&
state={RANDOM_STATE}
3. 실행 계획
3.1 즉시 적용 가능
- Slack App 설정에서 Event URL 수동 등록 (1회)
- 현재 코드로 봇 설치 진행 가능
3.2 코드 개선 필요
- Redis로 state 저장 로직 변경
- workspace_id 하드코딩 제거
- Manifest API 자동화 스크립트 추가 (선택)
4. 중요 발견사항
4.1 Event URL 관련
- OAuth 설치 ≠ Event URL 설정 (별개 프로세스)
- Manifest API로 자동 업데이트 가능 (apps.manifest.update)
- url_verification 처리 이미 구현됨 (slack_router.py:76)
4.2 아키텍처
- Gateway 불필요: Slack은 team_id로 라우팅 가능
- 단일 Event URL로 모든 워크스페이스 처리
- Interactivity/Slash Commands 없이도 기본 기능 충분
5. 참고사항
- Event URL:
https://auth.ro-being.com/slack/events/router(api 접두사 없음) - DB 스키마: DOCS 문서 업데이트 완료 (tables.md)
- Python 모델: SlackWorkspace의 workspace_id는 실제로 company_id 사용