Collect Android browser sign-ins after the app was stopped
The Android app kept a pending browser sign-in in a thread inside the login screen. Android often kills the process while the browser is in front, so the approval reached the server but nothing collected it, and the app came back signed out with nothing saved. The pending device code is now kept in Prefs and collected whenever the login screen resumes. The app passes return_url=keeporg://device-approved when it starts the sign-in, and the server's approval page, after a password or single sign-on, links back to it. Only the keeporg: scheme is accepted. Against a server older than 0.9, which rejects the field, the app retries without it. Verified on an Android 15 emulator: approval collected after the process was killed, and the fallback against the 0.8 server. Server 0.9.0, Android 0.3.0 (versionCode 3). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
ef6598fa15
commit
318bd68908
@@ -31,8 +31,9 @@ p.sub{margin:0 0 1.25rem;opacity:.7;font-size:.9rem}
|
||||
label{display:block;font-size:.8rem;text-transform:uppercase;letter-spacing:.04em;opacity:.7;margin:.9rem 0 .25rem}
|
||||
input{width:100%;padding:.6rem .7rem;font:inherit;color:var(--fg);background:transparent;
|
||||
border:1px solid var(--line);border-radius:8px}
|
||||
button{width:100%;margin-top:1.4rem;padding:.7rem;font:inherit;font-weight:600;color:#fff;
|
||||
button,a.button{width:100%;margin-top:1.4rem;padding:.7rem;font:inherit;font-weight:600;color:#fff;
|
||||
background:var(--accent);border:0;border-radius:8px;cursor:pointer}
|
||||
a.button{display:block;box-sizing:border-box;text-align:center;text-decoration:none}
|
||||
.err{margin:0 0 1rem;padding:.6rem .7rem;border-radius:8px;background:#f8d7da;color:#842029;font-size:.9rem}
|
||||
.alt{display:block;margin-top:1rem;text-align:center;font-size:.9rem;color:var(--accent)}
|
||||
code{font-size:1.1rem;letter-spacing:.08em}
|
||||
@@ -250,7 +251,8 @@ to ask for.</p>
|
||||
{{end}}`))
|
||||
|
||||
var doneTmpl = template.Must(template.Must(pages.Clone()).Parse(`
|
||||
{{define "body"}}<h1>{{.Title}}</h1><p class="sub">{{.Message}}</p>{{end}}`))
|
||||
{{define "body"}}<h1>{{.Title}}</h1><p class="sub">{{.Message}}</p>
|
||||
{{if .Return}}<p><a class="button" href="{{.Return}}">Return to KeepOrg</a></p>{{end}}{{end}}`))
|
||||
|
||||
func (s *Server) renderDevice(w http.ResponseWriter, code, errMsg string) {
|
||||
render(w, deviceTmpl, map[string]any{
|
||||
@@ -290,6 +292,18 @@ func (s *Server) renderDone(w http.ResponseWriter, title, msg string) {
|
||||
render(w, doneTmpl, map[string]any{"Title": title, "Message": msg})
|
||||
}
|
||||
|
||||
// renderApproved ends a device approval. A client that gave a return URL
|
||||
// gets a link back to itself; html/template would neutralise its custom
|
||||
// scheme, which is why it is marked safe here, after validReturnURL.
|
||||
func (s *Server) renderApproved(w http.ResponseWriter, returnURL string) {
|
||||
d := map[string]any{"Title": "Device approved",
|
||||
"Message": "You can close this page and return to the application."}
|
||||
if returnURL != "" && validReturnURL(returnURL) {
|
||||
d["Return"] = template.URL(returnURL)
|
||||
}
|
||||
render(w, doneTmpl, d)
|
||||
}
|
||||
|
||||
func render(w http.ResponseWriter, t *template.Template, data map[string]any) {
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
w.Header().Set("Referrer-Policy", "no-referrer")
|
||||
|
||||
Reference in New Issue
Block a user