auth

Main authentication module for my projects
git clone git://git.finwo.net/app/auth
Log | Files | Refs

commit 7a04adeb3e6cc6dc68c9d88488be63ecd73fd6be
parent eb9919267f5709f5d61f6d244c74bea733e55ff1
Author: finwo <finwo@pm.me>
Date:   Sun,  8 Nov 2026 00:29:59 +0100

Mocked up client-host assignment panel and generalized table-in-panel styling

Diffstat:
Mapp/shared/style/global.css | 25+++++++++++++++++++++++++
Mmockup/plain/admin-client-detail.html | 391+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mmockup/plain/global.css | 25+++++++++++++++++++++++++
3 files changed, 441 insertions(+), 0 deletions(-)

diff --git a/app/shared/style/global.css b/app/shared/style/global.css @@ -961,6 +961,31 @@ html.mobile-nav-open .mobile-nav .nav-item { height: 1.125rem; } +/* Data tables embedded inside a panel: align to panel content, use row rules */ +.panel .table-toolbar { + padding: 0; + margin: 1.25rem 0 1rem; + background: transparent; + box-shadow: none; + border-bottom: 0; +} + +.panel .data-table tbody tr { + padding: 0; + background: transparent; + box-shadow: none; +} + +.panel .data-table th, +.panel .data-table td { + padding-right: 0; + padding-left: 0; +} + +.panel .data-table tbody tr:last-child td { + border-bottom: 0; +} + .modal-overlay { position: fixed; inset: 0; diff --git a/mockup/plain/admin-client-detail.html b/mockup/plain/admin-client-detail.html @@ -5,6 +5,102 @@ <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" /> <title>Admin client detail mockup</title> <link rel="stylesheet" href="./global.css" /> + <style> + .host-name { + font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; + font-size: 0.8125rem; + overflow-wrap: anywhere; + } + + .host-added { + color: var(--muted); + font-size: 0.8125rem; + } + + .host-row-action { + display: flex; + align-items: center; + } + + .action-button { + display: inline-flex; + align-items: center; + min-height: 2rem; + padding: 0.25rem 0.625rem; + border: 0; + border-radius: 0.25rem; + background: transparent; + color: var(--muted); + font: inherit; + font-size: 0.8125rem; + font-weight: 500; + line-height: 1.4; + white-space: nowrap; + cursor: pointer; + } + + .action-button:hover { + background: var(--row-hover); + color: var(--text); + } + + .action-button:first-child { + margin-left: -0.625rem; + } + + .action-button.is-danger { + color: var(--danger-text); + } + + .action-button.is-danger:hover { + background: color-mix(in oklch, var(--danger) 12%, transparent); + color: var(--danger-text); + } + + .host-table td.host-action-column { + padding-bottom: 0.75rem; + } + + .empty { + padding: 2rem; + color: var(--muted); + font-size: 0.875rem; + } + + .empty p { + margin: 0; + } + + @media (max-width: 39.999em) { + .table-actions { + width: 100%; + flex-direction: column; + align-items: stretch; + } + + .table-actions .button { + width: 100%; + } + } + + @media (min-width: 40em) { + .host-table { + table-layout: fixed; + } + + .host-table .host-added-column { + width: 10rem; + } + + .host-table .host-action-column { + width: 9rem; + } + + .host-row-action { + justify-content: flex-start; + } + } + </style> </head> <body> <header class="topbar"> @@ -274,6 +370,41 @@ </div> </section> + <section class="panel" aria-labelledby="client-hosts-title"> + <h2 id="client-hosts-title">Hosts</h2> + <p class="note">Hostnames that resolve to this client.</p> + + <div id="client-hosts-notice" class="notice" role="status" hidden></div> + + <div class="table-toolbar"> + <div class="table-search"> + <input id="client-hosts-search" type="search" aria-label="Search hosts" placeholder="Search hosts" /> + </div> + <div class="table-actions"> + <button id="client-hosts-add-button" class="button" type="button">Add host</button> + </div> + </div> + + <div class="data-table-wrap"> + <table class="data-table data-table-static host-table"> + <thead> + <tr> + <th class="data-table-primary host-name-column" scope="col">Hostname</th> + <th class="host-added-column" scope="col">Added</th> + <th class="host-action-column" scope="col">Actions</th> + </tr> + </thead> + <tbody id="client-hosts-rows"></tbody> + </table> + <div id="client-hosts-search-empty" class="empty" hidden> + <p>No hosts match this search.</p> + </div> + <div id="client-hosts-empty" class="empty" hidden> + <p>No hosts are assigned to this client.</p> + </div> + </div> + </section> + <section class="panel danger-zone"> <h2>Danger zone</h2> <p class="note">Deleting removes the client registration and related authorization state.</p> @@ -309,6 +440,60 @@ </div> </div> + <div id="client-hosts-create-dialog" class="modal-overlay" hidden> + <form id="client-hosts-create-form" class="modal" role="dialog" aria-modal="true" aria-labelledby="client-hosts-create-title" novalidate> + <div class="modal-header"> + <h2 id="client-hosts-create-title">Add host</h2> + <button class="modal-close" type="button" aria-label="Close dialog" data-dialog-close> + <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> + <path d="M18 6 6 18" /> + <path d="m6 6 12 12" /> + </svg> + </button> + </div> + <div class="modal-body"> + <div id="client-hosts-create-alert" class="alert" role="alert" hidden></div> + + <label class="form-field" for="client-hosts-host-input"> + <span class="field-label">Hostname</span> + <input id="client-hosts-host-input" class="field-control" type="text" maxlength="253" placeholder="app.acme.test" autocomplete="off" spellcheck="false" /> + </label> + <p class="modal-note">Lowercase hostname. Do not include a scheme, port, path or wildcard.</p> + + <div class="modal-actions"> + <button class="button-secondary" type="button" data-dialog-close>Cancel</button> + <button class="button" type="submit">Add host</button> + </div> + </div> + </form> + </div> + + <div id="client-hosts-remove-dialog" class="modal-overlay" hidden> + <div class="modal" role="dialog" aria-modal="true" aria-labelledby="client-hosts-remove-title"> + <div class="modal-header"> + <h2 id="client-hosts-remove-title">Remove host</h2> + <button class="modal-close" type="button" aria-label="Close dialog" data-dialog-close> + <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> + <path d="M18 6 6 18" /> + <path d="m6 6 12 12" /> + </svg> + </button> + </div> + <div class="modal-body"> + <p id="client-hosts-remove-message" class="modal-note"></p> + <label class="form-field" for="client-hosts-remove-confirm"> + <span class="field-label">Confirm hostname</span> + <input id="client-hosts-remove-confirm" class="field-control" type="text" maxlength="253" autocomplete="off" spellcheck="false" /> + </label> + <p class="modal-note">Type the hostname exactly to confirm.</p> + <div class="modal-actions"> + <button class="button-secondary" type="button" data-dialog-close>Cancel</button> + <button id="client-hosts-remove-confirm-button" class="button-danger" type="button" disabled>Remove host</button> + </div> + </div> + </div> + </div> + <div class="mockup-controls" aria-label="Mockup theme"> <span class="mockup-label">Mockup</span> <button class="mockup-button is-active" type="button" data-theme-target="auto">Auto</button> @@ -389,6 +574,212 @@ } }); </script> + <script> + (function () { + const clientName = 'Internal App'; + const clientId = 'internal-app'; + + const hostAssignments = { + 'app.acme.localhost': { client: clientId }, + 'acme.localhost': { realm: 'Acme' }, + 'login.acme.test': { realm: 'Acme' }, + 'globex.localhost': { realm: 'Globex' }, + 'portal.globex.test': { client: 'globex-portal' }, + 'auth.example.test': { reserved: true }, + }; + + let hosts = [{ host: 'app.acme.localhost', added: '12 Mar 2026' }]; + + const rowsEl = document.getElementById('client-hosts-rows'); + const searchInput = document.getElementById('client-hosts-search'); + const searchEmpty = document.getElementById('client-hosts-search-empty'); + const emptyEl = document.getElementById('client-hosts-empty'); + const notice = document.getElementById('client-hosts-notice'); + const addButton = document.getElementById('client-hosts-add-button'); + + const createDialog = document.getElementById('client-hosts-create-dialog'); + const createForm = document.getElementById('client-hosts-create-form'); + const createAlert = document.getElementById('client-hosts-create-alert'); + const hostInput = document.getElementById('client-hosts-host-input'); + + const removeDialog = document.getElementById('client-hosts-remove-dialog'); + const removeMessage = document.getElementById('client-hosts-remove-message'); + const removeInput = document.getElementById('client-hosts-remove-confirm'); + const confirmRemoveButton = document.getElementById('client-hosts-remove-confirm-button'); + let pendingRemoveHost = ''; + + function escapeHtml(value) { + return String(value).replace(/[&<>"']/g, (character) => { + const entities = { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }; + return entities[character]; + }); + } + + function normalizeHost(value) { + return value.trim().toLowerCase(); + } + + function showNotice(message) { + notice.textContent = message; + notice.hidden = false; + } + + function render() { + rowsEl.replaceChildren( + ...hosts.map((entry) => { + const row = document.createElement('tr'); + row.className = 'host-row'; + row.dataset.search = entry.host.toLowerCase(); + row.innerHTML = + '<td class="data-table-primary host-name-column" data-label="Hostname">' + + '<span class="host-name">' + escapeHtml(entry.host) + '</span>' + + '</td>' + + '<td class="host-added-column" data-label="Added"><span class="host-added">' + escapeHtml(entry.added) + '</span></td>' + + '<td class="host-action-column" data-label="Actions"><div class="host-row-action">' + + '<button class="action-button is-danger" type="button" data-remove-host="' + escapeHtml(entry.host) + '">Remove</button>' + + '</div></td>'; + return row; + }) + ); + applySearch(); + } + + function applySearch() { + const term = searchInput.value.trim().toLowerCase(); + let visible = 0; + [...rowsEl.querySelectorAll('.host-row')].forEach((row) => { + const match = !term || (row.dataset.search || '').includes(term); + row.hidden = !match; + if (match) visible += 1; + }); + searchEmpty.hidden = hosts.length === 0 || visible !== 0; + emptyEl.hidden = hosts.length !== 0; + } + + function hostnameError(raw) { + const value = raw.trim(); + const host = normalizeHost(value); + + if (!host) return 'Hostname is required.'; + if (/\s/.test(value)) return 'Hostname must not contain spaces.'; + if (host.includes('://') || /^[a-z][a-z0-9+.-]*:\/\//i.test(value)) { + return 'Hostname must not include a scheme such as https://.'; + } + if (host.includes('@')) return 'Hostname must not include @.'; + if (host.includes('/')) return 'Hostname must not include a path.'; + if (host.includes('*')) return 'Wildcard hostnames are not supported.'; + if (host.startsWith('[')) { + if (!host.endsWith(']')) return 'Enter a valid IPv6 hostname.'; + } else if (host.includes(':')) { + return 'Hostname must not include a port.'; + } + if (host.length > 253) return 'Hostname must be 253 characters or fewer.'; + if (host.startsWith('.') || host.endsWith('.')) return 'Hostname must not start or end with a dot.'; + + if (!host.startsWith('[')) { + const labels = host.split('.'); + if (labels.length < 2) return 'Enter a complete hostname such as app.acme.test.'; + for (const label of labels) { + if (!/^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/.test(label)) { + return 'Hostname labels may use lowercase letters, numbers and hyphens.'; + } + if (label.length > 63) return 'Each hostname label must be 63 characters or fewer.'; + } + } + + if (hostAssignments[host] && hostAssignments[host].reserved) { + return 'This hostname is reserved for the authentication service.'; + } + + const assignment = hostAssignments[host]; + if (assignment) { + if (assignment.client === clientId) return 'This hostname is already assigned to this client.'; + if (assignment.client) return 'This hostname is already assigned to a client application.'; + if (assignment.realm) return 'This hostname is already assigned to the ' + assignment.realm + ' realm.'; + return 'This hostname is already assigned.'; + } + + return null; + } + + function clearCreateError() { + createAlert.hidden = true; + createAlert.textContent = ''; + hostInput.removeAttribute('aria-invalid'); + } + + function showCreateError(message) { + createAlert.hidden = false; + createAlert.textContent = message; + hostInput.setAttribute('aria-invalid', 'true'); + } + + addButton.addEventListener('click', () => { + createForm.reset(); + clearCreateError(); + createDialog.hidden = false; + requestAnimationFrame(() => hostInput.focus()); + }); + + hostInput.addEventListener('input', clearCreateError); + + createForm.addEventListener('submit', (event) => { + event.preventDefault(); + const error = hostnameError(hostInput.value); + if (error) { + showCreateError(error); + return; + } + + const host = normalizeHost(hostInput.value); + hosts = [{ host, added: 'Just now' }, ...hosts]; + hostAssignments[host] = { client: clientId }; + createDialog.hidden = true; + render(); + showNotice('Host ' + host + ' added.'); + }); + + function openRemoveDialog(host) { + pendingRemoveHost = host; + removeMessage.textContent = + 'Remove ' + host + '? This hostname will stop resolving to ' + clientName + '. ' + + 'Sessions for this client on that host will end. Client settings and users are unaffected.'; + removeInput.value = ''; + removeInput.placeholder = host; + confirmRemoveButton.disabled = true; + removeDialog.hidden = false; + requestAnimationFrame(() => removeInput.focus()); + } + + removeInput.addEventListener('input', () => { + confirmRemoveButton.disabled = normalizeHost(removeInput.value) !== pendingRemoveHost; + }); + + confirmRemoveButton.addEventListener('click', () => { + if (!pendingRemoveHost || confirmRemoveButton.disabled) return; + + hosts = hosts.filter((entry) => entry.host !== pendingRemoveHost); + delete hostAssignments[pendingRemoveHost]; + const removed = pendingRemoveHost; + pendingRemoveHost = ''; + removeDialog.hidden = true; + render(); + showNotice('Host ' + removed + ' removed.'); + }); + + rowsEl.addEventListener('click', (event) => { + const removeButton = event.target.closest('[data-remove-host]'); + if (removeButton) { + event.stopPropagation(); + openRemoveDialog(removeButton.dataset.removeHost); + } + }); + + searchInput.addEventListener('input', applySearch); + + render(); + })(); + </script> <script src="./shell.js"></script> </body> </html> diff --git a/mockup/plain/global.css b/mockup/plain/global.css @@ -908,6 +908,31 @@ html.mobile-nav-open .mobile-nav .nav-item { height: 1.125rem; } +/* Data tables embedded inside a panel: align to panel content, use row rules */ +.panel .table-toolbar { + padding: 0; + margin: 1.25rem 0 1rem; + background: transparent; + box-shadow: none; + border-bottom: 0; +} + +.panel .data-table tbody tr { + padding: 0; + background: transparent; + box-shadow: none; +} + +.panel .data-table th, +.panel .data-table td { + padding-right: 0; + padding-left: 0; +} + +.panel .data-table tbody tr:last-child td { + border-bottom: 0; +} + .client-breadcrumb { display: flex; flex-wrap: wrap;