feat: refresh settings, sync account avatars and link account management

This commit is contained in:
SantaSpeen committed 2026-10-22 12:52:37 +03:00
1 parent fa1832dfa7
commit d3d164910b
22 files changed
+789 -407

No files matched your search

+19 -4
View File
@@ -24,15 +24,17 @@ import (
type identityKey struct{}
type sessionIdentity struct {
ID uint
Admin bool
Name string
ID uint
Admin bool
Name string
Picture string
}
type ssoClaims struct {
Subject string `json:"sub"`
Username string `json:"preferred_username"`
Name string `json:"name"`
Email string `json:"email"`
Picture string `json:"picture"`
Roles []string `json:"roles"`
}
type loginAttempt struct {
@@ -267,12 +269,16 @@ func (s *SSO) callback(w http.ResponseWriter, r *http.Request) {
if claims.Email == "" {
claims.Email = info.Email
}
if claims.Picture == "" {
claims.Picture = info.Picture
}
}
identity, err := s.provisionUser(claims)
if err != nil {
http.Error(w, "Cannot provision SSO user", 500)
return
}
identity.Picture = s.loadAvatar(ctx, claims.Picture)
sid := randomSecret()
key := sha256.Sum256([]byte(sid))
s.mu.Lock()
@@ -386,6 +392,13 @@ func (s *SSO) Wrap(next http.Handler) http.Handler {
}
}
switch p {
case "/auth/account":
if r.Method != http.MethodGet {
w.WriteHeader(http.StatusMethodNotAllowed)
return
}
http.Redirect(w, r, strings.TrimRight(s.issuer, "/")+"/settings", http.StatusFound)
return
case "/auth/login":
s.login(w, r)
return
@@ -426,7 +439,9 @@ func (s *SSO) Wrap(next http.Handler) http.Handler {
}
applySSOIdentity(u, identity)
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(ssoUserInfo(u))
profile := ssoUserInfo(u)
profile.Picture = identity.Picture
_ = json.NewEncoder(w).Encode(profile)
return
}
if ok {