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

@ -8,6 +8,10 @@ type User struct {
PasswordHash string
DisplayName string
Role string
// AvatarURL is the picture Go Loose serves for this person. It is resolved
// from the identity provider on every sign-in rather than stored, because a
// stored key stops resolving once the picture is replaced or removed.
AvatarURL string
}
type Trait struct {

View file

@ -28,7 +28,7 @@ const CandidateThreshold = 60.0
type IAuthService interface {
Login(context.Context, string, string) (string, model.User, error)
EstablishExternalSession(context.Context, string, string) (string, model.User, error)
EstablishExternalSession(context.Context, ExternalIdentity) (string, model.User, error)
}
type IJobService interface {
@ -89,9 +89,19 @@ func (s *AuthService) Login(ctx context.Context, email, password string) (string
return token, user, nil
}
func (s *AuthService) EstablishExternalSession(ctx context.Context, email, displayName string) (string, model.User, error) {
email = strings.ToLower(strings.TrimSpace(email))
displayName = strings.TrimSpace(displayName)
// ExternalIdentity is what Go Loose reports about the person signing in. The
// avatar URL is deliberately not persisted: Go Loose retires a picture key when
// the picture changes, so a stored copy would eventually point at nothing. It is
// read from the live identity on every session instead.
type ExternalIdentity struct {
Email string
DisplayName string
AvatarURL string
}
func (s *AuthService) EstablishExternalSession(ctx context.Context, identity ExternalIdentity) (string, model.User, error) {
email := strings.ToLower(strings.TrimSpace(identity.Email))
displayName := strings.TrimSpace(identity.DisplayName)
if email == "" {
return "", model.User{}, ErrValidation
}
@ -116,6 +126,7 @@ func (s *AuthService) EstablishExternalSession(ctx context.Context, email, displ
return "", model.User{}, err
}
user.PasswordHash = ""
user.AvatarURL = strings.TrimSpace(identity.AvatarURL)
return token, user, nil
}