From 87eaa0fcb543a4a5a10ec8855cc1f087521c91ec Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Mon, 10 Jul 2023 11:53:30 +0000 Subject: [PATCH 1/2] fix(coderd): pass oauth configs to site Fixes #8351 --- coderd/coderd.go | 17 +++++++++-------- site/site.go | 14 ++++++++------ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/coderd/coderd.go b/coderd/coderd.go index 9d2045b9ca2da..b02b3e0e2d1cf 100644 --- a/coderd/coderd.go +++ b/coderd/coderd.go @@ -299,19 +299,20 @@ func New(options *Options) *API { }, ) - staticHandler := site.New(&site.Options{ - BinFS: binFS, - BinHashes: binHashes, - Database: options.Database, - SiteFS: site.FS(), - }) - staticHandler.Experiments.Store(&experiments) - oauthConfigs := &httpmw.OAuth2Configs{ Github: options.GithubOAuth2Config, OIDC: options.OIDCConfig, } + staticHandler := site.New(&site.Options{ + BinFS: binFS, + BinHashes: binHashes, + Database: options.Database, + SiteFS: site.FS(), + OAuth2Configs: oauthConfigs, + }) + staticHandler.Experiments.Store(&experiments) + ctx, cancel := context.WithCancel(context.Background()) r := chi.NewRouter() diff --git a/site/site.go b/site/site.go index a358d458e561a..e076a65bf18c9 100644 --- a/site/site.go +++ b/site/site.go @@ -61,10 +61,11 @@ func init() { } type Options struct { - BinFS http.FileSystem - BinHashes map[string]string - Database database.Store - SiteFS fs.FS + BinFS http.FileSystem + BinHashes map[string]string + Database database.Store + SiteFS fs.FS + OAuth2Configs *httpmw.OAuth2Configs } func New(opts *Options) *Handler { @@ -290,8 +291,9 @@ func (h *Handler) renderHTMLWithState(rw http.ResponseWriter, r *http.Request, f // Cookies are sent when requesting HTML, so we can get the user // and pre-populate the state for the frontend to reduce requests. apiKey, actor, _ := httpmw.ExtractAPIKey(rw, r, httpmw.ExtractAPIKeyConfig{ - Optional: true, - DB: h.opts.Database, + Optional: true, + DB: h.opts.Database, + OAuth2Configs: h.opts.OAuth2Configs, }) if apiKey != nil && actor != nil { ctx := dbauthz.As(r.Context(), actor.Actor) From 62591187ac0f5b26902d97a3388f9dadca92e553 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Mon, 10 Jul 2023 12:45:34 +0000 Subject: [PATCH 2/2] add special case for site --- site/site.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/site/site.go b/site/site.go index e076a65bf18c9..98ec8000fb761 100644 --- a/site/site.go +++ b/site/site.go @@ -294,6 +294,9 @@ func (h *Handler) renderHTMLWithState(rw http.ResponseWriter, r *http.Request, f Optional: true, DB: h.opts.Database, OAuth2Configs: h.opts.OAuth2Configs, + // Special case for site, we can always disable refresh here because + // the frontend will perform API requests if this fails. + DisableSessionExpiryRefresh: true, }) if apiKey != nil && actor != nil { ctx := dbauthz.As(r.Context(), actor.Actor)