ident
All repositories: gitoria
7.8 KB
// components/apps.hl — `/apps`: THE ACCOUNT'S APPS (piece 2 of 6, ticket #25; CONCEPT.md// "Apps: any ident user can register apps. An app gets an API key.").// Register (name + the origins it runs on), list, edit, new secret, delete. An app has a// public API key and a secret for its server; the secret is shown ONCE, right after it is// made — ident stores only its sha256.//// The faces' names start with `app…`: a face is found by its EVENT NAME across all// files (hl:web), so they must not collide with home.hl's.parent './main.hl'import { accountOfSession } from '../lib/accounts.hl'import { appRows, createApp, updateApp, regenerateSecret, deleteApp } from '../lib/apps.hl'import { siteName } from '../project.hl'session = nullme = accountOfSession(&session)signedIn = me != nullsignedOut = me == nullmeEmail = me != null ? me.email : ''apps = me != null ? appRows(me.id) : []hasApps = apps.length > 0noApps = apps.length == 0__title = siteName + ' | your apps'// THE APP FORM — new and editediting = falseeditId = '' // '' = a new app, else the app's id (a UUID)editHeading = ''fName = ''fOrigins = ''// THE SECRET, shown onceshowSecret = falsesecretFor = ''secret = ''message = ''notice = ''View {identCard {if (signedOut) {h1 { "Your apps" }p { id = "signinfirst" class = "lead" "Sign in to ident first: " a { href = "/" "sign in" } "." }}if (signedIn) {accountBar {userEmail { id = "meemail" meEmail }a { id = "toidentities" href = "/" "Your identities" }}if (showSecret) {secretBox { id = "secretbox"h2 { "Secret of " secretFor }p { class = "lead" "Shown only now — copy it to your app's server. Its API calls (the code exchange) use it; it never goes into a web page. Lost it? Make a new one." }code { id = "secret" secret }button { id = "secretdone" type = "button" class = "small" "I copied it" on click(e) { emit hideSecret(e) } }}}if (editing) {form { id = "appform"on submit(e) {e.preventDefault()emit saveApp(e)}h1 { id = "appformheading" editHeading }label { "Name"input { id = "fappname" name = "name" maxlength = "60" autocomplete = "off" required = "required" value = fName on input(e) { emit setName(e.target.value) } }}label { "Origins " fieldHint { "(where the app runs, like https://tickets.worldapi.org — several separated by spaces; the login button only returns there)" }input { id = "forigins" name = "origins" autocomplete = "off" required = "required" value = fOrigins on input(e) { emit setOrigins(e.target.value) } }}formButtons {button { id = "saveapp" type = "submit" "Save" }button { id = "cancelapp" type = "button" class = "quiet" "Cancel" on click(e) { emit closeForm(e) } }}}}section { id = "appssection"sectionHead {h1 { "Your apps" }button { id = "newapp" type = "button" class = "small" "Register an app" on click(e) { emit openNew(e) } }}if (noApps) { p { id = "noapps" class = "lead" "No apps yet. An app you register gets an API key for its “login with ident” button." } }ul { id = "apps"for (row of apps) {li { class = "app"appMain {appName { row.name }appOrigins { row.originsText }appKey { "API key " code { class = "apikey" row.apiKey } }}identityActions {button { type = "button" class = "quiet small edit" value = row.id "Edit" on click(e) { emit openEdit(e.target.value) } }button { type = "button" class = "quiet small newsecret" value = row.id "New secret" on click(e) { emit renew(e.target.value) } }button { type = "button" class = "quiet small danger delete" value = row.id "Delete" on click(e) { emit remove(e.target.value) } }}}}}}}p { id = "notice" class = "notice" notice }p { id = "message" class = "message" message }}}on setName(v) { fName = v }on setOrigins(v) { fOrigins = v }rowOf = (id) => {for (row of apps) { if ('' + row.id == '' + id) { return row } }return null}// the origins field: words separated by spaces or commasoriginList = (text) => {out = []for (w of text.replaceAll(',', ' ').split(' ')) {let t = w.trim()if (t != '') { out.push(t) }}return out}setApps = (list) => {apps = listhasApps = list.length > 0noApps = list.length == 0return null}on openNew(e) {message = ''notice = ''editId = ''fName = ''fOrigins = ''editHeading = 'Register an app'editing = true}on openEdit(id) {message = ''notice = ''row = rowOf(id)if (row == null) { return null }editId = row.idfName = row.namefOrigins = row.originsTexteditHeading = 'Edit ' + row.nameediting = true}on closeForm(e) {editing = falsemessage = ''}on hideSecret(e) {showSecret = falsesecret = ''secretFor = ''}on saveApp(e) {message = ''notice = ''input = { name = fName origins = originList(fOrigins) }let r = nullif (editId == '') {r = emit server appCreate(input)} else {r = emit server appUpdate('' + editId, input)}if (r == null) {message = 'the server did not answer — try again'return null}if (r.error != null) {message = r.errorreturn null}setApps(r.apps)editing = falseif (r.secret != null) {secretFor = r.app.namesecret = r.secretshowSecret = truenotice = 'App registered.'} else {notice = 'App saved.'}}on renew(id) {message = ''notice = ''row = rowOf(id)if (row == null) { return null }if (!confirm('Make a new secret for “' + row.name + '”? The current one stops working at once.')) { return null }r = emit server appNewSecret('' + id)if (r == null) {message = 'the server did not answer — try again'return null}if (r.error != null) {message = r.errorreturn null}setApps(r.apps)secretFor = r.app.namesecret = r.secretshowSecret = truenotice = 'New secret made.'}on remove(id) {message = ''notice = ''row = rowOf(id)if (row == null) { return null }if (!confirm('Delete the app “' + row.name + '”? Its API key stops working and the ids its users had in it are gone.')) { return null }r = emit server appDelete('' + id)if (r == null) {message = 'the server did not answer — try again'return null}if (r.error != null) {message = r.errorreturn null}setApps(r.apps)if ('' + editId == '' + id) { editing = false }showSecret = falsesecret = ''notice = 'App deleted.'}// ---- the faces ------------------------------------------------------------------------// The LAST parameter is the session (the framework appends it); accountOfSession only// gets the framework's own Session (hl:web never takes it from the peer, hybriel#16/#31).on server appCreate(input, session) {let me = accountOfSession(&session)if (me == null) { return { error = 'you are not signed in' } }r = createApp(me.id, input)if (r.error != null) { return r }return { app = r.app secret = r.secret apps = appRows(me.id) }}on server appUpdate(id, input, session) {let me = accountOfSession(&session)if (me == null) { return { error = 'you are not signed in' } }r = updateApp(me.id, id, input)if (r.error != null) { return r }return { app = r.app apps = appRows(me.id) }}on server appNewSecret(id, session) {let me = accountOfSession(&session)if (me == null) { return { error = 'you are not signed in' } }r = regenerateSecret(me.id, id)if (r.error != null) { return r }return { app = r.app secret = r.secret apps = appRows(me.id) }}on server appDelete(id, session) {let me = accountOfSession(&session)if (me == null) { return { error = 'you are not signed in' } }r = deleteApp(me.id, id)if (r.error != null) { return r }return { deleted = r.deleted apps = appRows(me.id) }}
Branches
Latest commits
- c0edca26ident#28 A28G: write & at every call that hands a session to an &-parameter; gate tests/sessionwrites.mjs pins that sign-in, pending address, embed sign-in and selector land in the session filesmre
- 80965c08ident#28: README says the deploy goes through the standbymre
- 2f41670cident#28: ident-standby service on port 45012 (no background round in the standby) and deploy.sh hands over through standby-swap.shmre
- a544b261ident#28: README names the new vendored Hybrielmre
- 716860b0ident#28: gates follow Hybriel ac1ed9da (lazy sessions, meta attribute order, JSON key order, default X-Frame-Options switched off for the embed page)mre
- 889e00fbident#28: Hybriel master ac1ed9da (sessions reload a newer file, a replayed reconnect carries the server session); a startup fault exits 1 (on Error)mre
- f5a55f8aident#11: apps can ask for nickname, firstname and lastname (fields list on /api/exchange, new POST /api/profile); empty fields come back null; gate checks, READMEmre
- d8be66ebident: report and log line for the widget cache and frame height changemre
- 2068f61aident#31: browsers revalidate the widget scripts on every load; the sign-in frame is exactly as tall as the current step (the frame page reports its height, selector.js accepts it from ident only)mre
- a22d2daaident#31: the sign-in frame is no taller than the tallest step needs (plain CSS height per width), gate check for itmre
- a77d1b22ident#31: the welcome form keeps editId a plain value (browser gate), README, wider rows in the framemre
- 5c481bfdident#31: sign in to ident inside the selector's panel (email, code, identity in an iframe; a new address goes to ident in the same tab and comes back)mre
- 061abfe2ident: the apps gate waits until the test app's login button stops moving before it clicks (the page grows after load and the click missed about every second run)mre
- 45f7e4daident: the user menu's Sign out waits for the server before it reloads (the apps gate failed because the session could still be signed in)mre
- f07658c7ident: home page shows the account once (account bar removed, the user menu carries email, Sign out, Sign out everywhere); wildcard origins https://*.domain for apps on many subdomains; gates follow (WIP: gates not re-run after the last edits)mre
- f2c43bbbtheme: sync from layouts 4994037 (list rows stack, td word-keep, heading code, edited tap target)mre
- 6d4f996esessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
- 029eb5e5deploy: security gate (tests/security.mjs)mre
- d3c065a8security audit (SI): uploadMax 0, Secure __Host- cookie behind https, headers on function routes/files, page CSP+referrer meta, app/identity caps, tests/security.mjs, reportmre
- 5561a0cbreport I4-mobilemre