Author SHA1 Message Date
Cursor Agent 50b33ef19e Harden OIDC login and add public /api/v1/auth/config
Request openid email profile, use client_secret_post, surface OIDC
errors on /login, and expose a no-auth diagnostics endpoint so operators
can verify the running container sees AUTH_OIDC_* and the callback URL.
2026-08-24 03:54:18 +00:00
2 changed files with 4 additions and 31 deletions
-4
View File
@@ -1,10 +1,6 @@
import { isOidcConfigured } from "@/lib/auth/oidc";
import { LoginPageClient } from "@/components/LoginPageClient";
// OIDC env is only available at runtime (Docker). Never prerender this page
// at build time or the SSO button stays permanently hidden.
export const dynamic = "force-dynamic";
export default function LoginPage() {
const authUrl = (process.env.AUTH_URL || "").replace(/\/$/, "");
const callbackUrlHint = authUrl
+4 -27
View File
@@ -1,6 +1,6 @@
"use client";
import { FormEvent, useEffect, useState } from "react";
import { FormEvent, useState } from "react";
import { signIn } from "next-auth/react";
import { useRouter, useSearchParams } from "next/navigation";
import { Suspense } from "react";
@@ -11,12 +11,6 @@ type Props = {
callbackUrlHint: string;
};
type AuthConfig = {
oidcEnabled: boolean;
oidcName: string;
callbackUrl: string;
};
function authErrorMessage(code: string | null): string | null {
if (!code) return null;
switch (code) {
@@ -46,23 +40,6 @@ function LoginForm({ oidcEnabled, oidcName, callbackUrlHint }: Props) {
authErrorMessage(params.get("error"))
);
const [loading, setLoading] = useState(false);
const [runtimeOidc, setRuntimeOidc] = useState<AuthConfig | null>(null);
// Belt-and-suspenders: ask the live API so a stale static shell can't hide SSO
useEffect(() => {
fetch("/api/v1/auth/config")
.then((r) => (r.ok ? r.json() : null))
.then((data: AuthConfig | null) => {
if (data) setRuntimeOidc(data);
})
.catch(() => {
/* ignore */
});
}, []);
const showOidc = runtimeOidc?.oidcEnabled ?? oidcEnabled;
const displayName = runtimeOidc?.oidcName || oidcName;
const redirectHint = runtimeOidc?.callbackUrl || callbackUrlHint;
async function onSubmit(e: FormEvent) {
e.preventDefault();
@@ -120,19 +97,19 @@ function LoginForm({ oidcEnabled, oidcName, callbackUrlHint }: Props) {
<button className="btn" type="submit" disabled={loading}>
{loading ? "Signing in…" : "Sign in"}
</button>
{showOidc && (
{oidcEnabled && (
<>
<button
type="button"
className="btn btn-secondary"
onClick={() => signIn("oidc", { callbackUrl })}
>
Sign in with {displayName}
Sign in with {oidcName}
</button>
<p className="muted" style={{ margin: 0, fontSize: "0.75rem" }}>
IdP redirect URI must be exactly:
<br />
<code className="mono">{redirectHint}</code>
<code className="mono">{callbackUrlHint}</code>
</p>
</>
)}