Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix(oauth2): return usable URLs in OAuth discovery for self-hosted mode (#19806)
Vincent Huang42977d985b2b
diff --git a/backend/api/oauth2/discovery.go b/backend/api/oauth2/discovery.goindex abb92181fd..4218b5f6e6 100644--- a/backend/api/oauth2/discovery.go+++ b/backend/api/oauth2/discovery.go@@ -62,12 +62,13 @@ func (s *Service) getBaseURL(c *echo.Context) string {func (s *Service) handleDiscovery(c *echo.Context) error {baseURL := s.getBaseURL(c)+ oauthBase := s.getOAuthBasePath(c, baseURL)metadata := &authorizationServerMetadata{Issuer: baseURL,- AuthorizationEndpoint: fmt.Sprintf("%s/api/workspaces/:workspaceID/oauth2/authorize", baseURL),- TokenEndpoint: fmt.Sprintf("%s/api/workspaces/:workspaceID/oauth2/token", baseURL),- RegistrationEndpoint: fmt.Sprintf("%s/api/workspaces/:workspaceID/oauth2/register", baseURL),- RevocationEndpoint: fmt.Sprintf("%s/api/workspaces/:workspaceID/oauth2/revoke", baseURL),+ AuthorizationEndpoint: fmt.Sprintf("%s/authorize", oauthBase),+ TokenEndpoint: fmt.Sprintf("%s/token", oauthBase),+ RegistrationEndpoint: fmt.Sprintf("%s/register", oauthBase),+ RevocationEndpoint: fmt.Sprintf("%s/revoke", oauthBase),ResponseTypesSupported: []string{"code"},GrantTypesSupported: []string{"authorization_code", "refresh_token"},CodeChallengeMethodsSupported: []string{"S256"},@@ -76,6 +77,18 @@ func (s *Service) handleDiscovery(c *echo.Context) error {return c.JSON(http.StatusOK, metadata)}+// getOAuthBasePath returns the base path for OAuth2 endpoints.+// In self-hosted mode, it uses legacy paths that don't require a workspace ID.+// In SaaS mode, the discovery endpoint cannot resolve a workspace ID (the route+// has no :workspaceID param), so it falls back to templated URLs. SaaS workspace+// discovery requires a separate mechanism (e.g., workspace-scoped well-known endpoint).+func (s *Service) getOAuthBasePath(_ *echo.Context, baseURL string) string {+ if !s.profile.SaaS {+ return fmt.Sprintf("%s/api/oauth2", baseURL)+ }+ return fmt.Sprintf("%s/api/workspaces/:workspaceID/oauth2", baseURL)+}+// handleProtectedResourceMetadata returns RFC 9728 protected resource metadata.// This tells clients which authorization server protects this resource.func (s *Service) handleProtectedResourceMetadata(c *echo.Context) error {