Update auth docstrings (#2977)

This commit is contained in:
William FH
2025-01-09 16:58:19 -08:00
committed by GitHub
parent e5b5f9510b
commit ecfbfa1b90
3 changed files with 28 additions and 1 deletions
+8 -1
View File
@@ -37,7 +37,7 @@ async def authenticate(authorization: str) -> str:
detail="Invalid token"
)
# Optional: Add authorization rules
# Add authorization rules to actually control access to resources
@my_auth.on
async def add_owner(
ctx: Auth.types.AuthContext,
@@ -48,6 +48,13 @@ async def add_owner(
metadata = value.setdefault("metadata", {})
metadata.update(filters)
return filters
# Assumes you organize information in store like (user_id, resource_type, resource_id)
@my_auth.on.store()
async def authorize_store(ctx: Auth.types.AuthContext, value: dict):
namespace: tuple = value["namespace"]
assert namespace[0] == ctx.user.identity, "Not authorized"
```
## 2. Update configuration
@@ -275,6 +275,13 @@ async def on_assistants(
status_code=403,
detail="User lacks the required permissions.",
)
# Assumes you organize information in store like (user_id, resource_type, resource_id)
@auth.on.store()
async def authorize_store(ctx: Auth.types.AuthContext, value: dict):
# The "namespace" field for each store item is a tuple you can think of as the directory of an item.
namespace: tuple = value["namespace"]
assert namespace[0] == ctx.user.identity, "Not authorized"
```
Notice that instead of one global handler, we now have specific handlers for: