C.W.K.
Stream
Lesson 05 of 07 · published

프로덕션의 OAuth lifecycle

~12 min · oauth, auth, tokens

Level 0Observer
0 XP0/64 lessons0/13 achievements
0/150 XP to next level150 XP to go0% complete

OAuth는 런타임 concern

Agent SDK가 claude login의 OAuth 토큰에 run 가능 — 개인 앱과 Pro/Max-funded 프로덕션에 완벽. 프로덕션 규율 — 토큰 어디 사는지(macOS의 Keychain, Linux의 파일), refresh 어떻게, expire 시 뭐 일어나, manual intervention 없이 어떻게 recover.

Anthropic API 키는 reserved scaffolding

cwkPippa 자세 — Anthropic API 키 path가 코드로 존재(symmetry, 미래 switching 위해)지만 의도적으로 런타임 path X. Env 값이 running 프로세스에 forbidden — sk-ant-* 패턴이 JSONL 로그에 leak 못 하게. OAuth-only가 청구뿐 아니라 프라이버시 자세.

'OAuth fail' 모양

OAuth 토큰 invalid나 expired면 SDK가 auth 에러 raise. 다뤄 — failure 로그, 운영자 alert, blindly retry X. 토큰 refresh가 인터랙티브(Anthropic 결정), 그래서 프로덕션이 운영자 path 필요 — silent crash loop X.

원칙: OAuth가 편하다 안 편하다 할 때까지. Recovery path 문서화; auth failure를 silent outage로 두지 마.

Code

OAuth failure 감지·surface·python
from claude_agent_sdk import query, ClaudeAgentOptions
from claude_agent_sdk.errors import AuthenticationError

async def try_query(prompt: str):
    try:
        async for ev in query(prompt=prompt, options=ClaudeAgentOptions(cwd="/tmp")):
            yield ev
    except AuthenticationError as e:
        # Blindly retry X — 운영자가 refresh할 때까지 토큰 bad.
        alert_operator(f"Claude OAuth failed: {e}")
        raise
API 키 값 forbid (cwkPippa 자세)·python
import os

if os.environ.get("ANTHROPIC_API_KEY", "").startswith("sk-ant-"):
    # 시작 거부; 값을 running 프로세스 밖.
    raise RuntimeError(
        "ANTHROPIC_API_KEY is set to a real key. Production runs on OAuth only;"
        " remove the env value so the sk-ant- pattern cannot leak into logs."
    )

External links

Exercise

프로덕션 배포에 대해 문서화 — OAuth 토큰 어디 사는지, 누가 refresh 가능, 'Claude auth fail'에 대한 운영자 runbook entry. 세 문장 이내.
Hint
답이 'I do not know'면 그게 작성 기다리는 runbook entry.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.