MCPcopy Index your code
hub / github.com/encode/starlette / authenticate

Method authenticate

tests/test_authentication.py:27–42  ·  view source on GitHub ↗
(
        self,
        request: HTTPConnection,
    )

Source from the content-addressed store, hash-verified

25
26class BasicAuth(AuthenticationBackend):
27 async def authenticate(
28 self,
29 request: HTTPConnection,
30 ) -> tuple[AuthCredentials, SimpleUser] | None:
31 if "Authorization" not in request.headers:
32 return None
33
34 auth = request.headers["Authorization"]
35 try:
36 scheme, credentials = auth.split()
37 decoded = base64.b64decode(credentials).decode("ascii")
38 except (ValueError, UnicodeDecodeError, binascii.Error):
39 raise AuthenticationError("Invalid basic auth credentials")
40
41 username, _, password = decoded.partition(":")
42 return AuthCredentials(["authenticated"]), SimpleUser(username)
43
44
45def homepage(request: Request) -> JSONResponse:

Callers

nothing calls this directly

Calls 4

AuthenticationErrorClass · 0.90
AuthCredentialsClass · 0.90
SimpleUserClass · 0.90
decodeMethod · 0.80

Tested by

no test coverage detected