feature: add oidc login flow

This commit is contained in:
2025-12-28 09:16:16 +01:00
parent 6f49528bbd
commit 3991362e67
9 changed files with 398 additions and 14 deletions

View File

@ -19,6 +19,10 @@
<section>
<h3>Login (nur Root-User)</h3>
<p>Bevorzugt OIDC nutzen, falls konfiguriert. Die Anmeldung öffnet den Identity Provider und setzt eine Session-Cookie.</p>
<button id="oidcLogin" type="button">Login via OIDC</button>
<hr />
<p>Lokale Anmeldung (PAM) nur falls OIDC nicht verfügbar:</p>
<form id="loginForm">
<div class="grid">
<div>
@ -91,7 +95,7 @@
currentToken = token;
if (token) {
sessionStorage.setItem(tokenKey, token);
loginStatus.textContent = 'Angemeldet';
loginStatus.textContent = 'Angemeldet (Token gespeichert)';
} else {
sessionStorage.removeItem(tokenKey);
loginStatus.textContent = 'Nicht angemeldet';
@ -107,11 +111,31 @@
async function api(path, options = {}) {
const headers = { ...authHeaders(), ...(options.headers || {}) };
const res = await fetch(path, { ...options, headers });
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
const res = await fetch(path, { ...options, headers, credentials: 'same-origin' });
if (!res.ok) {
const text = await res.text();
const error = new Error(text || `${res.status} ${res.statusText}`);
error.status = res.status;
throw error;
}
return res.json();
}
async function checkSession() {
try {
const data = await api('/me');
loginStatus.textContent = `Angemeldet als ${data.user} (${data.auth_mode})`;
return true;
} catch (err) {
if (err.status === 401) {
loginStatus.textContent = 'Nicht angemeldet';
} else {
loginStatus.textContent = `Session-Check fehlgeschlagen: ${err.message}`;
}
return false;
}
}
async function refreshUsers() {
statusDiv.textContent = 'Lade...';
try {
@ -149,6 +173,10 @@
}
});
document.getElementById('oidcLogin').addEventListener('click', () => {
window.location.href = '/login/oidc/start';
});
document.getElementById('refreshBtn').addEventListener('click', refreshUsers);
document.getElementById('actionForm').addEventListener('submit', async (e) => {
@ -176,6 +204,8 @@
resultDiv.textContent = `Fehler: ${err.message}`;
}
});
checkSession();
</script>
</body>
</html>