Skip to content

🙌 OpenHands: AI-Driven Development

Change client name and add IDP hint (#7787)

chuckbutkus78e3f82de14e
diff --git a/frontend/__tests__/components/features/auth-modal.test.tsx b/frontend/__tests__/components/features/auth-modal.test.tsx
index 197dcf8fab..9a4d092ae8 100644
--- a/frontend/__tests__/components/features/auth-modal.test.tsx
+++ b/frontend/__tests__/components/features/auth-modal.test.tsx
@@ -3,34 +3,46 @@ import { it, describe, expect, vi, beforeAll, afterAll } from "vitest";
import userEvent from "@testing-library/user-event";
import { AuthModal } from "#/components/features/waitlist/auth-modal";
import * as CaptureConsent from "#/utils/handle-capture-consent";
+import * as AuthHook from "#/context/auth-context";
describe("AuthModal", () => {
beforeAll(() => {
vi.stubGlobal("location", { href: "" });
+ vi.spyOn(AuthHook, "useAuth").mockReturnValue({
+ providersAreSet: false,
+ setProvidersAreSet: vi.fn(),
+ providerTokensSet: [],
+ setProviderTokensSet: vi.fn()
+ });
});
afterAll(() => {
vi.unstubAllGlobals();
+ vi.restoreAllMocks();
});
it("should render a tos checkbox that is unchecked by default", () => {
- render(<AuthModal githubAuthUrl={null} />);
+ render(<AuthModal githubAuthUrl={null} appMode="saas" />);
const checkbox = screen.getByRole("checkbox");
expect(checkbox).not.toBeChecked();
});
- it("should only enable the GitHub button if the tos checkbox is checked", async () => {
+ it("should only enable the identity provider buttons if the tos checkbox is checked", async () => {
const user = userEvent.setup();
- render(<AuthModal githubAuthUrl={null} />);
+ render(<AuthModal githubAuthUrl={null} appMode="saas" />);
+
const checkbox = screen.getByRole("checkbox");
- const button = screen.getByRole("button", { name: "GITHUB$CONNECT_TO_GITHUB" });
+ const githubButton = screen.getByRole("button", { name: "GITHUB$CONNECT_TO_GITHUB" });
+ const gitlabButton = screen.getByRole("button", { name: "GITLAB$CONNECT_TO_GITLAB" });
- expect(button).toBeDisabled();
+ expect(githubButton).toBeDisabled();
+ expect(gitlabButton).toBeDisabled();
await user.click(checkbox);
- expect(button).not.toBeDisabled();
+ expect(githubButton).not.toBeDisabled();
+ expect(gitlabButton).not.toBeDisabled();
});
it("should set user analytics consent to true when the user checks the tos checkbox", async () => {
@@ -40,7 +52,7 @@ describe("AuthModal", () => {
);
const user = userEvent.setup();
- render(<AuthModal githubAuthUrl="mock-url" />);
+ render(<AuthModal githubAuthUrl="mock-url" appMode="saas" />);
const checkbox = screen.getByRole("checkbox");
await user.click(checkbox);
@@ -50,4 +62,4 @@ describe("AuthModal", () => {
expect(handleCaptureConsentSpy).toHaveBeenCalledWith(true);
});
-});
+});
\ No newline at end of file
diff --git a/frontend/src/assets/branding/gitlab-logo.svg b/frontend/src/assets/branding/gitlab-logo.svg
new file mode 100644
index 0000000000..bfe9f3a56f
--- /dev/null
+++ b/frontend/src/assets/branding/gitlab-logo.svg
@@ -0,0 +1,6 @@
+<svg width="22" height="22" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
+ <path d="M11 21L16.5 8H5.5L11 21Z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
+ <path d="M1 8L3.5 15.5L11 21L18.5 15.5L21 8" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
+ <path d="M1 8L5.5 8L8.25 1" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
+ <path d="M21 8L16.5 8L13.75 1" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
+</svg>
\ No newline at end of file
diff --git a/frontend/src/components/features/waitlist/auth-modal.tsx b/frontend/src/components/features/waitlist/auth-modal.tsx
index dc84693fde..29b04cd086 100644
--- a/frontend/src/components/features/waitlist/auth-modal.tsx
+++ b/frontend/src/components/features/waitlist/auth-modal.tsx
@@ -8,15 +8,24 @@ import { TOSCheckbox } from "./tos-checkbox";
import { handleCaptureConsent } from "#/utils/handle-capture-consent";
import { BrandButton } from "../settings/brand-button";
import GitHubLogo from "#/assets/branding/github-logo.svg?react";
+import GitLabLogo from "#/assets/branding/gitlab-logo.svg?react";
+import { useAuthUrl } from "#/hooks/use-auth-url";
+import { GetConfigResponse } from "#/api/open-hands.types";
interface AuthModalProps {
githubAuthUrl: string | null;
+ appMode?: GetConfigResponse["APP_MODE"] | null;
}
-export function AuthModal({ githubAuthUrl }: AuthModalProps) {
+export function AuthModal({ githubAuthUrl, appMode }: AuthModalProps) {
const { t } = useTranslation();
const [isTosAccepted, setIsTosAccepted] = React.useState(false);
+ const gitlabAuthUrl = useAuthUrl({
+ appMode: appMode || null,
+ identityProvider: "gitlab",
+ });
+
const handleGitHubAuth = () => {
if (githubAuthUrl) {
handleCaptureConsent(true);
@@ -24,28 +33,48 @@ export function AuthModal({ githubAuthUrl }: AuthModalProps) {
}
};
+ const handleGitLabAuth = () => {
+ if (gitlabAuthUrl) {
+ handleCaptureConsent(true);
+ window.location.href = gitlabAuthUrl;
+ }
+ };
+
return (
<ModalBackdrop>
<ModalBody className="border border-tertiary">
<AllHandsLogo width={68} height={46} />
<div className="flex flex-col gap-2 w-full items-center text-center">
<h1 className="text-2xl font-bold">
- {t(I18nKey.AUTH$SIGN_IN_WITH_GITHUB)}
+ {t(I18nKey.AUTH$SIGN_IN_WITH_IDENTITY_PROVIDER)}
</h1>
</div>
<TOSCheckbox onChange={() => setIsTosAccepted((prev) => !prev)} />
- <BrandButton
- isDisabled={!isTosAccepted}
- type="button"
- variant="primary"
- onClick={handleGitHubAuth}
- className="w-full"
- startContent={<GitHubLogo width={20} height={20} />}
- >
- {t(I18nKey.GITHUB$CONNECT_TO_GITHUB)}
- </BrandButton>
+ <div className="flex flex-col gap-3 w-full">
+ <BrandButton
+ isDisabled={!isTosAccepted}
+ type="button"
+ variant="primary"
+ onClick={handleGitHubAuth}
+ className="w-full"
+ startContent={<GitHubLogo width={20} height={20} />}
+ >
+ {t(I18nKey.GITHUB$CONNECT_TO_GITHUB)}
+ </BrandButton>
+
+ <BrandButton
+ isDisabled={!isTosAccepted}
+ type="button"
+ variant="primary"
+ onClick={handleGitLabAuth}
+ className="w-full"
+ startContent={<GitLabLogo width={20} height={20} />}
+ >
+ {t(I18nKey.GITLAB$CONNECT_TO_GITLAB)}
+ </BrandButton>
+ </div>
</ModalBody>
</ModalBackdrop>
);
diff --git a/frontend/src/hooks/mutation/use-logout.ts b/frontend/src/hooks/mutation/use-logout.ts
index 0e08f83277..b41c784cd9 100644
--- a/frontend/src/hooks/mutation/use-logout.ts
+++ b/frontend/src/hooks/mutation/use-logout.ts
@@ -1,4 +1,5 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
+import { useNavigate } from "react-router";
import OpenHands from "#/api/open-hands";
import { useAuth } from "#/context/auth-context";
import { useConfig } from "../query/use-config";
@@ -7,6 +8,7 @@ export const useLogout = () => {
const { setProviderTokensSet, setProvidersAreSet } = useAuth();
const queryClient = useQueryClient();
const { data: config } = useConfig();
+ const navigate = useNavigate();
return useMutation({
mutationFn: async () => {
@@ -22,6 +24,10 @@ export const useLogout = () => {
// Update token state - this will trigger a settings refetch since it's part of the query key
setProviderTokensSet([]);
setProvidersAreSet(false);
+
+ // Navigate to root page and refresh the page
+ navigate("/");
+ window.location.reload();
},
});
};
diff --git a/frontend/src/hooks/use-auth-url.ts b/frontend/src/hooks/use-auth-url.ts
new file mode 100644
index 0000000000..a14218c023
--- /dev/null
+++ b/frontend/src/hooks/use-auth-url.ts
@@ -0,0 +1,29 @@
+import React from "react";
+import { generateAuthUrl } from "#/utils/generate-auth-url";
+import { GetConfigResponse } from "#/api/open-hands.types";
+import { useAuth } from "#/context/auth-context";
+
+interface UseAuthUrlConfig {
+ appMode: GetConfigResponse["APP_MODE"] | null;
+ identityProvider: string;
+}
+
+export const useAuthUrl = (config: UseAuthUrlConfig) => {
+ const { providersAreSet } = useAuth();
+
+ return React.useMemo(() => {
+ if (config.appMode === "saas" && !providersAreSet) {
+ try {
+ return generateAuthUrl(
+ config.identityProvider,
+ new URL(window.location.href),
+ );
+ } catch (e) {
+ // In test environment, window.location.href might not be a valid URL
+ return null;
+ }
+ }
+
+ return null;
+ }, [providersAreSet, config.appMode, config.identityProvider]);
+};
diff --git a/frontend/src/hooks/use-github-auth-url.ts b/frontend/src/hooks/use-github-auth-url.ts
index c4d7ae8d30..8547240df5 100644
--- a/frontend/src/hooks/use-github-auth-url.ts
+++ b/frontend/src/hooks/use-github-auth-url.ts
@@ -1,23 +1,13 @@
-import React from "react";
-import { generateGitHubAuthUrl } from "#/utils/generate-github-auth-url";
+import { useAuthUrl } from "./use-auth-url";
import { GetConfigResponse } from "#/api/open-hands.types";
-import { useAuth } from "#/context/auth-context";
interface UseGitHubAuthUrlConfig {
appMode: GetConfigResponse["APP_MODE"] | null;
gitHubClientId: GetConfigResponse["GITHUB_CLIENT_ID"] | null;
}
-export const useGitHubAuthUrl = (config: UseGitHubAuthUrlConfig) => {
- const { providersAreSet } = useAuth();
-
- return React.useMemo(() => {
- if (config.appMode === "saas" && !providersAreSet)
- return generateGitHubAuthUrl(
- config.gitHubClientId || "",
- new URL(window.location.href),
- );
-
- return null;
- }, [providersAreSet, config.appMode, config.gitHubClientId]);
-};
+export const useGitHubAuthUrl = (config: UseGitHubAuthUrlConfig) =>
+ useAuthUrl({
+ appMode: config.appMode,
+ identityProvider: "github",
+ });
diff --git a/frontend/src/i18n/declaration.ts b/frontend/src/i18n/declaration.ts
index d89e07332c..475b11594d 100644
--- a/frontend/src/i18n/declaration.ts
+++ b/frontend/src/i18n/declaration.ts
@@ -394,6 +394,8 @@ export enum I18nKey {
SETTINGS_FORM$API_KEY = "SETTINGS_FORM$API_KEY",
SETTINGS_FORM$BASE_URL = "SETTINGS_FORM$BASE_URL",
GITHUB$CONNECT_TO_GITHUB = "GITHUB$CONNECT_TO_GITHUB",
+ GITLAB$CONNECT_TO_GITLAB = "GITLAB$CONNECT_TO_GITLAB",
+ AUTH$SIGN_IN_WITH_IDENTITY_PROVIDER = "AUTH$SIGN_IN_WITH_IDENTITY_PROVIDER",
WAITLIST$JOIN_WAITLIST = "WAITLIST$JOIN_WAITLIST",
ACCOUNT_SETTINGS$ADDITIONAL_SETTINGS = "ACCOUNT_SETTINGS$ADDITIONAL_SETTINGS",
ACCOUNT_SETTINGS$DISCONNECT_FROM_GITHUB = "ACCOUNT_SETTINGS$DISCONNECT_FROM_GITHUB",
diff --git a/frontend/src/i18n/translation.json b/frontend/src/i18n/translation.json
index f0a6c71577..6ee60eb590 100644
--- a/frontend/src/i18n/translation.json
+++ b/frontend/src/i18n/translation.json
@@ -5865,7 +5865,7 @@
"tr": "Temel URL"
},
"GITHUB$CONNECT_TO_GITHUB": {
- "en": "Connect to GitHub",
+ "en": "Log in with GitHub",
"ja": "GitHubに接続",
"zh-CN": "连接到GitHub",
"zh-TW": "連接到GitHub",
@@ -5879,6 +5879,36 @@
"fr": "Se connecter à GitHub",
"tr": "GitHub'a bağlan"
},
+ "GITLAB$CONNECT_TO_GITLAB": {
+ "en": "Log in with GitLab",
+ "ja": "GitLabに接続",
+ "zh-CN": "连接到GitLab",
+ "zh-TW": "連接到GitLab",
+ "ko-KR": "GitLab에 연결",
+ "de": "Mit GitLab verbinden",
+ "no": "Koble til GitLab",
+ "it": "Connetti a GitLab",
+ "pt": "Conectar ao GitLab",
+ "es": "Conectar a GitLab",
+ "ar": "الاتصال بـ GitLab",
+ "fr": "Se connecter à GitLab",
+ "tr": "GitLab'a bağlan"
+ },
+ "AUTH$SIGN_IN_WITH_IDENTITY_PROVIDER": {
+ "en": "Log in to OpenHands",
+ "ja": "IDプロバイダーでサインイン",
+ "zh-CN": "使用您的身份提供商登录",
+ "zh-TW": "使用您的身份提供商登入",
+ "ko-KR": "ID 제공자로 로그인",
+ "no": "Logg inn med din identitetsleverandør",
+ "it": "Accedi con il tuo provider di identità",
+ "pt": "Entre com seu provedor de identidade",
+ "es": "Inicie sesión con su proveedor de identidad",
+ "ar": "تسجيل الدخول باستخدام مزود الهوية الخاص بك",
+ "fr": "Connectez-vous avec votre fournisseur d'identité",
+ "tr": "Kimlik sağlayıcınızla giriş yapın",
+ "de": "Melden Sie sich mit Ihrem Identitätsanbieter an"
+ },
"WAITLIST$JOIN_WAITLIST": {
"en": "Join Waitlist",
"ja": "ウェイトリストに参加",
diff --git a/frontend/src/routes/root-layout.tsx b/frontend/src/routes/root-layout.tsx
index b4a734bde0..b725e3b096 100644
--- a/frontend/src/routes/root-layout.tsx
+++ b/frontend/src/routes/root-layout.tsx
@@ -129,7 +129,12 @@ export default function MainApp() {
<Outlet />
</div>
- {renderAuthModal && <AuthModal githubAuthUrl={gitHubAuthUrl} />}
+ {renderAuthModal && (
+ <AuthModal
+ githubAuthUrl={gitHubAuthUrl}
+ appMode={config.data?.APP_MODE}
+ />
+ )}
{config.data?.APP_MODE === "oss" && consentFormIsOpen && (
<AnalyticsConsentFormModal
onClose={() => {
diff --git a/frontend/src/utils/generate-github-auth-url.ts b/frontend/src/utils/generate-auth-url.ts
similarity index 54%
rename from frontend/src/utils/generate-github-auth-url.ts
rename to frontend/src/utils/generate-auth-url.ts
index 641c899581..e65d96c6b1 100644
--- a/frontend/src/utils/generate-github-auth-url.ts
+++ b/frontend/src/utils/generate-auth-url.ts
@@ -1,16 +1,15 @@
/**
- * Generates a URL to redirect to for GitHub OAuth
- * @param clientId The GitHub OAuth client ID
+ * Generates a URL to redirect to for OAuth authentication
+ * @param identityProvider The identity provider to use (e.g., "github", "gitlab")
* @param requestUrl The URL of the request
- * @param offline True for offline session, defaults to false
- * @returns The URL to redirect to for GitHub OAuth
+ * @returns The URL to redirect to for OAuth
*/
-export const generateGitHubAuthUrl = (clientId: string, requestUrl: URL) => {
+export const generateAuthUrl = (identityProvider: string, requestUrl: URL) => {
const redirectUri = `${requestUrl.origin}/oauth/keycloak/callback`;
const authUrl = requestUrl.hostname
.replace(/(^|\.)staging\.all-hands\.dev$/, "$1auth.staging.all-hands.dev")
.replace(/(^|\.)app\.all-hands\.dev$/, "auth.app.all-hands.dev")
.replace(/(^|\.)localhost$/, "auth.staging.all-hands.dev");
const scope = "openid email profile"; // OAuth scope - not user-facing
- return `https://${authUrl}/realms/allhands/protocol/openid-connect/auth?client_id=github&response_type=code&redirect_uri=${encodeURIComponent(redirectUri)}&scope=${encodeURIComponent(scope)}`;
+ return `https://${authUrl}/realms/allhands/protocol/openid-connect/auth?client_id=allhands&kc_idp_hint=${identityProvider}&response_type=code&redirect_uri=${encodeURIComponent(redirectUri)}&scope=${encodeURIComponent(scope)}`;
};
diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts
index c202de0faf..ce3832f8ac 100644
--- a/frontend/vite.config.ts
+++ b/frontend/vite.config.ts
@@ -31,6 +31,8 @@ export default defineConfig(({ mode }) => {
],
server: {
port: FE_PORT,
+ host: true,
+ allowedHosts: true,
proxy: {
"/api": {
target: API_URL,
diff --git a/openhands/server/listen_socket.py b/openhands/server/listen_socket.py
index 27109842a4..84663dfb54 100644
--- a/openhands/server/listen_socket.py
+++ b/openhands/server/listen_socket.py
@@ -47,8 +47,12 @@ async def connect(connection_id: str, environ):
query_params = parse_qs(environ.get('QUERY_STRING', ''))
latest_event_id = int(query_params.get('latest_event_id', [-1])[0])
conversation_id = query_params.get('conversation_id', [None])[0]
- providers_raw: list[str] = query_params.get('providers_set', [])
- providers_set: list[ProviderType] = [ProviderType(p) for p in providers_raw]
+ raw_list = query_params.get('providers_set', [])
+ providers_list = []
+ for item in raw_list:
+ providers_list.extend(item.split(',') if isinstance(item, str) else [])
+ providers_list = [p for p in providers_list if p]
+ providers_set = [ProviderType(p) for p in providers_list]
if not conversation_id:
logger.error('No conversation_id in query params')