feat: account menu, database roles, and single logout
Bundles the console work from the current branch: the header account control, database-backed roles and permissions, and signing out across the applications that share this sign-in. The account control replaces a separate identity chip and a separate sign-out button, which meant the header carried two controls describing one fact. web/account.js is mounted into every page by a placeholder and owns the keyboard handling, the outside-click behaviour and the sign-out form once. It also fills the trigger's name, which the previous markup left empty. Signing out revokes the hosted-login bearer sessions this installation issued, then redirects to the provider's end_session_endpoint when the discovery document advertises one. Applications that authenticate against this installation therefore lose their session too; one pointed straight at an identity provider is out of its reach and is unchanged. Roles and permissions become rows rather than a closed enum, so a tenant can extend the catalog without a migration, and a role can no longer be granted a capability that is not in it. requireSameOrigin now compares against the origin the request arrived on instead of the configured base URL, which defaulted to http://localhost:8080 and so rejected every write in a deployment that never set it. Two bugs found while verifying in a browser: - A profile picture never rendered. avatarURL built an absolute URL from the configured base URL, and the page's own img-src 'self' blocked it. The console's own pages now take a root-relative path; only /connect/userinfo, read from another origin, needs an absolute one, and it follows the request. - absoluteURL preferred the configuration over the request while its comment claimed the opposite, which also misdirected the logout redirect. Card layout: the footer was one two-column row shared between a label and a forty-character identifier, so the identifier took the width and crushed its label into three stacked words. Each pair is a line now, the value truncates with the full text in the title, and cards align their footers across a row.
This commit is contained in:
parent
3fdc8cb489
commit
c7c81fb65c
43 changed files with 2248 additions and 298 deletions
|
|
@ -12,8 +12,6 @@ import (
|
|||
"github.com/danyel/go-loose/web"
|
||||
)
|
||||
|
||||
const googleDemoClientID = "554628171917-forvpfs44pqajv77dfhl503prfqnhor3.apps.googleusercontent.com"
|
||||
|
||||
func (s *Server) installPage(w http.ResponseWriter, r *http.Request) {
|
||||
if s.installed.Load() {
|
||||
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
||||
|
|
@ -31,7 +29,6 @@ func (s *Server) installPage(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
page := strings.NewReplacer(
|
||||
"{{CSRF_TOKEN}}", html.EscapeString(csrfToken),
|
||||
"{{GOOGLE_CLIENT_ID}}", googleDemoClientID,
|
||||
"{{CALLBACK_URL}}", html.EscapeString(s.cfg.OIDCRedirectURL),
|
||||
).Replace(string(content))
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
|
|
@ -56,38 +53,44 @@ func (s *Server) install(w http.ResponseWriter, r *http.Request) {
|
|||
writeError(w, http.StatusForbidden, "invalid installer form; reload the installer")
|
||||
return
|
||||
}
|
||||
clientID := strings.TrimSpace(r.Form.Get("oidc_client_id"))
|
||||
clientSecret := strings.TrimSpace(r.Form.Get("oidc_client_secret"))
|
||||
if clientID == "" || clientSecret == "" {
|
||||
writeError(w, http.StatusBadRequest, "Google client ID and client secret are required")
|
||||
return
|
||||
}
|
||||
if err := s.configureOIDC(r.Context(), "https://accounts.google.com", clientID, clientSecret); err != nil {
|
||||
writeError(w, http.StatusBadGateway, "Google OIDC discovery failed")
|
||||
return
|
||||
}
|
||||
ciphertext, err := secretbox.Encrypt(s.cfg.SessionSecret, clientSecret)
|
||||
if err != nil {
|
||||
s.internalError(w, "encrypt OIDC secret", err)
|
||||
issuer := strings.TrimSpace(r.Form.Get("field1"))
|
||||
clientID := strings.TrimSpace(r.Form.Get("field2"))
|
||||
clientSecret := strings.TrimSpace(r.Form.Get("field3"))
|
||||
redirectURL := strings.TrimSpace(r.Form.Get("field4"))
|
||||
if issuer == "" || clientID == "" || clientSecret == "" || redirectURL == "" {
|
||||
writeError(w, http.StatusBadRequest, "All four fields are required")
|
||||
return
|
||||
}
|
||||
seedDemo := r.Form.Get("seed_demo") == "on"
|
||||
var demoUsers []store.DemoUser
|
||||
var err error
|
||||
if seedDemo {
|
||||
demoUsers, err = buildDemoUsers()
|
||||
if err != nil {
|
||||
s.internalError(w, "hash demo credentials", err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
demoUsers = nil
|
||||
}
|
||||
ciphertext, encErr := secretbox.Encrypt(s.cfg.SessionSecret, clientSecret)
|
||||
if encErr != nil {
|
||||
s.internalError(w, "encrypt OIDC secret", encErr)
|
||||
return
|
||||
}
|
||||
err = s.store.Install(r.Context(), store.Installation{
|
||||
OIDCIssuer: "https://accounts.google.com", OIDCClientID: clientID,
|
||||
OIDCSecretCiphertext: ciphertext, SeededDemo: seedDemo,
|
||||
OIDCIssuer: issuer, OIDCClientID: clientID,
|
||||
OIDCSecretCiphertext: ciphertext, OIDCRedirectURL: redirectURL, SeededDemo: seedDemo,
|
||||
}, demoUsers)
|
||||
if err != nil {
|
||||
s.internalError(w, "complete installation", err)
|
||||
return
|
||||
}
|
||||
// Configure OIDC in the running server
|
||||
if err := s.configureOIDC(r.Context(), issuer, clientID, clientSecret, redirectURL); err != nil {
|
||||
s.internalError(w, "configure OIDC", err)
|
||||
return
|
||||
}
|
||||
s.installed.Store(true)
|
||||
if err := s.ensureLocalAdministrator(r.Context()); err != nil {
|
||||
s.internalError(w, "bootstrap local administrator", err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue