🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
feat(auth): add workos as idp (#5828)
Marc Klingenb98b90e635c0
diff --git a/.env.prod.example b/.env.prod.exampleindex b16c9e9b80..fca84879a7 100644--- a/.env.prod.example+++ b/.env.prod.example@@ -114,6 +114,9 @@ OTEL_SERVICE_NAME="langfuse"# AUTH_KEYCLOAK_ALLOW_ACCOUNT_LINKING=false# AUTH_KEYCLOAK_CLIENT_AUTH_METHOD=# AUTH_KEYCLOAK_CHECKS=+# AUTH_WORKOS_CLIENT_ID=+# AUTH_WORKOS_CLIENT_SECRET=+# AUTH_WORKOS_ALLOW_ACCOUNT_LINKING=false# AUTH_CUSTOM_CLIENT_ID=# AUTH_CUSTOM_CLIENT_SECRET=# AUTH_CUSTOM_ISSUER=diff --git a/web/src/env.mjs b/web/src/env.mjsindex 605615539a..0b450c0679 100644--- a/web/src/env.mjs+++ b/web/src/env.mjs@@ -137,6 +137,9 @@ export const env = createEnv({AUTH_CUSTOM_CHECKS: zAuthChecks,AUTH_CUSTOM_ALLOW_ACCOUNT_LINKING: z.enum(["true", "false"]).optional(),AUTH_CUSTOM_ID_TOKEN: z.enum(["true", "false"]).optional(),+ AUTH_WORKOS_CLIENT_ID: z.string().optional(),+ AUTH_WORKOS_CLIENT_SECRET: z.string().optional(),+ AUTH_WORKOS_ALLOW_ACCOUNT_LINKING: z.enum(["true", "false"]).optional(),AUTH_DOMAINS_WITH_SSO_ENFORCEMENT: z.string().optional(),AUTH_IGNORE_ACCOUNT_FIELDS: z.string().optional(),AUTH_DISABLE_USERNAME_PASSWORD: z.enum(["true", "false"]).optional(),@@ -428,6 +431,9 @@ export const env = createEnv({AUTH_CUSTOM_ALLOW_ACCOUNT_LINKING:process.env.AUTH_CUSTOM_ALLOW_ACCOUNT_LINKING,AUTH_CUSTOM_ID_TOKEN: process.env.AUTH_CUSTOM_ID_TOKEN,+ AUTH_WORKOS_CLIENT_ID: process.env.AUTH_WORKOS_CLIENT_ID,+ AUTH_WORKOS_CLIENT_SECRET: process.env.AUTH_WORKOS_CLIENT_SECRET,+ AUTH_WORKOS_ALLOW_ACCOUNT_LINKING: process.env.AUTH_WORKOS_ALLOW_ACCOUNT_LINKING,AUTH_IGNORE_ACCOUNT_FIELDS: process.env.AUTH_IGNORE_ACCOUNT_FIELDS,AUTH_DOMAINS_WITH_SSO_ENFORCEMENT:process.env.AUTH_DOMAINS_WITH_SSO_ENFORCEMENT,diff --git a/web/src/pages/auth/sign-in.tsx b/web/src/pages/auth/sign-in.tsxindex 328b8565de..24ea8ea3f3 100644--- a/web/src/pages/auth/sign-in.tsx+++ b/web/src/pages/auth/sign-in.tsx@@ -28,7 +28,7 @@ import { CloudRegionSwitch } from "@/src/features/auth/components/AuthCloudRegioimport { PasswordInput } from "@/src/components/ui/password-input";import { Turnstile } from "@marsidev/react-turnstile";import { isAnySsoConfigured } from "@/src/ee/features/multi-tenant-sso/utils";-import { Shield } from "lucide-react";+import { Shield, Code } from "lucide-react";import { useRouter } from "next/router";import { captureException } from "@sentry/nextjs";import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";@@ -54,6 +54,7 @@ export type PageProps = {auth0: boolean;cognito: boolean;keycloak: boolean;+ workos: boolean;custom:| {name: string;@@ -106,6 +107,9 @@ export const getServerSideProps: GetServerSideProps<PageProps> = async () => {env.AUTH_KEYCLOAK_CLIENT_ID !== undefined &&env.AUTH_KEYCLOAK_CLIENT_SECRET !== undefined &&env.AUTH_KEYCLOAK_ISSUER !== undefined,+ workos:+ env.AUTH_WORKOS_CLIENT_ID !== undefined &&+ env.AUTH_WORKOS_CLIENT_SECRET !== undefined,custom:env.AUTH_CUSTOM_CLIENT_ID !== undefined &&env.AUTH_CUSTOM_CLIENT_SECRET !== undefined &&@@ -253,6 +257,44 @@ export function SSOButtons({Keycloak</Button>)}+ {authProviders.workos && (+ <>+ <Button+ onClick={() => {+ const organization = window.prompt(+ "Please enter your organization ID",+ );+ if (organization) {+ capture("sign_in:button_click", { provider: "workos" });+ void signIn("workos", undefined, {+ organization,+ });+ }+ }}+ variant="secondary"+ >+ <Code className="mr-3" size={18} />+ WorkOS (organization)+ </Button>+ <Button+ onClick={() => {+ const connection = window.prompt(+ "Please enter your connection ID",+ );+ if (connection) {+ capture("sign_in:button_click", { provider: "workos" });+ void signIn("workos", undefined, {+ connection,+ });+ }+ }}+ variant="secondary"+ >+ <Code className="mr-3" size={18} />+ WorkOS (connection)+ </Button>+ </>+ )}{authProviders.custom && (<ButtononClick={() => handleSignIn("custom")}diff --git a/web/src/server/auth.ts b/web/src/server/auth.tsindex 40321eaadf..600e8ab289 100644--- a/web/src/server/auth.ts+++ b/web/src/server/auth.ts@@ -28,6 +28,7 @@ import Auth0Provider from "next-auth/providers/auth0";import CognitoProvider from "next-auth/providers/cognito";import AzureADProvider from "next-auth/providers/azure-ad";import KeycloakProvider from "next-auth/providers/keycloak";+import WorkOSProvider from "next-auth/providers/workos";import { type Provider } from "next-auth/providers/index";import { getCookieName, getCookieOptions } from "./utils/cookies";import {@@ -356,6 +357,19 @@ if (}),);+if (env.AUTH_WORKOS_CLIENT_ID && env.AUTH_WORKOS_CLIENT_SECRET)+ staticProviders.push(+ WorkOSProvider({+ clientId: env.AUTH_WORKOS_CLIENT_ID,+ clientSecret: env.AUTH_WORKOS_CLIENT_SECRET,+ allowDangerousEmailAccountLinking:+ env.AUTH_WORKOS_ALLOW_ACCOUNT_LINKING === "true",+ client: {+ token_endpoint_auth_method: "client_secret_post",+ },+ }),+ );+// Extend Prisma Adapterconst prismaAdapter = PrismaAdapter(prisma);const ignoredAccountFields = env.AUTH_IGNORE_ACCOUNT_FIELDS?.split(",") ?? [];@@ -397,6 +411,11 @@ const extendedPrismaAdapter: Adapter = {delete data["not-before-policy"];}+ // WorkOS returns profile data that doesn't match the schema+ if (data.provider === "workos") {+ delete data["profile"];+ }+// Optionally, remove fields returned by the provider that cause issues with the adapter// Configure via AUTH_IGNORE_ACCOUNT_FIELDSfor (const ignoredField of ignoredAccountFields) {