roledesk is built on the boilerplate from here on: pipeline 2.0 (queue and scheduler), auth (one password, sessions, passkeys), the deploy kit and its docs, plus the coupling and packaging tests. Downstream copies, unedited. Refreshed from boilerplate/d56949f7d0f6c0bfe5745478e09007bfad67ae87 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
175 lines
7.2 KiB
HTML
175 lines
7.2 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>{name} — sign in</title>
|
|
<!-- The app's own stylesheet, if it passed one to `connect`. Optional on
|
|
purpose: this folder is copied into projects that have no stylesheet yet,
|
|
and a login page that only looks right once something else exists is one
|
|
more thing to get working before you can get in. The CSS below is enough
|
|
on its own, and is overridden by anything the app loads after it. -->
|
|
{stylesheet}
|
|
<style>
|
|
:root { color-scheme: light dark; --ink: #1a1a1f; --paper: #fbfbfd; --line: #d9d9e3; --dim: #63636e; --bad: #b91c1c; }
|
|
@media (prefers-color-scheme: dark) {
|
|
:root { --ink: #e9e9ef; --paper: #15151a; --line: #33333d; --dim: #9a9aa8; --bad: #f87171; }
|
|
}
|
|
body.login {
|
|
margin: 0; min-height: 100dvh; display: grid; place-items: center;
|
|
background: var(--paper); color: var(--ink);
|
|
font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
|
|
}
|
|
.signin { width: min(22rem, calc(100vw - 2rem)); padding: 1rem; text-align: center; }
|
|
.wordmark { font-size: 1.4rem; font-weight: 700; letter-spacing: 0.02em; margin-bottom: 1.25rem; }
|
|
.signin form { display: grid; gap: 0.5rem; text-align: left; }
|
|
.signin label { font-size: 0.85rem; color: var(--dim); }
|
|
.signin input[type=password] {
|
|
font: inherit; padding: 0.5rem 0.6rem; border-radius: 8px;
|
|
border: 1px solid var(--line); background: transparent; color: inherit;
|
|
}
|
|
.signin button {
|
|
font: inherit; padding: 0.45rem 0.9rem; border-radius: 8px; cursor: pointer;
|
|
border: 1px solid var(--line); background: transparent; color: inherit;
|
|
}
|
|
.signin button.go { border-color: transparent; background: #4f46e5; color: #fff; }
|
|
.signin button[disabled] { opacity: 0.55; cursor: progress; }
|
|
.orpass { margin-top: 1rem; display: grid; gap: 0.5rem; justify-items: center; }
|
|
.orpass span { color: var(--dim); font-size: 0.85rem; }
|
|
.why { margin-top: 1rem; color: var(--bad); }
|
|
/* `hidden` is a browser default of `display: none` and any class rule with a
|
|
* `display` in it beats that, so both of the elements this page hides need
|
|
* saying twice. Without it the passkey button is drawn on an app that has no
|
|
* passkeys, and pressing it 404s. */
|
|
[hidden] { display: none !important; }
|
|
</style>
|
|
</head>
|
|
<body class="login">
|
|
|
|
<!-- Its own page rather than an overlay on the app, because the app is the
|
|
thing being protected: serving its markup to someone who has not signed in
|
|
and hiding it with CSS would put the whole page in the source behind a lock
|
|
that is decoration. Nothing here is fetched from the API, and there is
|
|
nothing on this page a signed-out browser could not already see. -->
|
|
<main class="signin">
|
|
<div class="wordmark">{name}</div>
|
|
|
|
<form id="signin" autocomplete="on">
|
|
<!-- A hidden username field with a stable value. There is no username in
|
|
this application, but a password manager will not reliably offer to
|
|
save a lone password field, and the one it does save has nothing to key
|
|
on. This gives it a key without inventing a login. -->
|
|
<input type="text" name="username" value="{name}" autocomplete="username"
|
|
hidden aria-hidden="true" tabindex="-1">
|
|
|
|
<label for="password">Password</label>
|
|
<input type="password" id="password" name="password" required autofocus
|
|
autocomplete="current-password">
|
|
|
|
<button type="submit" class="go" id="go">Sign in</button>
|
|
</form>
|
|
|
|
<!-- Shown only when this app has a passkey registered *and* the browser can
|
|
use one. Hidden by default rather than shown and then removed, so a
|
|
browser that cannot do WebAuthn never flashes a button it will withdraw. -->
|
|
<div class="orpass" id="orpass" hidden>
|
|
<span>or</span>
|
|
<button type="button" class="passkey" id="use-passkey">Use a passkey</button>
|
|
</div>
|
|
|
|
<p class="why" id="why" role="alert" hidden></p>
|
|
</main>
|
|
|
|
<script src="/_auth/passkey.js"></script>
|
|
<script>
|
|
// The password half. The passkey half is `/_auth/passkey.js`, shared with the
|
|
// account element, because both need the same base64url conversions.
|
|
//
|
|
// This page has its own `post()` rather than the app's `api()` helper, and that
|
|
// is deliberate: `api()` answers a 401 by sending you here, and a login page
|
|
// that redirects to itself on a wrong password is one that silently clears the
|
|
// field and looks broken. It is also the one page that has to work before the
|
|
// app's own scripts are loaded at all.
|
|
const form = document.querySelector('#signin');
|
|
const why = document.querySelector('#why');
|
|
const go = document.querySelector('#go');
|
|
|
|
// Read from the address bar rather than posted into the page, so the value is
|
|
// never interpolated into markup. The server sanitises it again on the way back
|
|
// -- see `_safe_next` -- because this half runs on the attacker's side of the
|
|
// fence and proves nothing.
|
|
const next = new URLSearchParams(location.search).get('next') || '/';
|
|
|
|
function fail(message) {
|
|
why.textContent = message;
|
|
why.hidden = false;
|
|
}
|
|
|
|
// ------------------------------------------------------------------- passkey
|
|
|
|
// Substituted by `auth/router.py`: is there a passkey registered here at all.
|
|
const passkeysOffered = {passkeys};
|
|
|
|
if (passkeysOffered && window.passkey && window.passkey.supported()) {
|
|
const orpass = document.querySelector('#orpass');
|
|
const button = document.querySelector('#use-passkey');
|
|
orpass.hidden = false;
|
|
|
|
button.onclick = async () => {
|
|
why.hidden = true;
|
|
button.disabled = true;
|
|
button.textContent = 'Waiting for your passkey...';
|
|
try {
|
|
const options = await post('/login/passkey/options');
|
|
const signed = await window.passkey.get(options);
|
|
// Nothing to carry over: a passkey login always lands on the front page.
|
|
// `next` exists for the password form because a 401 redirect can carry a
|
|
// deep link, and this button is never reached that way.
|
|
location.assign((await post('/login/passkey', {credential: signed})).next || '/');
|
|
return;
|
|
} catch (err) {
|
|
fail(window.passkey.explain(err));
|
|
}
|
|
button.disabled = false;
|
|
button.textContent = 'Use a passkey';
|
|
};
|
|
}
|
|
|
|
// ------------------------------------------------------------------ password
|
|
|
|
async function post(path, body) {
|
|
const r = await fetch(path, {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: JSON.stringify(body || {}),
|
|
});
|
|
if (!r.ok) {
|
|
let detail = '';
|
|
try { detail = (await r.json()).detail || ''; } catch { /* not JSON */ }
|
|
throw new Error(detail || `Sign-in failed (${r.status})`);
|
|
}
|
|
return r.json();
|
|
}
|
|
|
|
form.onsubmit = async (e) => {
|
|
e.preventDefault();
|
|
const password = document.querySelector('#password').value;
|
|
why.hidden = true;
|
|
go.disabled = true;
|
|
go.textContent = 'Signing in...';
|
|
try {
|
|
// `location.assign` rather than setting `.href` to the raw value: the
|
|
// server has already reduced `next` to a local path, and this keeps the
|
|
// navigation an ordinary one.
|
|
location.assign((await post('/login', {password, next})).next || '/');
|
|
} catch (err) {
|
|
fail(String(err).replace('Error: ', ''));
|
|
go.disabled = false;
|
|
go.textContent = 'Sign in';
|
|
form.password.select();
|
|
}
|
|
};
|
|
</script>
|
|
</body>
|
|
</html>
|