authentication

class litestar.middleware.authentication.AbstractAuthenticationMiddleware[原始碼]

基底類別:ABC

Abstract AuthenticationMiddleware that allows users to create their own AuthenticationMiddleware by extending it and overriding AbstractAuthenticationMiddleware.authenticate_request().

__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[原始碼]

Initialize AbstractAuthenticationMiddleware.

參數:
  • app -- An ASGIApp, this value is the next ASGI handler to call in the middleware stack.

  • exclude -- A pattern or list of patterns to skip in the authentication middleware.

  • exclude_from_auth_key -- An identifier to use on routes to disable authentication for a particular route.

  • exclude_http_methods -- A sequence of http methods that do not require authentication.

  • scopes -- ASGI scopes processed by the authentication middleware.

async __call__(scope: Scope, receive: Receive, send: Send) None[原始碼]

ASGI callable.

參數:
  • scope -- The ASGI connection scope.

  • receive -- ASGI 接收函式。

  • send -- ASGI 發送函式。

回傳:

None

abstractmethod async authenticate_request(connection: ASGIConnection) AuthenticationResult[原始碼]

Receive the http connection and return an AuthenticationResult.

備註

  • This method must be overridden by subclasses.

參數:

connection -- An ASGIConnection instance.

引發:

NotAuthorizedException | PermissionDeniedException -- if authentication fails.

回傳:

An instance of AuthenticationResult.

class litestar.middleware.authentication.AuthenticationResult[原始碼]

基底類別:object

Dataclass for authentication result.

user: Any

The user model, this can be any value corresponding to a user of the API.

auth: Any

The auth value, this can for example be a JWT token.

__init__(user: Any, auth: Any) None