Dependencies¶
fastauth.api.deps.require_auth
async
¶
FastAPI dependency that enforces authentication.
Reads the access token from the Authorization: Bearer header or the
configured access-token cookie (FastAuthConfig.cookie_name_access).
Returns the current user record on success.
Example
Raises:
| Type | Description |
|---|---|
HTTPException(401)
|
If no valid access token is present or the token is expired / malformed. |
fastauth.api.deps.require_role
¶
Return a FastAPI dependency that enforces a specific RBAC role.
The requesting user must be authenticated and have role_name assigned.
RBAC must be configured — i.e. role_adapter must be set on the
:class:~fastauth.app.FastAuth instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
role_name
|
str
|
The role the user must hold (e.g. |
required |
Example
Raises:
| Type | Description |
|---|---|
HTTPException(401)
|
If the user is not authenticated. |
HTTPException(403)
|
If the user does not hold role_name. |
HTTPException(500)
|
If RBAC is not configured on the FastAuth instance. |
fastauth.api.deps.require_permission
¶
Return a FastAPI dependency that enforces a specific RBAC permission.
Checks that the authenticated user holds at least one role that includes
permission. RBAC must be configured on the
:class:~fastauth.app.FastAuth instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
permission
|
str
|
The permission string to check (e.g. |
required |
Example
Raises:
| Type | Description |
|---|---|
HTTPException(401)
|
If the user is not authenticated. |
HTTPException(403)
|
If the user lacks permission. |
HTTPException(500)
|
If RBAC is not configured on the FastAuth instance. |