Skip to content

Commit 5259142

Browse files
committed
Fix for SAML SP-initiated flow bug #685
1 parent eae7025 commit 5259142

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

cmd/admin/auth.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ func handlerAuthCheck(h http.Handler, auth string) http.Handler {
4040
case config.AuthSAML:
4141
samlSession, err := samlMiddleware.Session.GetSession(r)
4242
if err != nil {
43+
if samlConfig.SPInitiated {
44+
samlMiddleware.HandleStartAuthFlow(w, r)
45+
return
46+
}
4347
http.Redirect(w, r, samlConfig.LoginURL, http.StatusFound)
4448
return
4549
}
@@ -89,6 +93,10 @@ func handlerAuthCheck(h http.Handler, auth string) http.Handler {
8993
session, err = sessionsmgr.Save(r, w, u)
9094
if err != nil {
9195
log.Err(err).Msgf("session error")
96+
if samlConfig.SPInitiated {
97+
samlMiddleware.HandleStartAuthFlow(w, r)
98+
return
99+
}
92100
http.Redirect(w, r, samlConfig.LoginURL, http.StatusFound)
93101
return
94102
}
@@ -103,7 +111,7 @@ func handlerAuthCheck(h http.Handler, auth string) http.Handler {
103111
if err != nil {
104112
log.Err(err).Msgf("error updating metadata for user %s", session.Username)
105113
}
106-
// Access granted
114+
// Access granted, use SAML middleware to set context
107115
samlMiddleware.RequireAccount(h).ServeHTTP(w, r.WithContext(ctx))
108116
}
109117
})

cmd/admin/saml.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type JSONConfigurationSAML struct {
2424
LoginURL string `json:"loginurl"`
2525
LogoutURL string `json:"logouturl"`
2626
JITProvision bool `json:"jitprovision"`
27+
SPInitiated bool `json:"spinitiated"`
2728
}
2829

2930
// Structure to keep all SAML related data

0 commit comments

Comments
 (0)