🪢 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
Add AUTH_DOMAINS_WITH_SSO_ENFORCEMENT flag (#433)
Marc Klingen996c08c32cb2
diff --git a/.env.cloud.example b/.env.cloud.exampleindex 2949f60407..2f872e82ac 100644--- a/.env.cloud.example+++ b/.env.cloud.example@@ -38,4 +38,5 @@ SALT="salt"AUTH_GOOGLE_CLIENT_ID=AUTH_GOOGLE_CLIENT_SECRET=AUTH_GITHUB_CLIENT_ID=-AUTH_GITHUB_CLIENT_SECRET=\ No newline at end of file+AUTH_GITHUB_CLIENT_SECRET=+# AUTH_DOMAINS_WITH_OAUTH_ENFORCEMENT=domain1.com,domain2.com\ No newline at end of filediff --git a/src/env.mjs b/src/env.mjsindex fc510eb8a7..c9302bad2f 100644--- a/src/env.mjs+++ b/src/env.mjs@@ -38,6 +38,7 @@ export const env = createEnv({AUTH_GOOGLE_CLIENT_SECRET: z.string().optional(),AUTH_GITHUB_CLIENT_ID: z.string().optional(),AUTH_GITHUB_CLIENT_SECRET: z.string().optional(),+ AUTH_DOMAINS_WITH_SSO_ENFORCEMENT: z.string().optional(),},/**@@ -78,5 +79,7 @@ export const env = createEnv({AUTH_GOOGLE_CLIENT_SECRET: process.env.AUTH_GOOGLE_CLIENT_SECRET,AUTH_GITHUB_CLIENT_ID: process.env.AUTH_GITHUB_CLIENT_ID,AUTH_GITHUB_CLIENT_SECRET: process.env.AUTH_GITHUB_CLIENT_SECRET,+ AUTH_DOMAINS_WITH_SSO_ENFORCEMENT:+ process.env.AUTH_DOMAINS_WITH_SSO_ENFORCEMENT,},});diff --git a/src/pages/api/auth/signup.ts b/src/pages/api/auth/signup.tsindex 6708004861..e44a3e5ed1 100644--- a/src/pages/api/auth/signup.ts+++ b/src/pages/api/auth/signup.ts@@ -23,6 +23,18 @@ export default async function handler(const body = validBody.data;+ // check if email domain is blocked+ const blockedDomains =+ env.AUTH_DOMAINS_WITH_SSO_ENFORCEMENT?.split(",") ?? [];+ const domain = body.email.split("@")[1]?.toLowerCase();+ if (domain && blockedDomains.includes(domain)) {+ res.status(422).json({+ message:+ "Sign up with email and password is disabled for this domain. Please use SSO.",+ });+ return;+ }+// create the userlet userId: string;try {diff --git a/src/pages/auth/sign-in.tsx b/src/pages/auth/sign-in.tsxindex 34ac640e8f..6326236eef 100644--- a/src/pages/auth/sign-in.tsx+++ b/src/pages/auth/sign-in.tsx@@ -142,8 +142,9 @@ export default function SignIn(props: PageProps) {</Button>{credentialsFormError ? (<div className="text-center text-sm font-medium text-destructive">- {credentialsFormError}, contact support if this error is- unexpected.+ {credentialsFormError}+ <br />+ Contact support if this error is unexpected.</div>) : null}</form>diff --git a/src/server/auth.ts b/src/server/auth.tsindex 7d0e402bb6..2af2bc96f1 100644--- a/src/server/auth.ts+++ b/src/server/auth.ts@@ -53,6 +53,15 @@ const providers: Provider[] = [async authorize(credentials, _req) {if (!credentials) throw new Error("No credentials");+ const blockedDomains =+ env.AUTH_DOMAINS_WITH_SSO_ENFORCEMENT?.split(",") ?? [];+ const domain = credentials.email.split("@")[1]?.toLowerCase();+ if (domain && blockedDomains.includes(domain)) {+ throw new Error(+ "Sign in with email and password is disabled for this domain. Please use SSO.",+ );+ }+const dbUser = await prisma.user.findUnique({where: {email: credentials.email.toLowerCase(),