feat: SSO-Login per OpenID Connect (Authentik u.a.)
Dritte Login-Methode neben Passwort und Passkey, konfiguriert über OIDC_ISSUER/OIDC_CLIENT_ID/OIDC_CLIENT_SECRET (optional, Button bleibt ohne diese Vars ausgeblendet). Authorization-Code-Flow mit PKCE, ID-Token-Signaturprüfung gegen das JWKS des Providers via neuer Abhängigkeit "jose" (RS256 fest gepinnt gegen Algorithm-Confusion), State/Nonce kurzlebig und einmalig verwendbar in neuer Tabelle oidc_states (Migration 0003, analog zu webauthn_challenges). Funktioniert ausschließlich für bereits angelegte Benutzer (Abgleich per E-Mail) – kein Auto-Provisioning, keine Rollenübernahme aus Claims, beides bleibt exklusiv über die bestehende Benutzerverwaltung steuerbar. app/login/page.tsx zu Server-Component-Wrapper reduziert (prüft isConfigured(), liest ?error= aus searchParams), bisheriger Inhalt nach components/LoginForm.tsx verschoben. Version 1.9.0. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import "server-only";
|
||||
import { query, queryOne } from "@/lib/db";
|
||||
|
||||
const STATE_TTL_MS = 10 * 60 * 1000;
|
||||
|
||||
export async function storeState(
|
||||
state: string,
|
||||
nonce: string,
|
||||
codeVerifier: string
|
||||
): Promise<void> {
|
||||
// Kein Cron nötig: abgelaufene Zeilen bei jedem neuen State gleich
|
||||
// mit aufräumen (wie bei webauthn_challenges).
|
||||
await query("delete from oidc_states where expires_at < now()");
|
||||
await query(
|
||||
"insert into oidc_states (state, nonce, code_verifier, expires_at) values ($1, $2, $3, $4)",
|
||||
[state, nonce, codeVerifier, new Date(Date.now() + STATE_TTL_MS)]
|
||||
);
|
||||
}
|
||||
|
||||
/** Einmalig verwendbar: die Zeile wird beim Abruf sofort gelöscht. */
|
||||
export async function consumeState(
|
||||
state: string
|
||||
): Promise<{ nonce: string; codeVerifier: string } | null> {
|
||||
const row = await queryOne<{ nonce: string; code_verifier: string }>(
|
||||
`delete from oidc_states
|
||||
where state = $1 and expires_at > now()
|
||||
returning nonce, code_verifier`,
|
||||
[state]
|
||||
);
|
||||
return row ? { nonce: row.nonce, codeVerifier: row.code_verifier } : null;
|
||||
}
|
||||
Reference in New Issue
Block a user