| 24 | |
| 25 | |
| 26 | class 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 | |
| 45 | def homepage(request: Request) -> JSONResponse: |
no outgoing calls
no test coverage detected