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

Method authenticate

tests/test_authentication.py:27–42  ·  tests/test_authentication.py::BasicAuth.authenticate
(
        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 class="st">"Authorization" not in request.headers:
32 return None
33
34 auth = request.headers[class="st">"Authorization"]
35 try:
36 scheme, credentials = auth.split()
37 decoded = base64.b64decode(credentials).decode(class="st">"ascii")
38 except (ValueError, UnicodeDecodeError, binascii.Error):
39 raise AuthenticationError(class="st">"Invalid basic auth credentials")
40
41 username, _, password = decoded.partition(class="st">":")
42 return AuthCredentials([class="st">"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