diff --git a/services/proxy/pkg/staticroutes/backchannellogout.go b/services/proxy/pkg/staticroutes/backchannellogout.go index a3cece55d..941c5cae7 100644 --- a/services/proxy/pkg/staticroutes/backchannellogout.go +++ b/services/proxy/pkg/staticroutes/backchannellogout.go @@ -1,10 +1,11 @@ package staticroutes import ( + "net/http" + "github.com/go-chi/render" "github.com/pkg/errors" microstore "go-micro.dev/v4/store" - "net/http" ) // handle backchannel logout requests as per https://openid.net/specs/openid-connect-backchannel-1_0.html#BCRequest diff --git a/services/proxy/pkg/staticroutes/oidc_well-known.go b/services/proxy/pkg/staticroutes/oidc_well-known.go index 3065ae10a..2cbd4bff9 100644 --- a/services/proxy/pkg/staticroutes/oidc_well-known.go +++ b/services/proxy/pkg/staticroutes/oidc_well-known.go @@ -9,13 +9,13 @@ var ( wellKnownPath = "/.well-known/openid-configuration" ) -// OIDCWellKnownRewrite is a middleware that rewrites the /.well-known/openid-configuration endpoint for external IDPs. -func (s *StaticRouteHandler) OIDCWellKnownRewrite(w http.ResponseWriter, r *http.Request) { +// OIDCWellKnownRewrite is a handler that rewrites the /.well-known/openid-configuration endpoint for external IDPs. +func (s *StaticRouteHandler) oIDCWellKnownRewrite(w http.ResponseWriter, r *http.Request) { wellKnownRes, err := s.OidcHttpClient.Get(s.oidcURL.String()) if err != nil { s.Logger.Error(). Err(err). - Str("middleware", "oidc wellknown rewrite"). + Str("handler", "oidc wellknown rewrite"). Str("url", s.oidcURL.String()). Msg("get information from url failed") w.WriteHeader(http.StatusInternalServerError) @@ -26,9 +26,14 @@ func (s *StaticRouteHandler) OIDCWellKnownRewrite(w http.ResponseWriter, r *http copyHeader(w.Header(), wellKnownRes.Header) w.WriteHeader(wellKnownRes.StatusCode) - io.Copy(w, wellKnownRes.Body) + _, err = io.Copy(w, wellKnownRes.Body) + if err != nil { + s.Logger.Error(). + Err(err). + Str("handler", "oidc wellknown rewrite"). + Msg("copying response body failed") - return + } } func copyHeader(dst, src http.Header) { diff --git a/services/proxy/pkg/staticroutes/staticroutes.go b/services/proxy/pkg/staticroutes/staticroutes.go index 8a4dcd004..e131d3b2e 100644 --- a/services/proxy/pkg/staticroutes/staticroutes.go +++ b/services/proxy/pkg/staticroutes/staticroutes.go @@ -1,14 +1,15 @@ package staticroutes import ( + "net/http" + "net/url" + "path" + "github.com/go-chi/chi/v5" "github.com/owncloud/ocis/v2/ocis-pkg/log" "github.com/owncloud/ocis/v2/ocis-pkg/oidc" "github.com/owncloud/ocis/v2/services/proxy/pkg/config" microstore "go-micro.dev/v4/store" - "net/http" - "net/url" - "path" ) // StaticRouteHandler defines a Route Handler for static routes @@ -40,9 +41,9 @@ func (s *StaticRouteHandler) Handler() http.Handler { // openid .well-known if s.Config.OIDC.RewriteWellKnown { - r.Get("/.well-known/openid-configuration", s.OIDCWellKnownRewrite) + r.Get("/.well-known/openid-configuration", s.oIDCWellKnownRewrite) } - + // Send all requests to the proxy handler r.HandleFunc("/*", s.Proxy.ServeHTTP) })