109 lines
4.1 KiB
HTML
109 lines
4.1 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 */
|
|
}
|
|
.section a, .section button {
|
|
display: inline-block;
|
|
padding: 0.4em;
|
|
margin-right: 0.3em;
|
|
border: none;
|
|
background: #aaa2;
|
|
color: inherit;
|
|
font: inherit;
|
|
text-decoration: none;
|
|
cursor: pointer;
|
|
}
|
|
</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>
|
|
<a href="/auth/">👤 User Profile</a>
|
|
<a href="/auth/admin/">⚙️ Admin Panel</a>
|
|
</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="profileDemo()">👤 Login/Profile</button>
|
|
<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). If not authenticated, you'll see the login page; after auth, a 204 response (blank page = success). Back returns here:</p>
|
|
<a href="/auth/api/forward">🔐 Basic Auth</a>
|
|
<a href="/auth/api/forward?max_age=10s">🔄 Reauth (max_age=10s)</a>
|
|
<a href="/auth/api/forward?perm=auth:admin">🛡️ Admin Only</a>
|
|
</div>
|
|
|
|
<pre id="output">Click a button to test...</pre>
|
|
</div>
|
|
</div>
|
|
|
|
<script type="module">
|
|
import { apiFetch, apiJson, AuthCancelledError, profile } from '/paskia-js/dist/paskia.js'
|
|
|
|
function log(msg) {
|
|
console.log(msg)
|
|
document.getElementById('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')
|
|
}
|
|
|
|
// Profile dialog: resolves 'login' / 'logout' / 'back'
|
|
window.profileDemo = async function() {
|
|
log(`Profile return: ${await profile()}`)
|
|
}
|
|
|
|
</script>
|
|
</body>
|
|
</html>
|