FastAPIPassthroughAuthMiddleware
FastAPI middleware that automatically sets Flyte auth metadata from request headers.
Attributes
| Attribute | Type | Description |
|---|---|---|
| app | FastAPI | The FastAPI application (this is a mandatory framework parameter) |
| header_extractors | list[HeaderExtractor] = [self.extract_authorization_header, self.extract_cookie_header] | List of functions to extract headers from requests |
| excluded_paths | set[str] = set() | Set of URL paths that bypass auth extraction |
Constructor
Signature
def FastAPIPassthroughAuthMiddleware(
app: Any,
header_extractors: list[HeaderExtractor]| None = None,
excluded_paths: set[str]| None = None
) - > None
Parameters
| Name | Type | Description |
|---|---|---|
| app | Any | The FastAPI/Starlette application instance. |
| header_extractors | `list[HeaderExtractor] | None` = None |
| excluded_paths | `set[str] | None` = None |
Signature
def FastAPIPassthroughAuthMiddleware(
app: Any,
header_extractors: list[HeaderExtractor]| None = None,
excluded_paths: set[str]| None = None
)
Parameters
| Name | Type | Description |
|---|---|---|
| app | Any | The FastAPI/Starlette application instance being wrapped by the middleware |
| header_extractors | `list[HeaderExtractor] | None` = None |
| excluded_paths | `set[str] | None` = None |
Methods
dispatch()
@classmethod
def dispatch(
request: Request,
call_next: Callable
) - > Response
Process each request, extracting auth headers and setting Flyte context.
Parameters
| Name | Type | Description |
|---|---|---|
| request | Request | The incoming HTTP request |
| call_next | Callable | The next middleware or route handler to call |
Returns
| Type | Description |
|---|---|
Response | The HTTP response from the handler |
extract_authorization_header()
@classmethod
def extract_authorization_header(
request: Request
) - > tuple[str, str]| None
Extract the Authorization header from the request.
Parameters
| Name | Type | Description |
|---|---|---|
| request | Request | The FastAPI/Starlette request object |
Returns
| Type | Description |
|---|---|
| `tuple[str, str] | None` |
extract_cookie_header()
@classmethod
def extract_cookie_header(
request: Request
) - > tuple[str, str]| None
Extract the Cookie header from the request.
Parameters
| Name | Type | Description |
|---|---|---|
| request | Request | The FastAPI/Starlette request object |
Returns
| Type | Description |
|---|---|
| `tuple[str, str] | None` |
extract_custom_header()
@classmethod
def extract_custom_header(
header_name: str
) - > HeaderExtractor
Create a header extractor for a custom header name.
Parameters
| Name | Type | Description |
|---|---|---|
| header_name | str | The name of the header to extract (case-insensitive) |
Returns
| Type | Description |
|---|---|
HeaderExtractor | A header extractor function that extracts the specified header |