gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit6bfbd3f26bfbd3f2ident#45: docs/IDENT.md, what ident is and how it works; CONCEPT.md marks one id per app as droppedmre6bfbd3f2/components/embed.hl

6.1 KB

  1. // components/embed.hl — `/embed/signin?key=<api key>&return=<url>` (ident#31): THE SELECTOR'S SIGN-IN, shown inside the selector's
  2. // panel on an app's page (an iframe; lib/api.hl embedSignin checks key + return, parks the request like the login button and allows
  3. // framing only by the app's registered origins). Signed out of ident: email → code → the identity list, all in this frame, with one
  4. // note that this signs the user in to ident. Choosing an identity, and the way on for a NEW address, are plain links with
  5. // target="_top": the whole app page then goes to `<return>?ident_code=<code>` (lib/api.hl embedGo), the flow every app handles.
  6. // A new address (the account is created by the first right code) is sent on to ident in the same tab (`/signin/<rid>/welcome`)
  7. // to name its identity and pick it; ident then sends the browser back to the page it came from.
  8. parent './embedshell.hl'
  9. import { accountOfSession } from '../lib/accounts.hl'
  10. import { signInWithCode } from '../lib/login.hl'
  11. import { identityRows } from '../lib/identities.hl'
  12. import { requestOf } from '../lib/apps.hl'
  13. session = null
  14. rid = null
  15. me = accountOfSession(session)
  16. request = rid != null ? requestOf(rid) : null
  17. appName = request != null ? request.app.name : ''
  18. identities = me != null ? identityRows(me.id) : []
  19. // the steps (a View's `if` takes a member): email → code → choose (or `fresh` for a new address)
  20. askEmail = me == null
  21. askCode = false
  22. choose = me != null
  23. fresh = false
  24. email = ''
  25. sentTo = ''
  26. code = ''
  27. message = ''
  28. rowsOf = (list) => {
  29. out = []
  30. for (row of list) { out.push({ label = row.label shortId = row.shortId href = '/embed/go?rid=' + rid + '&identity=' + row.id }) }
  31. return out
  32. }
  33. choices = rowsOf(identities)
  34. newHref = '/signin/' + rid + '/welcome'
  35. View {
  36. embedCard {
  37. if (askEmail) {
  38. fitMark { on animationstart(e) { emit fit(e) } on animationiteration(e) { emit fit(e) } }
  39. p { id = "embednote" class = "lead" "This signs you in to ident. We mail you a one-time code." }
  40. form { id = "emailform"
  41. on submit(e) {
  42. e.preventDefault()
  43. emit ask(e)
  44. }
  45. label { "Email"
  46. input { id = "email" name = "email" type = "email" autocomplete = "email" required = "required" value = email on input(e) { emit setEmail(e.target.value) } }
  47. }
  48. button { id = "sendcode" type = "submit" "Send me a code" }
  49. }
  50. }
  51. if (askCode) {
  52. fitMark { on animationstart(e) { emit fit(e) } on animationiteration(e) { emit fit(e) } }
  53. p { id = "sentto" class = "lead" "We sent a six-digit code to " strong { sentTo } "." }
  54. form { id = "codeform"
  55. on submit(e) {
  56. e.preventDefault()
  57. emit verify(e)
  58. }
  59. label { "One-time code"
  60. input { id = "code" name = "code" autocomplete = "one-time-code" inputmode = "numeric" pattern = "[0-9]{6}" maxlength = "6" required = "required" value = code on input(e) { emit setCode(e.target.value) } }
  61. }
  62. formButtons {
  63. button { id = "verify" type = "submit" "Sign in" }
  64. button { id = "back" type = "button" class = "quiet" "Other address" on click(e) { emit back(e) } }
  65. }
  66. }
  67. }
  68. if (choose) {
  69. fitMark { on animationstart(e) { emit fit(e) } on animationiteration(e) { emit fit(e) } }
  70. p { class = "lead" "You are signed in to ident. Choose the identity to log in to " strong { appName } " with." }
  71. ul { id = "chooselist"
  72. for (row of choices) {
  73. li { class = "choice"
  74. identityMain { identityLabel { row.label } identityShortId { class = "shortid" row.shortId } }
  75. a { class = "choose button" target = "_top" href = row.href "Continue" }
  76. }
  77. }
  78. }
  79. }
  80. if (fresh) {
  81. fitMark { on animationstart(e) { emit fit(e) } on animationiteration(e) { emit fit(e) } }
  82. p { id = "freshnote" class = "lead" "This address is new to ident, so it has an account now. Create your identity on ident: it takes you there and brings you back to this page." }
  83. a { id = "gonew" class = "button" target = "_top" href = newHref "Create my identity" }
  84. }
  85. p { id = "message" class = "message" message }
  86. }
  87. }
  88. // THE FRAME'S HEIGHT: the selector (selector.js) cannot read this page's height across origins, so the page tells it. Every step has a
  89. // fitMark whose CSS animation starts when the step appears (and repeats each second for a resize or a message): then the page's content
  90. // height goes to the parent window. No JavaScript of ours; selector.js accepts it from ident's origin only.
  91. on fit(e) {
  92. // the card's bottom edge, not the document's height (the document is as tall as the frame, so it could never shrink)
  93. card = document.querySelector('embed-card')
  94. if (card != null) { window.parent.postMessage({ identFrameHeight = Math.ceil(card.getBoundingClientRect().bottom + window.scrollY) }, '*') }
  95. }
  96. on setEmail(v) { email = v }
  97. on setCode(v) { code = v }
  98. browserZone = () => { return Intl.DateTimeFormat().resolvedOptions().timeZone }
  99. // the code request is the same plain POST as on the login page: only an HTTP request carries the client IP the per-IP limit counts
  100. on ask(e) {
  101. message = ''
  102. res = fetch('/api/code', { method = 'POST' headers = { 'Content-Type' = 'application/json' } body = JSON.stringify({ email = email }) })
  103. r = res != null ? res.json() : null
  104. if (r == null) {
  105. message = 'the server did not answer — try again'
  106. return null
  107. }
  108. if (r.error != null) {
  109. message = r.error
  110. return null
  111. }
  112. sentTo = r.email
  113. code = ''
  114. askEmail = false
  115. askCode = true
  116. }
  117. on verify(e) {
  118. message = ''
  119. r = emit server verifyEmbedCode(sentTo, code, browserZone())
  120. if (r == null) {
  121. message = 'the server did not answer — try again'
  122. return null
  123. }
  124. if (r.error != null) {
  125. message = r.error
  126. return null
  127. }
  128. askCode = false
  129. identities = r.identities
  130. choices = rowsOf(r.identities)
  131. if (r.created) {
  132. fresh = true
  133. } else {
  134. choose = true
  135. }
  136. }
  137. on back(e) {
  138. message = ''
  139. askCode = false
  140. askEmail = true
  141. }
  142. on server verifyEmbedCode(email, code, timeZone, session) {
  143. if (session == null) { return { error = 'no session — reload the page' } }
  144. if (email == null || hlTypeName(email) != 'String' || code == null || hlTypeName(code) != 'String') { return { error = 'email and code must be strings' } }
  145. return signInWithCode(session, email, code, timeZone)
  146. }

Branches

Latest commits

  • 6bfbd3f2ident#45: docs/IDENT.md, what ident is and how it works; CONCEPT.md marks one id per app as droppedmre
  • 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