mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-24 06:24:18 +02:00
Support async auth checks (#3152)
Co-authored-by: marvin-context-protocol[bot] <225465937+marvin-context-protocol[bot]@users.noreply.github.com>
This commit is contained in:
parent
25e2f4da32
commit
50b23299f8
21 changed files with 292 additions and 118 deletions
|
|
@ -36,7 +36,7 @@ Example:
|
|||
|
||||
## Functions
|
||||
|
||||
### `require_scopes` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/authorization.py#L77" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
||||
### `require_scopes` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/authorization.py#L78" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
||||
|
||||
```python
|
||||
require_scopes(*scopes: str) -> AuthCheck
|
||||
|
|
@ -52,7 +52,7 @@ in the token (AND logic).
|
|||
- `*scopes`: One or more scope strings that must all be present.
|
||||
|
||||
|
||||
### `restrict_tag` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/authorization.py#L105" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
||||
### `restrict_tag` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/authorization.py#L106" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
||||
|
||||
```python
|
||||
restrict_tag(tag: str) -> AuthCheck
|
||||
|
|
@ -69,7 +69,7 @@ required scopes. If the component doesn't have the tag, access is allowed.
|
|||
- `scopes`: List of scopes required when the tag is present.
|
||||
|
||||
|
||||
### `run_auth_checks` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/authorization.py#L133" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
||||
### `run_auth_checks` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/authorization.py#L134" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
||||
|
||||
```python
|
||||
run_auth_checks(checks: AuthCheck | list[AuthCheck], ctx: AuthContext) -> bool
|
||||
|
|
@ -78,7 +78,8 @@ run_auth_checks(checks: AuthCheck | list[AuthCheck], ctx: AuthContext) -> bool
|
|||
|
||||
Run auth checks with AND logic.
|
||||
|
||||
All checks must pass for authorization to succeed.
|
||||
All checks must pass for authorization to succeed. Checks can be
|
||||
synchronous or asynchronous functions.
|
||||
|
||||
Auth checks can:
|
||||
- Return True to allow access
|
||||
|
|
@ -88,6 +89,7 @@ Auth checks can:
|
|||
|
||||
**Args:**
|
||||
- `checks`: A single check function or list of check functions.
|
||||
Each check can be sync (returns bool) or async (returns Awaitable[bool]).
|
||||
- `ctx`: The auth context to pass to each check.
|
||||
|
||||
**Returns:**
|
||||
|
|
@ -99,7 +101,7 @@ Auth checks can:
|
|||
|
||||
## Classes
|
||||
|
||||
### `AuthContext` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/authorization.py#L47" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
||||
### `AuthContext` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/authorization.py#L48" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
||||
|
||||
|
||||
Context passed to auth check callables.
|
||||
|
|
@ -115,7 +117,7 @@ access to the current authentication token and the component being accessed.
|
|||
|
||||
**Methods:**
|
||||
|
||||
#### `tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/authorization.py#L63" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
||||
#### `tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/authorization.py#L64" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
||||
|
||||
```python
|
||||
tool(self) -> Tool | None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue