fix(webui): send a refused browser to sign in, and drop an unused method

Two loose ends from the sign-in work, both mine.

A browser that cannot authenticate now goes to the provider when this instance has
a sign-in flow, instead of being shown the shared-token paste page -- a page that
cannot help it, because the token it would paste is not what this instance accepts.
A refusal that signing in again cannot fix, a suspended identity, is still answered
rather than redirected: sending someone back to a provider that already authenticated
them would hide the reason they were refused.

ProviderSession.Expired is removed. Nothing called it, and it must not: expiry is
the verifier's check, and a second opinion about whether a token is still good is
exactly the sort of near-duplicate that drifts from the authority it copies. The
browser path re-runs the flow when verification refuses, which is one rule rather
than two.

Verified: task check exit 0 on this tree.
This commit is contained in:
sam committed 2026-09-22 15:02:27 +10:00
1 parent 79f521b65b
commit debeb869bb
3 files changed
+80 -11

No files matched your search

+16 -4
View File
@@ -32,10 +32,13 @@ const (
loginStateCookie = "archie_login_state"
loginVerifierCookie = "archie_login_verifier"
loginCookieMaxAge = 600
// loginRoute and loginCallbackRoute must match the redirect URI registered at
// the provider: the provider returns the browser to the path it was given.
loginRoute = "GET /oauth2/login"
loginCallbackRoute = "GET /oauth2/callback"
// loginPath is where a browser signs in, and the path a refused browser is
// sent to. loginCallbackPath must match the redirect URI registered at the
// provider: the provider returns the browser to the path it was given.
loginPath = "/oauth2/login"
loginCallbackPath = "/oauth2/callback"
loginRoute = "GET " + loginPath
loginCallbackRoute = "GET " + loginCallbackPath
)
// IsLoopback reports whether a listen address is reachable only from this
@@ -324,6 +327,15 @@ func (s *Server) refuseUnidentified(w http.ResponseWriter, r *http.Request, err
w.Header().Set("WWW-Authenticate", `Bearer realm="archie"`)
}
if !allowed && wantsDocument(r) {
// A browser that cannot authenticate is sent to sign in, when this
// instance has a sign-in flow: re-presenting a credential is the only
// thing that helps, and a shared-token paste page would be meaningless
// here. A refusal the caller cannot fix by signing in again -- a
// suspended identity -- is answered rather than redirected.
if s.Login != nil {
http.Redirect(w, r, loginPath, http.StatusSeeOther)
return
}
s.authPage(w, reason)
return
}