oficina / sheets Public

Clone
git clone https://amadan.net/oficina/sheets

Plain git — no account needed to clone.

Download

Download this file

1package sheets
2
3import (
4 "net/http"
5
6 "amadan.net/oficina/home/connect"
7 "github.com/go-chi/chi/v5"
8)
9
10func (a *App) mountAuth(r chi.Router) {
11 if a.homeRoutes != nil {
12 // The sign-in door's three routes (home/connect MIGRATING.md, step
13 // 6): /signin is always the door, offering Continue with Oficina ID;
14 // /signin/local is the door with email as the one way in, where
15 // connect sends people Oficina ID cannot help; /signin/oficina
16 // starts the Home exchange. connect hands both door routes to
17 // Sheets' door (RoutesConfig.LocalSignin, signinDoor). All three
18 // sit behind Sheets' admission check (admittedOnly).
19 r.Get(connect.SigninPath, a.admittedOnly(a.homeRoutes.SigninDoor))
20 r.Get(connect.SigninLocalPath, a.homeRoutes.LocalGuard(a.admittedOnly(a.homeRoutes.SigninLocal)))
21 r.Get(connect.SigninOficinaPath, a.admittedOnly(a.homeRoutes.SigninOficina))
22 r.Get("/auth/start", a.home.Start)
23 r.Post("/auth/assertion", a.home.Callback)
24 r.Get("/auth/finish", a.home.Finish)
25 r.Get(connect.LocalCompletePath, a.homeRoutes.LocalGuard(a.homeLocalComplete))
26 r.Get("/account/home", a.homeRoutes.Account)
27 r.Post("/account/home", a.homeRoutes.LinkStart)
28 r.Get("/account/home/confirm", a.home.ConfirmPage)
29 r.Post("/account/home/confirm", a.homeRoutes.ConfirmPost)
30 r.Get("/signed-out", a.homeRoutes.SignedOut)
31 // The member choice (team mode; connect answers 404 without the
32 // team hooks): no session yet, and the POST inside the app-wide
33 // CSRF check like any form (connect also demands this Origin).
34 r.Get(connect.ChoosePath, a.home.ChoosePage)
35 r.Post(connect.ChoosePath, a.home.ChoosePost)
36 // The native app's Oficina ID exchange (Home spec
37 // 2026-11-14-oficina-id-native.md §7). connect's Middleware lets
38 // this one path past the CSRF check: it refuses anything a browser
39 // sends.
40 r.Post(connect.NativeExchangePath, a.home.NativeExchange)
41 } else {
42 r.Get("/signin", a.handleSignin)
43 r.Get("/signed-out", a.handleSignedOut)
44 }
45 if a.auth != nil {
46 // "Use a different email" on the door and "Forget me on this
47 // device" on the signed-out page: a same-origin POST, inside the
48 // app-wide CSRF check like any form, and auth's own. With Home, the
49 // signed-out page's chains on to Oficina ID's own Forget (forget).
50 r.Post(signinForgetPath, a.forget)
51 }
52 if a.auth != nil {
53 // The handlers rastrillo/auth expects an app to mount, at the
54 // paths its own docs use. Verify answers GET with the confirm
55 // door (renderConfirm), which spends nothing, and POST with the
56 // redemption, so it is mounted for both methods in both modes:
57 // without the POST, the door's Sign in button gets a 405 and
58 // nobody signs in. The path is baked into every emailed link, so
59 // moving it later invalidates links already in people's inboxes.
60 // A verified address that is not admitted is answered by auth's
61 // Refused hook (App.refused), inside Callback and Verify.
62 if a.homeRoutes != nil {
63 r.Post("/signin", a.homeRoutes.LocalGuard(a.handleBegin))
64 r.Get("/auth/callback", a.homeRoutes.LocalGuard(a.auth.Callback))
65 r.Get("/auth/verify", a.homeRoutes.LocalGuard(a.auth.Verify))
66 r.Post("/auth/verify", a.homeRoutes.LocalGuard(a.auth.Verify))
67 r.Post("/signout", a.homeSignout)
68 } else {
69 r.Post("/signin", a.handleBegin)
70 r.Get("/auth/callback", a.auth.Callback)
71 r.Get("/auth/verify", a.auth.Verify)
72 r.Post("/auth/verify", a.auth.Verify)
73 r.Post("/signout", a.signOutToPage)
74 }
75 }
76}
77
78// homeSignout is connect's Sign out, which also forgets a page a sign-in
79// in progress kept (signin_return.go): it was this person's, not the
80// next one's.
81func (a *App) homeSignout(w http.ResponseWriter, r *http.Request) {
82 forgetReturn(w)
83 a.homeRoutes.Signout(w, r)
84}
85