From 178c432164dc96b3de2eb24a3b870f4c0856de04 Mon Sep 17 00:00:00 2001 From: "raoha.rh" Date: Tue, 17 Dec 2024 17:19:12 +0800 Subject: [PATCH] feat: support locally auth --- server/.env.local.example | 1 + server/auth/clients/local.py | 6 +++++- server/main.py | 4 +--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/server/.env.local.example b/server/.env.local.example index 2e2460ab..390407c6 100644 --- a/server/.env.local.example +++ b/server/.env.local.example @@ -26,6 +26,7 @@ X_GITHUB_APPS_CLIENT_SECRET=github_apps_client_secret # OPTIONAL - Local Authorization Configures PETERCAT_LOCAL_UID="petercat|001" PETERCAT_LOCAL_UNAME="petercat" +PETERCAT_LOCAL_GITHUB_TOKEN="github_pat_xxxx" # OPTIONAL - SKIP AUTH0 Authorization PETERCAT_AUTH0_ENABLED=True diff --git a/server/auth/clients/local.py b/server/auth/clients/local.py index f6b2a634..da52f1fc 100644 --- a/server/auth/clients/local.py +++ b/server/auth/clients/local.py @@ -6,6 +6,7 @@ PETERCAT_LOCAL_UID = get_env_variable("PETERCAT_LOCAL_UID") PETERCAT_LOCAL_UNAME = get_env_variable("PETERCAT_LOCAL_UNAME") +PETERCAT_LOCAL_GITHUB_TOKEN = get_env_variable("PETERCAT_LOCAL_GITHUB_TOKEN") WEB_URL = get_env_variable("WEB_URL") WEB_LOGIN_SUCCESS_URL = f"{WEB_URL}/user/login" @@ -21,7 +22,7 @@ async def login(self, request: Request): return RedirectResponse(url=f"{WEB_LOGIN_SUCCESS_URL}", status_code=302) - async def get_user_info(user_id): + async def get_user_info(self, user_id): token = PETERCAT_LOCAL_UID username = PETERCAT_LOCAL_UNAME seed = token[:4] @@ -36,3 +37,6 @@ async def get_user_info(user_id): "agreement_accepted": False, } + + async def get_access_token(self, user_id): + return PETERCAT_LOCAL_GITHUB_TOKEN \ No newline at end of file diff --git a/server/main.py b/server/main.py index 793489de..6089da19 100644 --- a/server/main.py +++ b/server/main.py @@ -71,13 +71,11 @@ def home_page(): @app.get("/api/health_checker") def health_checker(): - supabase_url = get_env_variable("SUPABASE_URL") return { "ENVIRONMENT": ENVIRONMENT, "API_URL": API_URL, "WEB_URL": WEB_URL, - "CALLBACK_URL": CALLBACK_URL, - "supabase_url": supabase_url, + "CALLBACK_URL": CALLBACK_URL }