Quick setup
The authenticate handler
The@auth.authenticate decorator registers your authentication function. It receives the request headers and must return a dictionary with user data.
Required fields
| Field | Type | Description |
|---|---|---|
identity | string | Unique user identifier |
Optional fields
| Field | Type | Default | Description |
|---|---|---|---|
display_name | string | Same as identity | Display name |
permissions | list[str] | [] | Permission strings |
is_authenticated | bool | True | Authentication status |
role, team_id, etc.) are preserved and accessible via ctx.user in authorization handlers and via the User model in custom routes.
Denying access
Raise any exception to deny authentication:Authorization handlers
Authorization handlers give you fine-grained access control for specific resources and actions.Handler types
Handlers can:- Allow — Return
NoneorTrue(default behavior) - Deny — Return
False(returns 403 Forbidden) - Filter — Return a dictionary with filters to apply to queries
- Modify — Modify the
valuedict (e.g., inject metadata)
Resolution priority
Handlers are matched from most specific to least specific:@auth.on.threads.create— Resource + action@auth.on.threads— Resource only@auth.on.*.create— Action only@auth.on— Global fallback
Examples
Restrict deletion to admins:Handler context
Thectx parameter provides:
ctx.user— Authenticated user object (with all fields you returned fromauthenticate)ctx.resource— Resource name ("threads","assistants", etc.)ctx.action— Action name ("create","read","update","delete","search")ctx.permissions— User permissions list
Return values
| Return | Behavior |
|---|---|
None or True | Allow the request |
False | Deny with 403 Forbidden |
dict | Allow with filters (e.g., {"metadata": {"team_id": "123"}}) |
Modified value | Allow with modified request data |
Provider examples
- JWT
- OAuth
- Firebase
Auth on custom routes
Custom routes can use authentication via therequire_auth dependency:
enable_custom_route_auth in your config:
No-auth mode
If no auth is configured, Aegra runs in no-auth mode:- All requests are allowed
- User is set to
anonymous - Authorization handlers are not called
Configuration options
| Option | Type | Default | Description |
|---|---|---|---|
auth.path | string | — | Import path to your auth handler (./file.py:variable) |
auth.disable_studio_auth | bool | false | Disable auth for LangGraph Studio connections |
Non-interruptive design
Authorization handlers are additive by default:- If no auth is configured, requests are allowed
- If no handlers are defined, requests are allowed
- Handlers only restrict access when they explicitly deny