Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

chore(sso): improve enterprise sso error message clarity (#10783)

Michael Fröhlich2f52aafddcc4
diff --git a/web/src/features/auth-credentials/server/signupApiHandler.ts b/web/src/features/auth-credentials/server/signupApiHandler.ts
index abbac370fe..d30b8635e8 100644
--- a/web/src/features/auth-credentials/server/signupApiHandler.ts
+++ b/web/src/features/auth-credentials/server/signupApiHandler.ts
@@ -2,6 +2,7 @@ import { env } from "@/src/env.mjs";
import { createUserEmailPassword } from "@/src/features/auth-credentials/lib/credentialsServerUtils";
import { signupSchema } from "@/src/features/auth/lib/signupSchema";
import { getSsoAuthProviderIdForDomain } from "@/src/ee/features/multi-tenant-sso/utils";
+import { ENTERPRISE_SSO_REQUIRED_MESSAGE } from "@/src/features/auth/constants";
import type { NextApiRequest, NextApiResponse } from "next";
import { logger } from "@langfuse/shared/src/server";
@@ -63,8 +64,7 @@ export async function signupApiHandler(
const multiTenantSsoProvider = await getSsoAuthProviderIdForDomain(domain);
if (multiTenantSsoProvider) {
res.status(422).json({
- message:
- "You must sign in via Enterprise SSO for this domain. Enter your email on the sign-in page and press Continue.",
+ message: ENTERPRISE_SSO_REQUIRED_MESSAGE,
});
return;
}
diff --git a/web/src/features/auth/constants.ts b/web/src/features/auth/constants.ts
new file mode 100644
index 0000000000..dfee99a4eb
--- /dev/null
+++ b/web/src/features/auth/constants.ts
@@ -0,0 +1,2 @@
+export const ENTERPRISE_SSO_REQUIRED_MESSAGE =
+ "You must sign in via custom Enterprise SSO for this domain. Enter your email on the sign-in page and press Continue.";
diff --git a/web/src/pages/auth/enterprise-sso-required.tsx b/web/src/pages/auth/enterprise-sso-required.tsx
new file mode 100644
index 0000000000..c06341839d
--- /dev/null
+++ b/web/src/pages/auth/enterprise-sso-required.tsx
@@ -0,0 +1,228 @@
+import Head from "next/head";
+import Link from "next/link";
+import { useRouter } from "next/router";
+import { useEffect, useMemo, useState } from "react";
+import { signIn } from "next-auth/react";
+import { zodResolver } from "@hookform/resolvers/zod";
+import * as z from "zod/v4";
+import { useForm } from "react-hook-form";
+import { LangfuseIcon } from "@/src/components/LangfuseLogo";
+import { Button } from "@/src/components/ui/button";
+import {
+ Form,
+ FormControl,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+} from "@/src/components/ui/form";
+import { Input } from "@/src/components/ui/input";
+import { env } from "@/src/env.mjs";
+import { captureException } from "@sentry/nextjs";
+
+const enterpriseSsoFormSchema = z.object({
+ email: z.string().email(),
+});
+
+const PROVIDER_LABELS: Record<string, string> = {
+ google: "Google",
+ github: "GitHub",
+ "github-enterprise": "GitHub Enterprise",
+ gitlab: "GitLab",
+ "azure-ad": "Azure AD",
+ okta: "Okta",
+ authentik: "Authentik",
+ onelogin: "OneLogin",
+ auth0: "Auth0",
+ cognito: "Cognito",
+ keycloak: "Keycloak",
+ workos: "WorkOS",
+ wordpress: "WordPress",
+ custom: "Custom OAuth",
+};
+
+export default function EnterpriseSsoRequiredPage() {
+ const router = useRouter();
+ const [error, setError] = useState<string | null>(null);
+ const [loading, setLoading] = useState(false);
+
+ const emailFromQuery =
+ typeof router.query.email === "string" ? router.query.email : "";
+ const attemptedProvider =
+ typeof router.query.attemptedProvider === "string"
+ ? router.query.attemptedProvider
+ : undefined;
+ const callbackUrl =
+ typeof router.query.callbackUrl === "string"
+ ? router.query.callbackUrl
+ : undefined;
+
+ const friendlyProviderName = useMemo(() => {
+ if (!attemptedProvider) return undefined;
+ return (
+ PROVIDER_LABELS[attemptedProvider] ?? attemptedProvider.replace(/-/g, " ")
+ );
+ }, [attemptedProvider]);
+
+ const form = useForm<z.infer<typeof enterpriseSsoFormSchema>>({
+ resolver: zodResolver(enterpriseSsoFormSchema),
+ defaultValues: {
+ email: emailFromQuery,
+ },
+ });
+
+ useEffect(() => {
+ if (emailFromQuery) {
+ form.setValue("email", emailFromQuery);
+ }
+ }, [emailFromQuery, form]);
+
+ async function onSubmit(values: z.infer<typeof enterpriseSsoFormSchema>) {
+ setError(null);
+ setLoading(true);
+
+ const domain = values.email.split("@")[1]?.toLowerCase();
+ if (!domain) {
+ form.setError("email", { message: "Invalid email address" });
+ setLoading(false);
+ return;
+ }
+
+ try {
+ const response = await fetch(
+ `${env.NEXT_PUBLIC_BASE_PATH ?? ""}/api/auth/check-sso`,
+ {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({ domain }),
+ },
+ );
+
+ if (response.ok) {
+ const { providerId } = (await response.json()) as {
+ providerId: string;
+ };
+ await signIn(providerId, {
+ callbackUrl,
+ });
+ return;
+ }
+
+ if (response.status === 404) {
+ setError(
+ "We couldn't find a custom Enterprise SSO configuration for this domain. Double-check your company email or contact your administrator.",
+ );
+ return;
+ }
+
+ const data = (await response.json().catch(() => null)) as {
+ message?: string;
+ } | null;
+ setError(
+ data?.message ??
+ "Unable to start the Enterprise SSO sign-in flow. Please try again.",
+ );
+ } catch (err) {
+ captureException(err);
+ setError(
+ "Something went wrong while checking your Enterprise SSO configuration. Please try again.",
+ );
+ } finally {
+ setLoading(false);
+ }
+ }
+
+ const description = friendlyProviderName
+ ? `You tried signing in with ${friendlyProviderName}, but this domain requires your company's custom Enterprise SSO.`
+ : "This domain requires your company's custom Enterprise SSO.";
+
+ return (
+ <>
+ <Head>
+ <title>Enterprise SSO Required | Langfuse</title>
+ </Head>
+ <div className="flex min-h-screen-with-banner flex-col justify-center bg-background px-6 py-12 lg:px-8">
+ <div className="sm:mx-auto sm:w-full sm:max-w-md">
+ <LangfuseIcon className="mx-auto" />
+ <h1 className="mt-6 text-center text-2xl font-bold text-primary">
+ Use your Enterprise SSO
+ </h1>
+ <p className="mt-2 text-center text-sm leading-6 text-muted-foreground">
+ {description} Enter your company email so we can send you to the
+ correct identity provider.
+ </p>
+ </div>
+
+ <div className="mt-10 rounded-lg border border-border bg-card px-6 py-8 shadow sm:mx-auto sm:w-full sm:max-w-md">
+ <Form {...form}>
+ <form
+ className="space-y-6"
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
+ onSubmit={form.handleSubmit(onSubmit)}
+ >
+ <FormField
+ control={form.control}
+ name="email"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Email</FormLabel>
+ <FormControl>
+ <Input
+ placeholder="[email protected]"
+ autoComplete="email"
+ {...field}
+ />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ <Button
+ type="submit"
+ className="w-full"
+ loading={loading}
+ disabled={loading}
+ >
+ Continue with Enterprise SSO
+ </Button>
+ </form>
+ </Form>
+ {error ? (
+ <div className="mt-4 text-center text-sm font-medium text-destructive">
+ {error}
+ <br />
+ Contact{" "}
+ <a
+ href="mailto:[email protected]"
+ className="text-primary-accent hover:text-hover-primary-accent"
+ >
+ </a>{" "}
+ if this keeps happening.
+ </div>
+ ) : null}
+ <div className="mt-6 text-center text-sm text-muted-foreground">
+ <Link
+ href="/auth/sign-in"
+ className="text-primary-accent hover:text-hover-primary-accent"
+ >
+ Back to other sign-in options
+ </Link>
+ </div>
+ </div>
+
+ <div className="mt-4 text-center text-xs text-muted-foreground">
+ Need help? Contact{" "}
+ <a
+ href="mailto:[email protected]"
+ className="text-primary-accent hover:text-hover-primary-accent"
+ >
+ </a>
+ .
+ </div>
+ </div>
+ </>
+ );
+}
diff --git a/web/src/server/auth.ts b/web/src/server/auth.ts
index 6c5443a396..f3a57a7e8c 100644
--- a/web/src/server/auth.ts
+++ b/web/src/server/auth.ts
@@ -40,6 +40,7 @@ import {
getSsoAuthProviderIdForDomain,
loadSsoProviders,
} from "@/src/ee/features/multi-tenant-sso/utils";
+import { ENTERPRISE_SSO_REQUIRED_MESSAGE } from "@/src/features/auth/constants";
import { z } from "zod/v4";
import { CloudConfigSchema } from "@langfuse/shared";
import {
@@ -111,9 +112,7 @@ const staticProviders: Provider[] = [
const multiTenantSsoProvider =
await getSsoAuthProviderIdForDomain(domain);
if (multiTenantSsoProvider) {
- throw new Error(
- `Sign in with SSO is required for this domain. Please enter your email address and click continue to proceed.`,
- );
+ throw new Error(ENTERPRISE_SSO_REQUIRED_MESSAGE);
}
const dbUser = await prisma.user.findUnique({
@@ -748,12 +747,17 @@ export async function getAuthOptions(): Promise<NextAuthOptions> {
multiTenantSsoProvider &&
account?.provider !== multiTenantSsoProvider
) {
- console.log(
+ logger.info(
"Custom SSO provider enforced for domain, user signed in with other provider",
+ { email, attemptedProvider: account?.provider },
);
- throw new Error(
- `You must sign in via Enterprise SSO for this domain. Enter your email on the sign-in page and press Continue.`,
- );
+ const params = new URLSearchParams({
+ reason: "sso_enforced_domain",
+ });
+ if (email) params.set("email", email);
+ if (account?.provider)
+ params.set("attemptedProvider", account.provider);
+ return `${env.NEXT_PUBLIC_BASE_PATH ?? ""}/auth/enterprise-sso-required?${params.toString()}`;
}
// EE: Check that provider is only used for the associated domain