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):