Log OAuth sign-ins and failures; show providers' error text unescaped

Sign-in starts (with the redirect URI sent) and failures are logged, so
a failed connection can be diagnosed from `supermarket logs`. LinkedIn
sends error_description HTML-escaped, which showed as " on the
error page; it's unescaped before display.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-21 11:39:27 -07:00
co-authored by Claude Opus 5.5
parent 1f181ed554
commit a2c8889599
2 changed files with 19 additions and 1 deletions
+7 -1
View File
@@ -2,6 +2,7 @@ package web
import (
"context"
"html"
"net/http"
"net/url"
"strings"
@@ -371,6 +372,7 @@ func (s *Server) oauthStart(w http.ResponseWriter, r *http.Request) {
}
s.pending[p.State] = p
s.mu.Unlock()
s.Log.Info("oauth: sign-in started", "provider", provider, "redirect_uri", p.RedirectURI)
http.Redirect(w, r, authURL, http.StatusSeeOther)
}
@@ -383,15 +385,19 @@ func (s *Server) oauthCallback(w http.ResponseWriter, r *http.Request) {
delete(s.pending, q.Get("state")) // a state is good for one callback
s.mu.Unlock()
if p == nil || p.Provider != provider || time.Since(p.Started) > oauthTTL {
s.Log.Warn("oauth: callback with an unknown or expired state", "provider", provider)
redirect(w, r, "/settings/accounts", "oauth-expired")
return
}
fail := func(msg string) {
s.Log.Warn("oauth: sign-in failed", "provider", provider, "reason", msg)
s.render(w, r, "message", page{Title: "Sign-in failed", Nav: "settings/accounts", Error: msg,
Data: map[string]string{"Back": "/settings/accounts"}})
}
if e := q.Get("error"); e != "" {
fail("The provider said: " + e + " " + q.Get("error_description"))
// Some providers (LinkedIn) send the description HTML-escaped;
// unescape it so the page doesn't show &quot;.
fail("The provider said: " + e + " " + html.UnescapeString(q.Get("error_description")))
return
}
code := q.Get("code")