Skip to content

Commit

Permalink
[SDK] Add studio user object (#2813)
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw authored Dec 18, 2024
2 parents a6f0c66 + 77fba7a commit 09a6450
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
51 changes: 51 additions & 0 deletions libs/sdk-py/langgraph_sdk/auth/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,57 @@ def permissions(self) -> Sequence[str]:
...


class StudioUser:
"""A user object that's populated from authenticated requests from the LangGraph studio.
Note: Studio auth can be disabled in your `langgraph.json` config.
```json
{
"auth": {
"disable_studio_auth": true
}
}
```
You can use `isinstance` checks in your authorization handlers (`@auth.on`) to control access specifically
for developers accessing the instance from the LangGraph Studio UI.
???+ example "Examples"
```python
@auth.on
async def allow_developers(ctx: Auth.types.AuthContext, value: Any) -> None:
if isinstance(ctx.user, Auth.types.StudioUser):
return None
...
return False
```
"""

__slots__ = ("username", "_is_authenticated", "_permissions")

def __init__(self, username: str, is_authenticated: bool = False) -> None:
self.username = username
self._is_authenticated = is_authenticated
self._permissions = ["authenticated"] if is_authenticated else []

@property
def is_authenticated(self) -> bool:
return self._is_authenticated

@property
def display_name(self) -> str:
return self.username

@property
def identity(self) -> str:
return self.username

@property
def permissions(self) -> Sequence[str]:
return self._permissions


Authenticator = Callable[
...,
Awaitable[
Expand Down
2 changes: 1 addition & 1 deletion libs/sdk-py/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "langgraph-sdk"
version = "0.1.47"
version = "0.1.48"
description = "SDK for interacting with LangGraph API"
authors = []
license = "MIT"
Expand Down

0 comments on commit 09a6450

Please sign in to comment.