gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchf2-shellc3a40ff6|||PR ident#40 one shell for the app and /start (account part off on /start, #40.1); startshell.hl removed; unused signOut faces gone (#40.4)mref2-shell/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 (the identity row itself, no extra Continue click), 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. a { class = "choose" target = "_top" href = row.href
  75. identityMain { identityLabel { row.label } identityShortId { class = "shortid" row.shortId } }
  76. }
  77. }
  78. }
  79. }
  80. }
  81. if (fresh) {
  82. fitMark { on animationstart(e) { emit fit(e) } on animationiteration(e) { emit fit(e) } }
  83. 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." }
  84. a { id = "gonew" class = "button" target = "_top" href = newHref "Create my identity" }
  85. }
  86. p { id = "message" class = "message" message }
  87. }
  88. }
  89. // 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
  90. // fitMark whose CSS animation starts when the step appears (and repeats each second for a resize or a message): then the page's content
  91. // height goes to the parent window. No JavaScript of ours; selector.js accepts it from ident's origin only.
  92. on fit(e) {
  93. // the card's bottom edge, not the document's height (the document is as tall as the frame, so it could never shrink)
  94. card = document.querySelector('embed-card')
  95. if (card != null) { window.parent.postMessage({ identFrameHeight = Math.ceil(card.getBoundingClientRect().bottom + window.scrollY) }, '*') }
  96. }
  97. on setEmail(v) { email = v }
  98. on setCode(v) { code = v }
  99. browserZone = () => { return Intl.DateTimeFormat().resolvedOptions().timeZone }
  100. // 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
  101. on ask(e) {
  102. message = ''
  103. res = fetch('/api/code', { method = 'POST' headers = { 'Content-Type' = 'application/json' } body = JSON.stringify({ email = email }) })
  104. r = res != null ? res.json() : null
  105. if (r == null) {
  106. message = 'the server did not answer — try again'
  107. return null
  108. }
  109. if (r.error != null) {
  110. message = r.error
  111. return null
  112. }
  113. sentTo = r.email
  114. code = ''
  115. askEmail = false
  116. askCode = true
  117. }
  118. on verify(e) {
  119. message = ''
  120. r = emit server verifyEmbedCode(sentTo, code, browserZone())
  121. if (r == null) {
  122. message = 'the server did not answer — try again'
  123. return null
  124. }
  125. if (r.error != null) {
  126. message = r.error
  127. return null
  128. }
  129. askCode = false
  130. identities = r.identities
  131. choices = rowsOf(r.identities)
  132. if (r.created) {
  133. fresh = true
  134. } else {
  135. choose = true
  136. }
  137. }
  138. on back(e) {
  139. message = ''
  140. askCode = false
  141. askEmail = true
  142. }
  143. on server verifyEmbedCode(email, code, timeZone, session) {
  144. if (session == null) { return { error = 'no session — reload the page' } }
  145. if (email == null || hlTypeName(email) != 'String' || code == null || hlTypeName(code) != 'String') { return { error = 'email and code must be strings' } }
  146. return signInWithCode(&session, email, code, timeZone)
  147. }

Branches

Latest commits

  • c3a40ff6|||PR ident#40 one shell for the app and /start (account part off on /start, #40.1); startshell.hl removed; unused signOut faces gone (#40.4)mre
  • 060f3870ident#40.4: use the shell sign-out faces in regression gatesmre
  • 9b94aa6aMerge branch 'f1b-cleanup' into mainIdent
  • edcfce3f|||PR ident#41 ident#43 ident#44 login error page as a component (same status codes and text, pixel-identical), declarations and route wiring cleaned upmre
  • 3ac85995ident#43 ident#44: plain declarations for never-reassigned lets, one envString helper, named route functions and audience rule out of project.hlmre
  • c7eef14aMerge branch 'nv1-navigate' into mainIdent
  • 644f9775|||PR ident#36 navigate() instead of window.location in the shell, start shell and homemre
  • 4ca2f921deploy.sh: tar --hard-dereference so backups hold no hard linksmre
  • 23971fb7ident#49: media queries in the language's @media formmre
  • 73f4f97dident: re-vendor to hybriel day38b (mpackdb store-open fix)mre
  • aa056c03ident: a startup error prints its message before exit 1 (hybriel#247)mre
  • ee37a861ident#G48: gitoria's registration gets the wildcard origin of its repo addresses at load (gate tests/gitoria-origin.mjs)mre
  • dc6d486fident#27: the docs gate expects the new Access entry in the main menumre
  • d277633cident#27: README: identity access and the introspect endpointmre
  • e999b0d3ident#27: the Access tab — one key per identity for all its apps: give access in three steps, the overview matrix, a cell's sheet (since, last use, level, rotate, revoke), the app's check POST /api/introspect, agent identities hidden from the login picker, an inbox icon in the header's icon style (gate: tests/access.mjs)mre
  • 436206fcident#47: deploy.sh runs the sign-in gate on the deploy's own port slot, like the sessionwrites and docs gates (the default 8700 can be taken by another process)mre
  • a4887ea3ident#47: the selector's sign-in frame no longer has a Continue button; the identity row itself is the link (gate tests/signin.mjs fails on the old code)mre
  • d8ec703dident#45: /docs shows docs/IDENT.md (hl:markdown, vendored from ac1ed9da), one Docs entry in the main menu, README for developers only, gates tests/docs.mjs and tests/sessionwrites.mjs in deploy.shmre
  • ec6aad35Merge branch 'a28g-amp-callsites' into d45-docsmre
  • 6bfbd3f2ident#45: docs/IDENT.md, what ident is and how it works; CONCEPT.md marks one id per app as droppedmre