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

Class BasicAuth

tests/test_authentication.py:26–42  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24
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 1

Calls

no outgoing calls

Tested by

no test coverage detected