@@ -200,9 +200,7 @@ func NewAPIWithVersion(globalConfig *conf.GlobalConfiguration, db *storage.Conne
200200 // Both OIDC Discovery and OAuth Authorization Server Metadata use the same unified handler
201201 // OIDC Discovery is an extension of RFC 8414, so one response satisfies both specs
202202 r .Get ("/.well-known/openid-configuration" , api .WellKnownOpenID )
203- if globalConfig .OAuthServer .Enabled {
204- r .Get ("/.well-known/oauth-authorization-server" , api .WellKnownOpenID )
205- }
203+ r .With (api .requireOAuthServerEnabled ).Get ("/.well-known/oauth-authorization-server" , api .WellKnownOpenID )
206204
207205 r .Route ("/callback" , func (r * router ) {
208206 r .Use (api .isValidExternalHost )
@@ -285,13 +283,12 @@ func NewAPIWithVersion(globalConfig *conf.GlobalConfiguration, db *storage.Conne
285283 r .Delete ("/{identity_id}" , api .DeleteIdentity )
286284 })
287285
288- // OAuth grant management endpoints (only if OAuth server is enabled)
289- if globalConfig .OAuthServer .Enabled {
290- r .Route ("/oauth/grants" , func (r * router ) {
291- r .Get ("/" , api .oauthServer .UserListOAuthGrants )
292- r .Delete ("/" , api .oauthServer .UserRevokeOAuthGrant )
293- })
294- }
286+ // OAuth grant management endpoints
287+ r .Route ("/oauth/grants" , func (r * router ) {
288+ r .Use (api .requireOAuthServerEnabled )
289+ r .Get ("/" , api .oauthServer .UserListOAuthGrants )
290+ r .Delete ("/" , api .oauthServer .UserRevokeOAuthGrant )
291+ })
295292 })
296293
297294 r .With (api .requireAuthentication ).Route ("/factors" , func (r * router ) {
@@ -397,60 +394,57 @@ func NewAPIWithVersion(globalConfig *conf.GlobalConfiguration, db *storage.Conne
397394 })
398395
399396 // Admin only oauth client management endpoints
400- if globalConfig .OAuthServer .Enabled {
401- r .Route ("/oauth" , func (r * router ) {
402- r .Route ("/clients" , func (r * router ) {
403- // Manual client registration
404- r .Post ("/" , api .oauthServer .AdminOAuthServerClientRegister )
405-
406- r .Get ("/" , api .oauthServer .OAuthServerClientList )
407-
408- r .Route ("/{client_id}" , func (r * router ) {
409- r .Use (api .oauthServer .LoadOAuthServerClient )
410- r .Get ("/" , api .oauthServer .OAuthServerClientGet )
411- r .Put ("/" , api .oauthServer .OAuthServerClientUpdate )
412- r .Delete ("/" , api .oauthServer .OAuthServerClientDelete )
413- r .Post ("/regenerate_secret" , api .oauthServer .OAuthServerClientRegenerateSecret )
414- })
397+ r .Route ("/oauth" , func (r * router ) {
398+ r .Use (api .requireOAuthServerEnabled )
399+ r .Route ("/clients" , func (r * router ) {
400+ // Manual client registration
401+ r .Post ("/" , api .oauthServer .AdminOAuthServerClientRegister )
402+
403+ r .Get ("/" , api .oauthServer .OAuthServerClientList )
404+
405+ r .Route ("/{client_id}" , func (r * router ) {
406+ r .Use (api .oauthServer .LoadOAuthServerClient )
407+ r .Get ("/" , api .oauthServer .OAuthServerClientGet )
408+ r .Put ("/" , api .oauthServer .OAuthServerClientUpdate )
409+ r .Delete ("/" , api .oauthServer .OAuthServerClientDelete )
410+ r .Post ("/regenerate_secret" , api .oauthServer .OAuthServerClientRegenerateSecret )
415411 })
416412 })
417- }
413+ })
418414
419415 // Custom OAuth/OIDC provider management endpoints
420- if globalConfig .CustomOAuth .Enabled {
421- r .Route ("/custom-providers" , func (r * router ) {
422- // supports both OAuth2 and OIDC via provider_type)
423- r .Get ("/" , api .adminCustomOAuthProvidersList ) // Optional ?type=oauth2 or ?type=oidc filter
424- r .Post ("/" , api .adminCustomOAuthProviderCreate ) // provider_type in request body
425-
426- r .Route ("/{identifier}" , func (r * router ) {
427- r .Get ("/" , api .adminCustomOAuthProviderGet )
428- r .Put ("/" , api .adminCustomOAuthProviderUpdate )
429- r .Delete ("/" , api .adminCustomOAuthProviderDelete )
430- })
416+ r .Route ("/custom-providers" , func (r * router ) {
417+ r .Use (api .requireCustomOAuthEnabled )
418+ // supports both OAuth2 and OIDC via provider_type)
419+ r .Get ("/" , api .adminCustomOAuthProvidersList ) // Optional ?type=oauth2 or ?type=oidc filter
420+ r .Post ("/" , api .adminCustomOAuthProviderCreate ) // provider_type in request body
421+
422+ r .Route ("/{identifier}" , func (r * router ) {
423+ r .Get ("/" , api .adminCustomOAuthProviderGet )
424+ r .Put ("/" , api .adminCustomOAuthProviderUpdate )
425+ r .Delete ("/" , api .adminCustomOAuthProviderDelete )
431426 })
432- }
427+ })
433428 })
434429
435430 // OAuth Dynamic Client Registration endpoint (public, rate limited)
436- if globalConfig .OAuthServer .Enabled {
437- r .Route ("/oauth" , func (r * router ) {
438- r .With (api .limitHandler (api .limiterOpts .OAuthClientRegister )).
439- Post ("/clients/register" , api .oauthServer .OAuthServerClientDynamicRegister )
440-
441- // OAuth Token endpoint (public, with client authentication)
442- r .With (api .requireOAuthClientAuth ).Post ("/token" , api .oauthServer .OAuthToken )
443-
444- // OIDC UserInfo endpoint (requires user authentication via Bearer token)
445- r .With (api .requireAuthentication ).Get ("/userinfo" , api .oauthServer .OAuthUserInfo )
446-
447- // OAuth 2.1 Authorization endpoints
448- // `/authorize` to initiate OAuth2 authorization code flow where Supabase Auth is the OAuth2 provider
449- r .Get ("/authorize" , api .oauthServer .OAuthServerAuthorize )
450- r .With (api .requireAuthentication ).Get ("/authorizations/{authorization_id}" , api .oauthServer .OAuthServerGetAuthorization )
451- r .With (api .requireAuthentication ).Post ("/authorizations/{authorization_id}/consent" , api .oauthServer .OAuthServerConsent )
452- })
453- }
431+ r .Route ("/oauth" , func (r * router ) {
432+ r .Use (api .requireOAuthServerEnabled )
433+ r .With (api .limitHandler (api .limiterOpts .OAuthClientRegister )).
434+ Post ("/clients/register" , api .oauthServer .OAuthServerClientDynamicRegister )
435+
436+ // OAuth Token endpoint (public, with client authentication)
437+ r .With (api .requireOAuthClientAuth ).Post ("/token" , api .oauthServer .OAuthToken )
438+
439+ // OIDC UserInfo endpoint (requires user authentication via Bearer token)
440+ r .With (api .requireAuthentication ).Get ("/userinfo" , api .oauthServer .OAuthUserInfo )
441+
442+ // OAuth 2.1 Authorization endpoints
443+ // `/authorize` to initiate OAuth2 authorization code flow where Supabase Auth is the OAuth2 provider
444+ r .Get ("/authorize" , api .oauthServer .OAuthServerAuthorize )
445+ r .With (api .requireAuthentication ).Get ("/authorizations/{authorization_id}" , api .oauthServer .OAuthServerGetAuthorization )
446+ r .With (api .requireAuthentication ).Post ("/authorizations/{authorization_id}/consent" , api .oauthServer .OAuthServerConsent )
447+ })
454448 })
455449
456450 corsHandler := cors .New (cors.Options {
0 commit comments