From b6c3a0d0fddd9e71934619ec2c2f322629b72f26 Mon Sep 17 00:00:00 2001 From: William Fu-Hinthorn <13333726+hinthornw@users.noreply.github.com> Date: Tue, 17 Dec 2024 11:37:25 -0800 Subject: [PATCH] Update wording --- Makefile | 2 +- docs/docs/cloud/reference/sdk/python_sdk_ref.md | 11 ++++++++++- libs/sdk-py/langgraph_sdk/auth/__init__.py | 15 ++++++++------- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 0d039591e..9bd2847e4 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ serve-clean-docs: clean-docs poetry run python -m mkdocs serve -c -f docs/mkdocs.yml --strict -w ./libs/langgraph serve-docs: build-typedoc - poetry run python -m mkdocs serve -f docs/mkdocs.yml -w ./libs/langgraph -w ./libs/checkpoint --dirty + poetry run python -m mkdocs serve -f docs/mkdocs.yml -w ./libs/langgraph -w ./libs/checkpoint -w ./libs/sdk-py --dirty clean-docs: find ./docs/docs -name "*.ipynb" -type f -delete diff --git a/docs/docs/cloud/reference/sdk/python_sdk_ref.md b/docs/docs/cloud/reference/sdk/python_sdk_ref.md index 1a0d0d4ef..3ffa8b180 100644 --- a/docs/docs/cloud/reference/sdk/python_sdk_ref.md +++ b/docs/docs/cloud/reference/sdk/python_sdk_ref.md @@ -11,7 +11,16 @@ ::: langgraph_sdk.auth handler: python -::: langgraph_sdk.auth.types +::: langgraph_sdk.auth.types.Authenticator + handler: python + +::: langgraph_sdk.auth.types.Handler + handler: python + +::: langgraph_sdk.auth.types.HandlerResult + handler: python + +::: langgraph_sdk.auth.types.FilterType handler: python ::: langgraph_sdk.auth.exceptions diff --git a/libs/sdk-py/langgraph_sdk/auth/__init__.py b/libs/sdk-py/langgraph_sdk/auth/__init__.py index 5b9c8c985..317c89e9f 100644 --- a/libs/sdk-py/langgraph_sdk/auth/__init__.py +++ b/libs/sdk-py/langgraph_sdk/auth/__init__.py @@ -39,10 +39,8 @@ class Auth: Then the LangGraph server will load your auth file and run it server-side whenever a request comes in. - ???+ example "Basic Usage" ```python - # auth.py from langgraph_sdk import Auth my_auth = Auth() @@ -71,14 +69,15 @@ class Auth: async def authorize_thread_create(params: Auth.on.threads.create.value): # Allow the allowed user to create a thread assert params.get("metadata", {}).get("owner") == "allowed_user" + ``` ???+ note "Request Processing Flow" 1. Authentication (your `@auth.authenticate` handler) is performed first on **every request** 2. For authorization, the most specific matching handler is called: - - - If a handler exists for the exact resource and action, it is used - - Otherwise, if a handler exists for the resource with any action, it is used - - Finally, if no specific handlers match, the global handler is used (if any) + * If a handler exists for the exact resource and action, it is used (e.g., `@auth.on.threads.create`) + * Otherwise, if a handler exists for the resource with any action, it is used (e.g., `@auth.on.threads`) + * Finally, if no specific handlers match, the global handler is used (e.g., `@auth.on`) + * If no global handler is set, the request is accepted This allows you to set default behavior with a global handler while overriding specific routes as needed. @@ -572,7 +571,9 @@ class _On: return fn # Used with parameters, return a decorator - def decorator(handler: AHO) -> AHO: + def decorator( + handler: AHO, + ) -> AHO: if isinstance(resources, str): resource_list = [resources] else: