Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(coderd): pass oauth configs to site #8390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(coderd): pass oauth configs to site
Fixes #8351
  • Loading branch information
mafredri committed Jul 10, 2023
commit 87eaa0fcb543a4a5a10ec8855cc1f087521c91ec
17 changes: 9 additions & 8 deletions coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
14 changes: 8 additions & 6 deletions site/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Copy link
Member Author

@mafredri mafredri Jul 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we pass other extract api key configs, like DisableSessionExpiryRefresh, too?

Edit: We also don't seem to be utilizing e.g. DisableSessionExpiryRefresh in enterprise/coderd, is this a bug?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/ping @deansheather (ref: #5976)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah we should be setting that flag everywhere we use it, so this is definitely a bug.

For this specific case though, we can just set it to true because it doesn't matter if loading the frontend doesn't refresh the token (because the frontend will make API requests after loading the page).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @deansheather, added the always true and an accompanying comment.

})
if apiKey != nil && actor != nil {
ctx := dbauthz.As(r.Context(), actor.Actor)
Expand Down