98 lines
3.9 KiB
HTML
98 lines
3.9 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Paskia - Dev Mode</title>
|
|
<style>
|
|
:root {
|
|
color-scheme: light dark; /* Automatic themes by browser */
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<header>
|
|
<h1>🔐 Paskia - Development Server</h1>
|
|
<p class="subtitle">The following features are available after you have registered your Admin account and logged in. You should also use the Admin Site to create non-privileged users to see the Forbidden dialog caused by missing permissions.</p>
|
|
</header>
|
|
|
|
<div class="content">
|
|
<div class="section">
|
|
<h2>Management Site</h2>
|
|
<button onclick="window.open('/auth/', '_blank')">👤 User Profile</button>
|
|
<button onclick="window.open('/auth/admin/', '_blank')">⚙️ Admin Panel</button>
|
|
</div>
|
|
|
|
<div class="section">
|
|
<h2>API Mode (not leaving the page)</h2>
|
|
<p>For SPAs and fetch() calls - shows auth in an iframe overlay:</p>
|
|
<button onclick="apiCall('/auth/api/user-info', 'GET')">📋 Get User Info</button>
|
|
<button onclick="apiCall('/auth/api/forward?max_age=10s')">🔄 Reauth (max_age=10s)</button>
|
|
<button onclick="apiCall('/auth/api/forward?perm=auth:admin')">🛡️ Admin Only</button>
|
|
<button onclick="logout()">🚪 Logout</button>
|
|
</div>
|
|
|
|
<div class="section">
|
|
<h2>Browser Mode (full page)</h2>
|
|
<p>Block access to otherwise open site - intended for forward-auth mechanism (Caddy, Nginx):</p>
|
|
<button onclick="browserNav('/auth/api/forward')">🔐 Basic Auth</button>
|
|
<button onclick="browserNav('/auth/api/forward?max_age=10s')">🔄 Reauth (max_age=10s)</button>
|
|
<button onclick="browserNav('/auth/api/forward?perm=auth:admin')">🛡️ Admin Only</button>
|
|
</div>
|
|
|
|
<pre id="output">Click a button to test...</pre>
|
|
</div>
|
|
</div>
|
|
|
|
<script type="module">
|
|
import { apiFetch, apiJson, AuthCancelledError } from '/paskia-js/dist/paskia.js'
|
|
|
|
const output = document.getElementById('output');
|
|
|
|
function log(msg) {
|
|
output.textContent = msg;
|
|
}
|
|
|
|
// Make an API call using paskia module (handles 401/403 automatically)
|
|
window.apiCall = async function(url, method = 'GET') {
|
|
log(`${method} ${url}...`);
|
|
try {
|
|
const response = await apiFetch(url, { method });
|
|
|
|
// Forward endpoint returns 204 on success
|
|
if (response.status === 204) {
|
|
log('✓ Success (204 No Content)');
|
|
return;
|
|
}
|
|
|
|
if (!response.ok) {
|
|
log(`Error: ${response.status} ${response.statusText}`);
|
|
return;
|
|
}
|
|
|
|
const data = await response.json();
|
|
log('✓ Response:\n' + JSON.stringify(data, null, 2));
|
|
} catch (e) {
|
|
if (e instanceof AuthCancelledError) {
|
|
log('Authentication cancelled');
|
|
} else {
|
|
log(`Error: ${e.message}`);
|
|
}
|
|
}
|
|
}
|
|
|
|
window.logout = async function() {
|
|
await fetch('/auth/api/logout', { method: 'POST' });
|
|
log('Logged out');
|
|
}
|
|
|
|
// Browser mode: open the forward endpoint directly in a new window.
|
|
window.browserNav = function(url) {
|
|
log('Opening in new window...\nIf not authenticated, you\'ll see the login page.\nAfter auth, you\'ll see a 204 response (blank page = success).');
|
|
window.open(url, '_blank');
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|