From a02ab7c04e57c2895e4a83606f401599ca777c26 Mon Sep 17 00:00:00 2001 From: Cory Bolar Date: Thu, 23 Feb 2023 14:00:19 -0500 Subject: [PATCH 1/3] Embed static stylesheets and dependencies Embedding css and webfont dependencies allows the application to present itself correctly in an environment that does not allow downloading the files from a cdn. Inspiration taken from #1492 but reworked to make use of embed.FS simplifying the approach. --- oauthproxy.go | 8 ++++++++ pkg/app/pagewriter/error.html | 4 ++-- pkg/app/pagewriter/sign_in.html | 2 +- static/css/all.min.css | 9 +++++++++ static/css/bulma.min.css | 1 + static/webfonts/fa-solid-900.woff2 | Bin 0 -> 149908 bytes 6 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 static/css/all.min.css create mode 100644 static/css/bulma.min.css create mode 100644 static/webfonts/fa-solid-900.woff2 diff --git a/oauthproxy.go b/oauthproxy.go index 25b14e61..10a69b31 100644 --- a/oauthproxy.go +++ b/oauthproxy.go @@ -2,6 +2,7 @@ package main import ( "context" + "embed" "encoding/json" "errors" "fmt" @@ -50,6 +51,7 @@ const ( oauthCallbackPath = "/callback" authOnlyPath = "/auth" userInfoPath = "/userinfo" + staticPathPrefix = "/static/" ) var ( @@ -58,6 +60,9 @@ var ( // ErrAccessDenied means the user should receive a 401 Unauthorized response ErrAccessDenied = errors.New("access denied") + + //go:embed static/* + staticFiles embed.FS ) // allowedRoute manages method + path based allowlists @@ -320,6 +325,9 @@ func (p *OAuthProxy) buildProxySubrouter(s *mux.Router) { s.Path(oauthStartPath).HandlerFunc(p.OAuthStart) s.Path(oauthCallbackPath).HandlerFunc(p.OAuthCallback) + // Static file paths + s.PathPrefix(staticPathPrefix).Handler(http.StripPrefix(p.ProxyPrefix, http.FileServer(http.FS(staticFiles)))) + // The userinfo endpoint needs to load sessions before handling the request s.Path(userInfoPath).Handler(p.sessionChain.ThenFunc(p.UserInfo)) } diff --git a/pkg/app/pagewriter/error.html b/pkg/app/pagewriter/error.html index a346b2b3..86df3272 100644 --- a/pkg/app/pagewriter/error.html +++ b/pkg/app/pagewriter/error.html @@ -5,8 +5,8 @@ {{.StatusCode}} {{.Title}} - - + +