Files
Wallos/logout.php
Ali Khattab b9567c3d2e Add declarative OIDC (#1056)
* feat(oidc): add declarative runtime configuration

* feat(admin): reflect env-managed oidc settings

* docs(oidc): document environment variables

* chore: match repo line endings and dedupe compose comment

---------

Co-authored-by: Miguel Ribeiro <k.d.mitnick@gmail.com>
2026-07-09 22:54:12 +02:00

64 lines
1.7 KiB
PHP

<?php
require_once 'includes/connect.php';
require_once 'includes/oidc_settings.php';
$secondsInMonth = 30 * 24 * 60 * 60;
if (session_status() === PHP_SESSION_NONE) {
session_set_cookie_params([
'lifetime' => $secondsInMonth,
'httponly' => true,
'samesite' => 'Lax'
]);
session_start();
}
$logoutOIDC = false;
// Check if user is logged in with OIDC
if (isset($_SESSION['from_oidc']) && $_SESSION['from_oidc'] === true) {
$logoutOIDC = true;
$oidcConfiguration = wallos_get_effective_oidc_configuration($db);
$oidcSettings = $oidcConfiguration['settings'];
$logoutUrl = $oidcSettings['logout_url'] ?? '';
}
// get token from cookie to remove from DB
if (isset($_SESSION['token'])) {
$token = $_SESSION['token'];
$sql = "DELETE FROM login_tokens WHERE token = :token AND user_id = :userId";
$stmt = $db->prepare($sql);
$stmt->bindParam(':token', $token, SQLITE3_TEXT);
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
$stmt->execute();
}
$_SESSION = array();
session_destroy();
$cookieExpire = time() - 3600;
setcookie('wallos_login', '', $cookieExpire);
$db->close();
if ($logoutOIDC && !empty($logoutUrl)) {
$returnTo = urlencode($oidcSettings['redirect_url'] ?? '');
header("Location: $logoutUrl?post_logout_redirect_uri=$returnTo");
exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<script>
async function clearAndRedirect() {
if ('caches' in window) {
await caches.delete('pages-cache-v1');
}
sessionStorage.removeItem('sw_prefetched');
window.location.href = '.';
}
clearAndRedirect();
</script>
</head>
<body></body>
</html>
<?php
exit();