feat: avatar, account menu, and single sign-on from Go Loose

Signing in now starts at the sign-in screen and one button that hands the
browser to Go Loose, which returns to the welcome page. Nothing redirects to the
identity provider on its own any more: that fired on every anonymous visit and
read as a redirect loop rather than as a choice to sign in. The password form
remains only where the API reports that Go Loose login is not configured for the
host, because otherwise the application is unreachable on a bare localhost.

A person's picture is carried through from the Go Loose identity and rendered in
the account menu and on the profile page, with their initials as the fallback.
Two things make that fallback necessary rather than decorative: Go Loose retires a
picture key when a picture is replaced, so a link cached in a browser can be dead,
and most people have not uploaded one. The URL is deliberately not persisted
locally, since a stored key would keep failing after the picture changed.

The account menu is a disclosure rather than a hover menu: a real button with
aria-expanded, Escape and outside clicks closing it, and focus returning to the
trigger. It is not an ARIA menu, because its actions are a link and a button and
menuitem roles would strip the link semantics from one of them for no gain.

The account URL of the Go Loose identity is resolved on each sign-in and is read
from the live identity provider every time, which is also what makes it correct
after a picture change.

Depends on the Go Loose revision that serves avatar_url through
/connect/userinfo, so the picture URL reaches this application at all.
This commit is contained in:
Daniel Noulet 2026-10-05 21:50:06 +02:00
parent 6be21597d5
commit 5449cd3d8d
52 changed files with 1927 additions and 434 deletions

View file

@ -21,7 +21,7 @@ func New(h *handler.Handler, tokens security.ITokenManager, frontendURL string)
router := chi.NewRouter()
spec := openapi.New()
router.Use(middleware.RequestID, middleware.RealIP, middleware.Recoverer, middleware.Compress(5))
router.Use(cors(frontendURL))
router.Use(cors(frontendURL, h.AppDomain()))
router.Use(mw.TenantSchemaMiddleware(h.Db(), h.AppDomain()))
router.Use(middleware.Timeout(2 * time.Minute))
register(router, spec, false, http.MethodGet, "/api/openapi.json", spec.ServeHTTP,
@ -164,11 +164,11 @@ func authenticate(tokens security.ITokenManager) func(http.Handler) http.Handler
}
}
func cors(origin string) func(http.Handler) http.Handler {
func cors(origin, appDomain string) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
requestOrigin := r.Header.Get("Origin")
if allowedCORSOrigin(requestOrigin, origin) {
if allowedCORSOrigin(requestOrigin, origin, appDomain) {
w.Header().Set("Access-Control-Allow-Origin", requestOrigin)
}
w.Header().Set("Access-Control-Allow-Headers", "Authorization, Content-Type, X-API-Key, X-Tenant-Id")
@ -183,7 +183,11 @@ func cors(origin string) func(http.Handler) http.Handler {
}
}
func allowedCORSOrigin(requestOrigin, configuredOrigin string) bool {
// allowedCORSOrigin accepts the configured frontend origin plus any tenant host
// of the configured application domain, which is what the Vite dev server on
// http://<tenant>.<appDomain>:5173 sends. *.guess.local stays allowed for the
// offline BDD and local password-only setups.
func allowedCORSOrigin(requestOrigin, configuredOrigin, appDomain string) bool {
if requestOrigin == "" {
return false
}
@ -194,5 +198,11 @@ func allowedCORSOrigin(requestOrigin, configuredOrigin string) bool {
if err != nil || (parsed.Scheme != "http" && parsed.Scheme != "https") {
return false
}
return strings.HasSuffix(strings.ToLower(parsed.Hostname()), ".guess.local")
hostname := strings.ToLower(parsed.Hostname())
for _, suffix := range []string{"." + appDomain, ".guess.local"} {
if suffix != "." && strings.HasSuffix(hostname, suffix) {
return true
}
}
return false
}