[SDK] Add studio user object

This commit is contained in:
William Fu-Hinthorn
2024-12-18 11:21:13 -08:00
parent e0b4eb6454
commit 60232eadc4
2 changed files with 52 additions and 1 deletions
+51
View File
@@ -176,6 +176,57 @@ class BaseUser(typing.Protocol):
...
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[
+1 -1
View File
@@ -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"