oficina / calendar Public

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

Plain git — no account needed to clone.

Download

Download this file

1package calendar
2
3// Signing out, and forgetting: the signed-out page with "Forget me on this
4// device", Forget itself (chained on to Oficina ID's own with Home), and
5// the two Sign outs.
6
7import (
8 "net/http"
9 "net/url"
10 "strings"
11
12 "amadan.net/oficina/estilo.git/chrome"
13 "amadan.net/oficina/estilo.git/sky"
14 "amadan.net/oficina/home/connect"
15)
16
17// renderSignedOut is where Sign out lands: /signed-out, in both modes, in
18// the door's words: "You’re signed out", Sign in, then the quiet "Forget
19// me on this device" (the smart-door spec's "Signed out"), a POST to
20// rastrillo auth's Forget. With Home configured the page is connect's
21// SignedOut, which carries that path (RoutesConfig.ForgetPath) for PageFor,
22// and the form also asks Calendar to go on to Oficina ID's own Forget once
23// this one has answered (forget). Standalone it is Calendar's own path,
24// with no chain.
25func (a *App) renderSignedOut(w http.ResponseWriter, r *http.Request, status int) {
26 w.Header().Set("Cache-Control", "no-store")
27 p := connect.PageFor(r, "signedout", "")
28 signin, forget, chain := p.Action, p.ForgetAction, []chrome.Hidden{{Name: "chain", Value: oficinaChain}}
29 if signin == "" {
30 signin = connect.SigninPath
31 }
32 if forget == "" {
33 forget, chain = signinForgetPath, nil
34 }
35 notice := chrome.SignInNotice{Icon: doorIcon(), App: "Calendar", Sky: sky.For(r.Host)}.
36 SignedOut(signin).Forgetting(forget, "", chain...)
37 renderStatus(w, "signin", status, a.h.page(r, notice.Page(), signinView{Notice: &notice}))
38}
39
40// signedOut serves GET /signed-out without Home.
41func (a *App) signedOut(w http.ResponseWriter, r *http.Request) {
42 a.renderSignedOut(w, r, http.StatusOK)
43}
44
45// forget is POST /signin/forget, rastrillo auth's Forget: "Use a different
46// email" on the door, and "Forget me on this device" on the signed-out
47// page. Each host remembers for itself, so with Home configured the
48// signed-out page's form (chain=oficina) goes on to Oficina ID's own Forget
49// once this one has answered, with Calendar's signed-out page as the way
50// back: {issuer}/forget?return=<origin>/signed-out. id.oficina.works asks
51// "Forget me on Oficina ID too?" and returns only to a registered
52// consumer's exact /signed-out. Anything but Forget's own redirect (a
53// cross-origin refusal, a wrong method) is passed on as it is. A page a
54// sign-in in progress kept (signin_return.go) is forgotten too.
55func (a *App) forget(w http.ResponseWriter, r *http.Request) {
56 if a.returns != nil && r.Method == http.MethodPost {
57 forgetReturn(w)
58 }
59 if a.home == nil {
60 a.auth.Forget(w, r)
61 return
62 }
63 result := &bufferedResponse{header: make(http.Header)}
64 a.auth.Forget(result, r)
65 if result.status == http.StatusSeeOther && r.PostFormValue("chain") == oficinaChain {
66 result.header.Set("Location", oficinaForgetURL(a.home.issuer, a.cfg.Origin))
67 }
68 result.replay(w)
69}
70
71// oficinaForgetURL is Oficina ID's Forget, returning to this origin's
72// signed-out page (Home's internal/home/door.go, forgetChainReturn).
73func oficinaForgetURL(issuer, origin string) string {
74 back := strings.TrimSuffix(origin, "/") + "/signed-out"
75 return strings.TrimSuffix(issuer, "/") + "/forget?" + url.Values{"return": {back}}.Encode()
76}
77
78// signOutToSignedOut is rastrillo's standalone Sign out with one change:
79// where it lands. auth.Signout revokes the session and answers 303 to its
80// SigninPath, which every other auth outcome also uses, so the path cannot
81// change; this retargets that one redirect to /signed-out.
82func signOutToSignedOut(signout http.HandlerFunc) http.HandlerFunc {
83 return func(w http.ResponseWriter, r *http.Request) {
84 signout(&signedOutRedirect{ResponseWriter: w}, r)
85 }
86}
87
88type signedOutRedirect struct{ http.ResponseWriter }
89
90func (s *signedOutRedirect) WriteHeader(code int) {
91 if code == http.StatusSeeOther && s.Header().Get("Location") == connect.SigninPath {
92 s.Header().Set("Location", "/signed-out")
93 }
94 s.ResponseWriter.WriteHeader(code)
95}
96
97// homeSignout is connect's Sign out, which also forgets a page a sign-in
98// in progress kept (signin_return.go): it was this person's, not the next
99// one's.
100func (a *App) homeSignout(w http.ResponseWriter, r *http.Request) {
101 forgetReturn(w)
102 a.home.routes.Signout(w, r)
103}
104