Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat(auth): add a generic OIDC provider
Atlas (by M. Pfennig)6bf2d0105e9e
diff --git a/apps/web/app/(org)/login/form.tsx b/apps/web/app/(org)/login/form.tsxindex 5172e8ae5..014d5f5bc 100644--- a/apps/web/app/(org)/login/form.tsx+++ b/apps/web/app/(org)/login/form.tsx@@ -177,6 +177,18 @@ export function LoginForm() {});}, [getNextPath]);+ const handleOidcSignIn = useCallback(() => {+ const nextPath = getNextPath();+ trackEvent("auth_started", {+ method: "oidc",+ is_signup: false,+ auth_surface: "login",+ });+ signIn("oidc", {+ ...(nextPath ? { callbackUrl: nextPath } : {}),+ });+ }, [getNextPath]);+const handleWorkosSignIn = useCallback((identifier: string, connectionId?: string) => {if (workosSignInPending.current) return;@@ -596,7 +608,9 @@ const NormalLogin = ({</Link></motion.p>- {(publicEnv.googleAuthAvailable || publicEnv.workosAuthAvailable) && (+ {(publicEnv.googleAuthAvailable ||+ publicEnv.workosAuthAvailable ||+ publicEnv.oidcAuthAvailable) && (<><div className="flex gap-4 items-center mt-4 mb-4"><span className="flex-1 h-px bg-gray-5" />@@ -632,6 +646,19 @@ const NormalLogin = ({</p></div>)}+ {publicEnv.oidcAuthAvailable && (+ <MotionButton+ variant="gray"+ type="button"+ className="w-full"+ layout+ onClick={handleOidcSignIn}+ disabled={loading || emailSent}+ >+ <LucideArrowUpRight size={20} />+ Login with {publicEnv.oidcName}+ </MotionButton>+ )}{publicEnv.workosAuthAvailable && (<MotionButtonvariant="gray"diff --git a/apps/web/app/Layout/AppProviders.tsx b/apps/web/app/Layout/AppProviders.tsxindex 18703d070..5f04a81fb 100644--- a/apps/web/app/Layout/AppProviders.tsx+++ b/apps/web/app/Layout/AppProviders.tsx@@ -28,6 +28,12 @@ export async function AppProviders({ children }: PropsWithChildren) {webUrl: buildEnv.NEXT_PUBLIC_WEB_URL,workosAuthAvailable: !!serverEnv().WORKOS_CLIENT_ID,googleAuthAvailable: !!serverEnv().GOOGLE_CLIENT_ID,+ oidcAuthAvailable: !!(+ serverEnv().OIDC_ISSUER &&+ serverEnv().OIDC_CLIENT_ID &&+ serverEnv().OIDC_CLIENT_SECRET+ ),+ oidcName: serverEnv().OIDC_NAME || "SSO",}}><ReactQueryProvider>diff --git a/apps/web/utils/public-env.tsx b/apps/web/utils/public-env.tsxindex 949999239..25da1b0af 100644--- a/apps/web/utils/public-env.tsx+++ b/apps/web/utils/public-env.tsx@@ -6,6 +6,8 @@ type PublicEnvContext = {webUrl: string;googleAuthAvailable: boolean;workosAuthAvailable: boolean;+ oidcAuthAvailable: boolean;+ oidcName: string;};const Context = createContext<PublicEnvContext | null>(null);diff --git a/packages/database/auth/auth-options.ts b/packages/database/auth/auth-options.tsindex b8641c378..ebd9e3527 100644--- a/packages/database/auth/auth-options.ts+++ b/packages/database/auth/auth-options.ts@@ -90,7 +90,42 @@ export const authOptions = (ssoContext?: SsoAuthContext): NextAuthOptions => {if (_providers) return _providers;const appleClientId = serverEnv().APPLE_CLIENT_ID;const appleClientSecret = serverEnv().APPLE_CLIENT_SECRET;+ const oidcIssuer = serverEnv().OIDC_ISSUER;+ const oidcClientId = serverEnv().OIDC_CLIENT_ID;+ const oidcClientSecret = serverEnv().OIDC_CLIENT_SECRET;_providers = [+ // Any OpenID Connect provider, described by its discovery document.+ // Email linking matches the WorkOS provider below: an operator who+ // configures this controls the issuer and its email claim.+ ...(oidcIssuer && oidcClientId && oidcClientSecret+ ? [+ {+ id: "oidc",+ name: serverEnv().OIDC_NAME || "SSO",+ type: "oauth" as const,+ wellKnown: `${oidcIssuer.replace(/\/$/, "")}/.well-known/openid-configuration`,+ issuer: oidcIssuer,+ clientId: oidcClientId,+ clientSecret: oidcClientSecret,+ idToken: true,+ checks: ["state" as const, "pkce" as const],+ authorization: { params: { scope: "openid email profile" } },+ allowDangerousEmailAccountLinking: true,+ profile(profile: Record<string, any>) {+ return {+ id: profile.sub,+ name:+ profile.name ||+ profile.preferred_username ||+ profile.email?.split("@")[0] ||+ profile.sub,+ email: profile.email?.trim().toLowerCase(),+ image: profile.picture ?? null,+ };+ },+ },+ ]+ : []),...(appleClientId && appleClientSecret? [AppleProvider({diff --git a/packages/env/server.ts b/packages/env/server.tsindex 78d649a44..b9c51a725 100644--- a/packages/env/server.ts+++ b/packages/env/server.ts@@ -75,6 +75,16 @@ function createServerEnv() {WORKOS_CLIENT_ID: z.string().optional(),WORKOS_API_KEY: z.string().optional(),+ /// Generic OIDC+ // Provide all three to add a sign-in button for any OpenID Connect+ // provider. OIDC_ISSUER is the base URL whose+ // /.well-known/openid-configuration describes the endpoints.+ OIDC_ISSUER: z.string().optional(),+ OIDC_CLIENT_ID: z.string().optional(),+ OIDC_CLIENT_SECRET: z.string().optional(),+ // Label for the sign-in button. Defaults to "SSO".+ OIDC_NAME: z.string().optional(),+/// SettingsCAP_VIDEOS_DEFAULT_PUBLIC: boolString(true).describe("Should videos be public or private by default",