diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2025-11-15 09:26:26 -0800 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2025-11-15 09:26:26 -0800 |
| commit | 2a489c6760852e135812062617d67ad4776db1a1 (patch) | |
| tree | 5f9ad3ea09d2f62a3e21c3b5f1ddd6caf73709c0 /roseh.moe.go | |
| parent | e3c4636772547507448146e04c71de657a5d4105 (diff) | |
| download | roseh.moe-2a489c6760852e135812062617d67ad4776db1a1.tar.zst | |
Fix cross-domain login
Diffstat (limited to 'roseh.moe.go')
| -rw-r--r-- | roseh.moe.go | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/roseh.moe.go b/roseh.moe.go index 2576627..1f9a9f2 100644 --- a/roseh.moe.go +++ b/roseh.moe.go @@ -447,14 +447,17 @@ var ( ) type loginTemplateArgs struct { - SelfURL string Redirect string Error bool } -func executeLoginTemplate(w io.Writer, redirect string) { +func redirectLogin(w http.ResponseWriter, r *http.Request, redirect string) { redirect += base64.RawURLEncoding.EncodeToString(mac([]byte(redirect))) - if err := loginTemplate.Execute(w, loginTemplateArgs{SelfURL: *selfURL, Redirect: redirect}); err != nil { + http.Redirect(w, r, *selfURL+"/login?redirect="+url.QueryEscape(redirect), http.StatusFound) +} + +func serveLogin(w http.ResponseWriter, r *http.Request) { + if err := loginTemplate.Execute(w, loginTemplateArgs{Redirect: r.FormValue("redirect")}); err != nil { log.Printf("Warning: login: %s", err) } } @@ -509,7 +512,7 @@ type notepadTemplateArgs struct { func notepad(w http.ResponseWriter, r *http.Request) { if !cookieAuth(w, r) { - executeLoginTemplate(w, "/notepad") + redirectLogin(w, r, "/notepad") return } notepadContentsMu.Lock() @@ -586,7 +589,7 @@ type jellyfinReverseProxy struct { func (p *jellyfinReverseProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { if !cookieAuth(w, r) { - executeLoginTemplate(w, "https://cinema.rose.moe") + redirectLogin(w, r, "https://cinema.rose.moe") return } p.proxy.ServeHTTP(w, r) @@ -605,6 +608,7 @@ func main() { http.HandleFunc("POST /wormhole/{hole}/upload", wormholeSend) http.HandleFunc("GET /wormhole/{hole}", wormholeRecv) http.HandleFunc("GET /wormhole/{hole}/qr.png", wormholeQR) + http.HandleFunc("GET /login", serveLogin) http.HandleFunc("POST /login", login) http.HandleFunc("GET /notepad", notepad) http.HandleFunc("POST /notepad", autosave) |
