Skip to content

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

feat(auth): add idp-initiated sso (#10191)

Marc Klingen75a365b9b857
diff --git a/web/src/components/layouts/layout.tsx b/web/src/components/layouts/layout.tsx
index 9d68b86e55..9c9901a2aa 100644
--- a/web/src/components/layouts/layout.tsx
+++ b/web/src/components/layouts/layout.tsx
@@ -72,6 +72,7 @@ const pathsWithoutNavigation: string[] = [
const unauthenticatedPaths: string[] = [
"/auth/sign-in",
"/auth/sign-up",
+ "/auth/sso-initiate",
"/auth/error",
"/auth/hf-spaces",
];
diff --git a/web/src/pages/auth/sso-initiate.tsx b/web/src/pages/auth/sso-initiate.tsx
new file mode 100644
index 0000000000..9c7e5fa6c6
--- /dev/null
+++ b/web/src/pages/auth/sso-initiate.tsx
@@ -0,0 +1,63 @@
+import { signIn } from "next-auth/react";
+import Head from "next/head";
+import { useEffect, useState } from "react";
+import { useRouter } from "next/router";
+import { ErrorPageWithSentry } from "@/src/components/error-page";
+import { Spinner } from "@/src/components/layouts/spinner";
+
+export default function SSOInitiate() {
+ const router = useRouter();
+ const [error, setError] = useState<string | null>(null);
+
+ useEffect(() => {
+ // Wait for router to be ready
+ if (!router.isReady) {
+ return;
+ }
+
+ const provider = router.query.provider as string | undefined;
+
+ // If provider is missing or empty, show error
+ if (!provider || provider === "") {
+ setError("No SSO provider specified. Please contact your administrator.");
+ return;
+ }
+
+ // Automatically trigger sign-in with the provider
+ signIn(provider)
+ .then(() => {
+ // signIn will redirect automatically on success
+ // No need to do anything here
+ })
+ .catch((error) => {
+ console.error("SSO initiation error:", error);
+ setError(
+ error instanceof Error
+ ? error.message
+ : "Failed to initiate SSO sign-in. Please try again or contact support.",
+ );
+ });
+ }, [router.isReady, router.query.provider]);
+
+ // Show error page if sign-in failed
+ if (error) {
+ return (
+ <>
+ <Head>
+ <title>Sign-in Error | Langfuse</title>
+ </Head>
+ <ErrorPageWithSentry title="SSO Sign-in Failed" message={error} />
+ </>
+ );
+ }
+
+ // Show loading spinner while processing
+ return (
+ <>
+ <Head>
+ <title>Signing in | Langfuse</title>
+ </Head>
+ <Spinner message="Redirecting to your identity provider..." />
+ </>
+ );
+}