gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit67cf016d67cf016d|||PR ident: vendor Hybriel day59mre67cf016d/lib/selector.hl

2.9 KB

  1. // lib/selector.hl — THE IDENTITY SELECTOR (piece 3 of 6, ticket #26; CONCEPT.md "Flow 2: identity selector"
  2. // and "Decided 2026-09-24"). Statics only, the server realm. Its two CORS endpoints are lib/api.hl
  3. // (apiSelectorIdentities, apiSelectorChoose; the CORS answers and the caller check: lib/api-helpers.hl);
  4. // the browser half is selector.js (served at /selector.js).
  5. //
  6. // GET /api/selector/identities?key=<api key> → { signedIn, identities: [{ id, name }] }
  7. // POST /api/selector/choose?key=<api key> { identity: <id from the list> } → { code }
  8. // OPTIONS /api/selector/choose?key=… the CORS preflight of the POST
  9. //
  10. // CORS: ident answers ONLY a request whose Origin header is one of the app's registered
  11. // origins AND whose key is that app's API key. Then (and only then) the answer carries
  12. // `Access-Control-Allow-Origin: <that exact origin>` and `…-Allow-Credentials: true`
  13. // (never `*`). Anything else is a 403 without those headers: the browser hands the page
  14. // nothing, and nothing is written.
  15. // The ident user is the one of the `identsid` cookie the browser sends along (credentials;
  16. // SameSite=Lax, so it only travels from the SAME SITE — our apps; other ports of the same
  17. // host count). Function routes get no session: it is resolved from the cookie (hybriel #18).
  18. //
  19. // THE LIST'S ids are not ident's identity ids: each is sha256(app's secret hash : identity)
  20. // cut to 32 hex — stable for one app, different for every app, not guessable, and it
  21. // means nothing outside this selector. The CODE of a choice follows the login button's
  22. // rules exactly (lib/apps.hl issueCode: single use, 60 s, this app only); the host's server
  23. // trades it with POST /api/exchange (key + secret) for the app-specific identity id.
  24. import { sha256 } from 'hl:crypto'
  25. import { issueCode } from './apps.hl'
  26. import { identityRecords, isAgent } from './identities.hl'
  27. import { labelOf } from './identities-helpers.hl'
  28. // (since mission 009 the identity's id is its UUID, so every pick id changed once then)
  29. static pickOf = (appRec, identityRec) => { return sha256(appRec.secretHash + ':' + identityRec.id).slice(0, 32) }
  30. // the account's identities for the app's page: the id to pick it by and the identity
  31. // name (CONCEPT.md: "that one is shown in the selector"; blank → the list's fallback)
  32. static selectorList = (appRec, accountId) => {
  33. out = []
  34. let n = 1
  35. for (r of identityRecords(accountId)) {
  36. // ident#27: an agent identity (a conductor's) is not offered at a login; its numbering is kept
  37. if (!isAgent(r)) { out.push({ id = pickOf(appRec, r) name = labelOf(r, n) }) }
  38. n = n + 1
  39. }
  40. return out
  41. }
  42. // THE CHOICE: the account's identity whose pick id is `pick` gets a one-time code for the app. Answers the
  43. // code, or null (no such identity).
  44. static codeOfPick = (appRec, accountId, pick) => {
  45. for (r of identityRecords(accountId)) {
  46. if (pickOf(appRec, r) == pick && !isAgent(r)) {
  47. return issueCode(appRec.id, r.id)
  48. }
  49. }
  50. return null
  51. }

Branches

Latest commits

  • 67cf016d|||PR ident: vendor Hybriel day59mre
  • 600c043dMerge branch 'v58-day58' into mainIdent
  • 365f8c80|||PR ident: vendor Hybriel day58mre
  • 585126e5Merge branch 'f16-setf' into mainIdent
  • 953bf03a|||PR ident setF mirror dropped (hybriel#370)mre
  • a1419d9cMerge branch 'f15-navigate' into mainIdent
  • 3b3e451f|||PR ident#36 navigate to the app instead of location.assignmre
  • e36f4516Merge branch 'f14-online' into mainIdent
  • 2c5eac91|||PR ident#38 online state without probe timermre
  • bf1980f2Merge branch 'v56-day56' into mainIdent
  • 62ae0adf|||PR ident: vendor Hybriel day56mre
  • 0d18abc4Merge branch 'f13-avatar' into mainIdent
  • 2a99730a|||PR ident#37 avatar in hlmre
  • fa4ed25bMerge branch 'f11-upsert' into mainIdent
  • 8f3d9bc9|||PR ident#42 keyed upsert and removemre
  • 675493b1ident#42: editing an identity upserts the one edited row (face editIdentity answers { identity, row }); a create or delete keeps the whole list because the rows' position-dependent parts (default, Delete, Identity n) changemre
  • 45e55303ident#42: an app write patches one row: upsert on create, edit and new secret, one-argument remove on delete; the faces answer the changed app (or the deleted id), not the whole listmre
  • 991641d4Merge branch 'f10-access' into mainIdent
  • e56d8273|||PR ident#34 part 4: access and inbox fixed classesmre
  • df7696dbident#34: tests: access ticks selector quoting fixmre