@@ -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 })
0 commit comments