From 36623a16da2a2577311c67cb57878c7bc2d73757 Mon Sep 17 00:00:00 2001 From: Robert Brennan Date: Fri, 1 Nov 2024 18:33:29 -0700 Subject: [PATCH] Minor auth fixes (#4699) --- frontend/src/api/open-hands.ts | 10 +++++++--- frontend/src/routes/oauth.github.callback.tsx | 8 -------- frontend/src/services/api.ts | 1 + openhands/server/github.py | 6 ++---- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/frontend/src/api/open-hands.ts b/frontend/src/api/open-hands.ts index 6f004862c2..6981848c7b 100644 --- a/frontend/src/api/open-hands.ts +++ b/frontend/src/api/open-hands.ts @@ -141,9 +141,13 @@ class OpenHands { * @returns Response with authentication status and user info if successful */ static async authenticate(): Promise { - return request(`/api/authenticate`, { - method: "POST", - }); + return request( + `/api/authenticate`, + { + method: "POST", + }, + true, + ); } } diff --git a/frontend/src/routes/oauth.github.callback.tsx b/frontend/src/routes/oauth.github.callback.tsx index 9232d9e222..b5bdca37e9 100644 --- a/frontend/src/routes/oauth.github.callback.tsx +++ b/frontend/src/routes/oauth.github.callback.tsx @@ -15,14 +15,6 @@ export const clientLoader = async ({ request }: ClientLoaderFunctionArgs) => { await OpenHands.getGitHubAccessToken(code); localStorage.setItem("ghToken", accessToken); - const authResponse = await OpenHands.authenticate(); - if (!authResponse.ok) { - localStorage.removeItem("ghToken"); - return json( - { error: "Failed to authenticate with GitHub" }, - { status: authResponse.status }, - ); - } return redirect("/"); } diff --git a/frontend/src/services/api.ts b/frontend/src/services/api.ts index dd67e2daf1..ab6006b6ab 100644 --- a/frontend/src/services/api.ts +++ b/frontend/src/services/api.ts @@ -7,6 +7,7 @@ const UNAUTHED_ROUTE_PREFIXES = [ "/api/authenticate", "/api/options/", "/config.json", + "/api/github/callback", ]; export async function request( diff --git a/openhands/server/github.py b/openhands/server/github.py index 14ef93cfeb..31e88adc90 100644 --- a/openhands/server/github.py +++ b/openhands/server/github.py @@ -76,11 +76,9 @@ class UserVerifier: return False -# Global instance of user verifier -user_verifier = UserVerifier() - - async def authenticate_github_user(auth_token) -> bool: + user_verifier = UserVerifier() + logger.info('Checking GitHub token') if not auth_token: