Skip to main content
이 가이드는 LangSmith 애플리케이션에 사용자 정의 인증을 추가하는 방법을 보여줍니다. 이 페이지의 단계는 cloudself-hosted 배포 모두에 적용됩니다. 자체 커스텀 서버에서 LangGraph 오픈 소스 라이브러리를 독립적으로 사용하는 경우에는 적용되지 않습니다.

배포에 사용자 정의 인증 추가

배포에서 사용자 정의 인증을 활용하고 사용자 수준 메타데이터에 액세스하려면 사용자 정의 인증 핸들러를 통해 config["configurable"]["langgraph_auth_user"] 객체를 자동으로 채우도록 사용자 정의 인증을 설정하세요. 그런 다음 그래프에서 langgraph_auth_user 키로 이 객체에 액세스하여 에이전트가 사용자를 대신하여 인증된 작업을 수행하도록 할 수 있습니다.
  1. 인증 구현:
    사용자 정의 @auth.authenticate 핸들러가 없으면 LangGraph는 API 키 소유자(일반적으로 개발자)만 인식하므로 요청이 개별 최종 사용자로 범위가 지정되지 않습니다. 사용자 정의 토큰을 전파하려면 자체 핸들러를 구현해야 합니다.
    from langgraph_sdk import Auth
    import requests
    
    auth = Auth()
    
    def is_valid_key(api_key: str) -> bool:
        is_valid = # your API key validation logic
        return is_valid
    
    @auth.authenticate # (1)!
    async def authenticate(headers: dict) -> Auth.types.MinimalUserDict:
        api_key = headers.get(b"x-api-key")
        if not api_key or not is_valid_key(api_key):
            raise Auth.exceptions.HTTPException(status_code=401, detail="Invalid API key")
    
        # Fetch user-specific tokens from your secret store
        user_tokens = await fetch_user_tokens(api_key)
    
        return { # (2)!
            "identity": api_key,  #  fetch user ID from LangSmith
            "github_token" : user_tokens.github_token
            "jira_token" : user_tokens.jira_token
            # ... custom fields/secrets here
        }
    
  • 이 핸들러는 요청(헤더 등)을 수신하고 사용자를 검증한 다음 최소한 identity 필드가 있는 딕셔너리를 반환합니다.
  • 원하는 사용자 정의 필드(예: OAuth 토큰, 역할, 조직 ID 등)를 추가할 수 있습니다.
  1. langgraph.json에서 auth 파일 경로를 추가하세요:
    {
        "dependencies": ["."],
        "graphs": {
        "agent": "./agent.py:graph"
        },
        "env": ".env",
        "auth": {
            "path": "./auth.py:my_auth"
        }
    }
    
  2. 서버에서 인증을 설정한 후에는 선택한 체계에 따라 요청에 필요한 인증 정보를 포함해야 합니다. JWT 토큰 인증을 사용한다고 가정하면 다음 방법 중 하나를 사용하여 배포에 액세스할 수 있습니다:
    • Python Client
    • Python RemoteGraph
    • JavaScript Client
    • JavaScript RemoteGraph
    • CURL
    from langgraph_sdk import get_client
    
    my_token = "your-token" # In practice, you would generate a signed token with your auth provider
    client = get_client(
        url="http://localhost:2024",
        headers={"Authorization": f"Bearer {my_token}"}
    )
    threads = await client.threads.search()
    
    RemoteGraph에 대한 자세한 내용은 Use RemoteGraph 가이드를 참조하세요.

에이전트 인증 활성화

인증 후 플랫폼은 LangSmith 배포에 전달되는 특수 구성 객체(config)를 생성합니다. 이 객체에는 @auth.authenticate 핸들러에서 반환하는 사용자 정의 필드를 포함하여 현재 사용자에 대한 정보가 포함됩니다. 에이전트가 사용자를 대신하여 인증된 작업을 수행할 수 있도록 하려면 그래프에서 langgraph_auth_user 키로 이 객체에 액세스하세요:
def my_node(state, config):
    user_config = config["configurable"].get("langgraph_auth_user")
    # token was resolved during the @auth.authenticate function
    token = user_config.get("github_token","")
    ...
보안 시크릿 저장소에서 사용자 자격 증명을 가져오세요. 그래프 상태에 시크릿을 저장하는 것은 권장되지 않습니다.

Studio에 대한 사용자 권한 부여

기본적으로 리소스에 사용자 정의 권한 부여를 추가하면 Studio에서 수행된 상호작용에도 적용됩니다. 원하는 경우 is_studio_user()를 확인하여 로그인한 Studio 사용자를 다르게 처리할 수 있습니다.
is_studio_user는 langgraph-sdk 버전 0.1.73에 추가되었습니다. 이전 버전을 사용하는 경우 isinstance(ctx.user, StudioUser)를 확인할 수 있습니다.
from langgraph_sdk.auth import is_studio_user, Auth
auth = Auth()

# ... Setup authenticate, etc.

@auth.on
async def add_owner(
    ctx: Auth.types.AuthContext,
    value: dict  # The payload being sent to this access method
) -> dict:  # Returns a filter dict that restricts access to resources
    if is_studio_user(ctx.user):
        return {}

    filters = {"owner": ctx.user.identity}
    metadata = value.setdefault("metadata", {})
    metadata.update(filters)
    return filters
관리형 LangSmith SaaS에 배포된 그래프에 대한 개발자 액세스를 허용하려는 경우에만 이 기능을 사용하세요.

더 알아보기


Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.
I