Skip to content

Commit 7e7cda5

Browse files
committed
Add dev and entitlement checks to oauth2 provider
The endpoints are disabled until we can implement the token exchange.
1 parent 7c3b1b1 commit 7e7cda5

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

enterprise/coderd/coderd.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,10 @@ func New(ctx context.Context, options *Options) (_ *API, err error) {
312312
r.Put("/", api.putUserQuietHoursSchedule)
313313
})
314314
r.Route("/oauth2-provider", func(r chi.Router) {
315-
r.Use(apiKeyMiddleware)
316-
315+
r.Use(
316+
apiKeyMiddleware,
317+
api.oAuth2ProviderMiddleware,
318+
)
317319
r.Route("/apps", func(r chi.Router) {
318320
r.Get("/", api.oAuth2ProviderApps)
319321
r.Post("/", api.postOAuth2ProviderApp)

enterprise/coderd/oauth2.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/google/uuid"
88

9+
"github.com/coder/coder/v2/buildinfo"
910
"github.com/coder/coder/v2/coderd/database"
1011
"github.com/coder/coder/v2/coderd/database/db2sdk"
1112
"github.com/coder/coder/v2/coderd/database/dbtime"
@@ -15,6 +16,30 @@ import (
1516
"github.com/coder/coder/v2/cryptorand"
1617
)
1718

19+
func (api *API) oAuth2ProviderMiddleware(next http.Handler) http.Handler {
20+
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
21+
if !buildinfo.IsDev() {
22+
httpapi.Write(r.Context(), rw, http.StatusForbidden, codersdk.Response{
23+
Message: "OAuth2 provider is under development.",
24+
})
25+
return
26+
}
27+
28+
api.entitlementsMu.RLock()
29+
entitled := api.entitlements.Features[codersdk.FeatureOAuth2Provider].Entitlement != codersdk.EntitlementNotEntitled
30+
api.entitlementsMu.RUnlock()
31+
32+
if !entitled {
33+
httpapi.Write(r.Context(), rw, http.StatusForbidden, codersdk.Response{
34+
Message: "OAuth2 provider is an Enterprise feature. Contact sales!",
35+
})
36+
return
37+
}
38+
39+
next.ServeHTTP(rw, r)
40+
})
41+
}
42+
1843
// @Summary Get OAuth2 applications.
1944
// @ID get-oauth2-applications
2045
// @Security CoderSessionToken

0 commit comments

Comments
 (0)