incorporate requested changes

Signed-off-by: Christian Richter <crichter@owncloud.com>
This commit is contained in:
Christian Richter
2024-03-18 16:48:42 +01:00
parent d31f5b9e15
commit 5cc286b8ef
3 changed files with 18 additions and 11 deletions

View File

@@ -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

View File

@@ -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) {

View File

@@ -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)
})