From 3ae30f1f7645203a8e8c15bd298d802fffbd2334 Mon Sep 17 00:00:00 2001 From: retoor Date: Fri, 9 May 2025 09:09:33 +0200 Subject: [PATCH] Do it. --- src/snek/sgit.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/snek/sgit.py b/src/snek/sgit.py index 74dc884..64bad65 100644 --- a/src/snek/sgit.py +++ b/src/snek/sgit.py @@ -41,9 +41,25 @@ class GitApplication(web.Application): web.post('/{repo_name}.git/git-receive-pack', self.git_smart_http), ]) + async def check_basic_auth(self, request): - # For now, always return the fixed user and path - return "retoor", pathlib.Path(self.REPO_DIR) + auth_header = request.headers.get("Authorization", "") + if not auth_header.startswith("Basic "): + return None,None + encoded_creds = auth_header.split("Basic ")[1] + decoded_creds = base64.b64decode(encoded_creds).decode() + username, password = decoded_creds.split(":", 1) + request["user"] = await self.parent.services.user.authenticate( + username=username, password=password + ) + if not request["user"]: + return None,None + request["repository_path"] = await self.parent.services.user.get_repository_path( + request["user"]["uid"] + ) + + return request["user"]['username'],request["repository_path"] + @staticmethod def require_auth(handler):