Files
coder/coderd/httpmw/oauth2provider.go
T
Bobby Ho 4ee70c66c3 feat: gate the OAuth2 provider on CODER_OAUTH2_PROVIDER_ENABLE (#29251)
Second of five for PLAT-492. Gates all OAuth2 provider routes and dashboard navigation on CODER_OAUTH2_PROVIDER_ENABLE instead of the oauth2 experiment. The flag is off by default, so deployments using CODER_EXPERIMENTS=oauth2 must set it before upgrading or OAuth2 clients will receive 404s. Existing apps, tokens, secrets, and DCR settings are unchanged. Stacked on #29248 and labeled release/breaking; the next PR makes the old experiment a no-op with a migration warning.
2026-09-14 13:47:48 -07:00

26 lines
727 B
Go

package httpmw
import (
"net/http"
"github.com/coder/coder/v2/coderd/httpapi"
)
// RequireOAuth2Provider returns 404 for every request while the OAuth2
// provider is disabled. A disabled provider looks the same as a deployment
// that never had one, which is what RFC 8414 and RFC 9728 discovery clients
// expect. There is no bypass for development builds.
//
//nolint:revive // The flag is fixed for the life of the process.
func RequireOAuth2Provider(enabled bool) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
if !enabled {
httpapi.RouteNotFound(rw)
return
}
next.ServeHTTP(rw, r)
})
}
}