Phase 12: signing in with the Core's Authelia

Admins make the client's secret under Settings → Sign-in, which shows the
entry for the Core's idproviders.yml (the secret's PBKDF2-SHA512 hash, the
redirect address, PKCE). People sign in with their Core account: invited
ones are matched by verified email, then by subject; optionally anyone at
the Core's domain joins. Passwords can be turned off but for the owner's,
and signing out ends the Core's session where it can. On multi-tenant, the
team is found by its proved domain.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 13:00:36 -07:00
co-authored by Claude Opus 5.5
parent 637ef1cc25
commit 962dbe3286
19 changed files with 1458 additions and 15 deletions
+37 -2
View File
@@ -25,6 +25,8 @@ type signinForm struct {
Problem string
Sent bool // a reset link went out (or would have)
Reset string
Core string // "Sign in with <the Core>": its domain, on the server edition
CoreMulti bool // the multi-tenant edition: ask for the team's domain
}
// safeNext is where to go after signing in: a path in this app, else the
@@ -46,10 +48,13 @@ func (s *Server) signinPage(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, next, http.StatusSeeOther)
return
}
s.render(w, r, "signin", page{Title: "Sign in", Bare: true, Data: signinForm{Next: next, Email: r.URL.Query().Get("email")}})
f := signinForm{Next: next, Email: r.URL.Query().Get("email")}
s.withCore(&f)
s.render(w, r, "signin", page{Title: "Sign in", Bare: true, Data: f})
}
func (s *Server) signinFail(w http.ResponseWriter, r *http.Request, f signinForm, code int) {
s.withCore(&f)
w.WriteHeader(code)
s.render(w, r, "signin", page{Title: "Sign in", Bare: true, Data: f})
}
@@ -91,6 +96,11 @@ func (s *Server) signin(w http.ResponseWriter, r *http.Request) {
s.signinFail(w, r, f, http.StatusForbidden)
return
}
if msg := s.passwordsOff(u); msg != "" {
f.Problem = msg
s.signinFail(w, r, f, http.StatusForbidden)
return
}
if u.TwoFactor {
token, err := users.NewLink(s.DB, users.CodeLink, u.ID, now)
if err != nil {
@@ -254,16 +264,41 @@ func (s *Server) countFailure(ipKey, emailKey string, u *users.User, now time.Ti
}
func (s *Server) signout(w http.ResponseWriter, r *http.Request) {
if viewerOf(r).User != nil {
v := viewerOf(r)
if v.User != nil {
s.audit(r, "signout", "", "")
}
// Signed in with the Core: out of the Core too, where it can.
core := ""
if v.Session != nil && v.Session.Via == "core" {
if ts, err := s.forTeam(v.Session.Team); err == nil {
ctx, cancel := context.WithTimeout(r.Context(), 10*time.Second)
core = ts.coreSignOut(ctx)
cancel()
}
}
if err := s.endSession(w, r); err != nil {
s.serverError(w, err)
return
}
if core != "" {
http.Redirect(w, r, core, http.StatusSeeOther)
return
}
redirect(w, r, "/signin", "signed-out")
}
// withCore adds the Core's sign-in to the sign-in page, where it's set up.
func (s *Server) withCore(f *signinForm) {
if s.multi() {
f.CoreMulti = true
return
}
if s.coreReady() {
f.Core = s.core().Domain
}
}
// Resetting a password.
func (s *Server) forgotPage(w http.ResponseWriter, r *http.Request) {