authentication¶
- class litestar.middleware.authentication.AbstractAuthenticationMiddleware¶
基类:
ABC抽象的 AuthenticationMiddleware,允许用户通过继承它并重写
AbstractAuthenticationMiddleware.authenticate_request()来创建自定义的 AuthenticationMiddleware。- __init__(app: ASGIApp, exclude: str | list[str] | None = None, exclude_from_auth_key: str = 'exclude_from_auth', exclude_http_methods: Sequence[Method] | None = None, scopes: Scopes | None = None) None¶
初始化
AbstractAuthenticationMiddleware。 Args: app: 一个 ASGIApp,该值是中间件栈中要调用的下一个 ASGI 处理器。 exclude: 一个模式或模式列表,用于在认证中间件中跳过匹配的路由。 exclude_from_auth_key: 用于在路由上禁用特定路由认证的标识符。 exclude_http_methods: 不需要认证的 HTTP 方法序列。 scopes: 由认证中间件处理的 ASGI scopes。
- async __call__(scope: Scope, receive: Receive, send: Send) None¶
ASGI 可调用对象。 Args: scope: ASGI 连接作用域。 receive: ASGI 接收函数。 send: ASGI 发送函数。 Returns: None
- abstractmethod async authenticate_request(connection: ASGIConnection) AuthenticationResult¶
接收 HTTP 连接并返回一个
AuthenticationResult。 Notes: - 此方法必须由子类重写。 Args: connection: 一个ASGIConnection实例。 Raises: NotAuthorizedException | PermissionDeniedException: 如果认证失败。 Returns: 一个AuthenticationResult实例。