MCPcopy
hub / github.com/encode/starlette / __call__

Method __call__

starlette/middleware/authentication.py:29–48  ·  view source on GitHub ↗
(self, scope: Scope, receive: Receive, send: Send)

Source from the content-addressed store, hash-verified

27 )
28
29 async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
30 if scope["type"] not in ["http", "websocket"]:
31 await self.app(scope, receive, send)
32 return
33
34 conn = HTTPConnection(scope)
35 try:
36 auth_result = await self.backend.authenticate(conn)
37 except AuthenticationError as exc:
38 response = self.on_error(conn, exc)
39 if scope["type"] == "websocket":
40 await send({"type": "websocket.close", "code": 1000})
41 else:
42 await response(scope, receive, send)
43 return
44
45 if auth_result is None:
46 auth_result = AuthCredentials(), UnauthenticatedUser()
47 scope["auth"], scope["user"] = auth_result
48 await self.app(scope, receive, send)
49
50 @staticmethod
51 def default_on_error(conn: HTTPConnection, exc: Exception) -> Response:

Callers

nothing calls this directly

Calls 6

HTTPConnectionClass · 0.90
AuthCredentialsClass · 0.90
UnauthenticatedUserClass · 0.90
sendFunction · 0.50
appMethod · 0.45
authenticateMethod · 0.45

Tested by

no test coverage detected