gitoria
All repositories: gitoria
2.0 KB
// lib/app-auth.hl — WHO IS THE APP BEHIND AN API REQUEST (gitoria#42; contract docs/apps-api.md §2 and §6). ONE helper for every route of the apps API:// appOfRequest(route, req) → { app, repo } the connected app and the repo its token is bound to// or { error } the contract's error answer (a Response), to be returned as it is:// 401 unauthorized no Bearer token, a token that is unknown, expired, or whose app was removed or re-connected// 404 not_found the token is good but the request's address names another repo (or none): the same as a repo that does not exist// and keyOfRequest / tokenOfRequest read the Bearer header. Statics only.import { apiError, repoOfRequest } from './api-helpers.hl'import { appsTable } from './apps-table.hl'import { rowOfToken } from './app-tokens.hl'// the credential of `Authorization: Bearer <x>` (the scheme in any case) or nullstatic bearerOf = (req) => {h = req.headers['authorization']if (h == null || hlTypeName(h) != 'String') { return null }t = h.trim()if (t.length < 8 || t.slice(0, 7).toLowerCase() != 'bearer ') { return null }return t.slice(7).trim()}static unauthorized = () => {return apiError(401, 'unauthorized', 'missing, unknown or expired token: get a new one with POST /apps/token', null)}static notFound = () => {return apiError(404, 'not_found', 'no such repository', null)}// the live token → { app, repo (records) } or null; the app must still exist and still belong to the token's repostatic appOfToken = (token) => {row = rowOfToken(token)if (row == null) { return null }app = appsTable.fetch(row.app)if (app == null || app.repo != row.repo) { return null }return { app = app repoId = row.repo }}static appOfRequest = (route, req) => {found = appOfToken(bearerOf(req))if (found == null) { return { error = unauthorized() } }repo = repoOfRequest(route, req)if (repo == null || repo.id != found.repoId) { return { error = notFound() } }return { app = found.app repo = repo }}
Branches
- f1-broken-json
- f2-api-bugs
- gp-gate-ports
- heap-revert
- hl25-records
- ident-chooser-selector
- mainmain branch
- p51-public-pr-reads
- records-1112
- s25-no-session-on-login-error
- v59
- w52-person-approval
- w52b-approval-followup
- w52c-header-phone
- w53-pulls-speed-pr
- w54-repo-rename-pr
- w55-rename-org
- w56-owner-members
- w62-pr-close
- w63-force-push
- w64-org-slash
Latest commits
- cd442066gitoria#43: app-auth unit test reads the apps table from its new filemre
- 5dccbe38gitoria#43: in-flight rows are left alone by the other process; gate in deploy.sh; READMEmre
- 8c8805f3merge main (gitoria#42), delivery log and redelivery routes, sweep fixmre
- 5a996ea8gitoria#42: short-lived app tokens, read-only git fetch with them (merge w42-app-token)mre
- afdb0cbfgitoria#43: rename the moved helper (name clash in the browser build)mre
- 15e01e94gitoria#43: tests/events.mjs and its probemre
- 77829b73gitoria#43: signed events to connected apps (deliveries table, sender timer, pull_request events, ping)mre
- b5d696fegitoria#42: app tokens (gat_, one hour), appOfRequest, app token as the git read passwordmre
- 1997e77dgitoria#40: stable PR numbers, refs/pull/N/head, ssh pushes reach the app (merge w40-pr-number)mre
- 9364fb16gitoria#40: ssh pushes call /__git/pushed before and after (ensurePulls, notifyPush, syncPulls); gate over the sshd imagemre
- fdb9ed28gitoria#41: repo owners can connect an app (merge w41-apps-connect)mre
- 2ef23df0gitoria#40: the browser gate reads the title without the #Nmre
- 9af07ecegitoria#41: connect an app to a repo (apps table, connect flow, manual add, allow-list, settings)mre
- b9137ff0gitoria#40: pull requests are stored with a number, refs/pull/N/head, syncPulls and pullObject; /pulls shows #Nmre
- 06d622daown image tag gitoria-runtime:debian12 for gitoria and standby (shared tag lost git)mre
- 20caa33agitoria#37: media queries in the language's @media block (minWidth = '60rem') in list, codebrowser and repomre
- c4175e6dgitoria: a startup error prints its message before exit 1 (hybriel#247)mre
- c50d17efKeep function-route not-found style in shared stylesheetmre
- e42d78d3Preserve ticket state CSS and document function-route style gapmre
- c6b7154eWIP gitoria#26: move styles into nested component blocksmre