Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat: improve local testing for VCS (#2625)

tianzhouf1bade60c7e9
diff --git a/server/oauth.go b/server/oauth.go
index b339af4436..c9d989183a 100644
--- a/server/oauth.go
+++ b/server/oauth.go
@@ -67,7 +67,7 @@ func (s *Server) registerOAuthRoutes(g *echo.Group) {
}
}
- oauthExchange.RedirectURL = fmt.Sprintf("%s/oauth/callback", s.profile.ExternalURL)
+ oauthExchange.RedirectURL = fmt.Sprintf("%s/oauth/callback", oauthRedirectURL(s.profile.ExternalURL))
oauthToken, err := vcsPlugin.Get(vcsType, vcsPlugin.ProviderConfig{}).
ExchangeOAuthToken(
c.Request().Context(),
@@ -75,7 +75,7 @@ func (s *Server) registerOAuthRoutes(g *echo.Group) {
oauthExchange,
)
if err != nil {
- return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to exchange OAuth token. Make sure --external-url: %s matches your browser host.", s.profile.ExternalURL)).SetInternal(err)
+ return echo.NewHTTPError(http.StatusInternalServerError, oauthErrorMessage(oauthExchange.RedirectURL)).SetInternal(err)
}
resp := &api.OAuthToken{
diff --git a/server/server_frontend_embed.go b/server/server_frontend_embed.go
index de4b30c19e..dbbee22cf5 100644
--- a/server/server_frontend_embed.go
+++ b/server/server_frontend_embed.go
@@ -5,6 +5,7 @@ package server
import (
"embed"
+ "fmt"
"io/fs"
"net/http"
@@ -45,3 +46,11 @@ func embedFrontend(e *echo.Echo) {
Filesystem: getFileSystem("dist/assets"),
}))
}
+
+func oauthRedirectURL(externalURL string) string {
+ return externalURL
+}
+
+func oauthErrorMessage(redirectURL string) string {
+ return fmt.Sprintf("Failed to exchange OAuth token. Make sure --external-url: %s matches your browser host.", redirectURL)
+}
diff --git a/server/server_frontend_not_embed.go b/server/server_frontend_not_embed.go
index 479e454510..b18bb9ef5f 100644
--- a/server/server_frontend_not_embed.go
+++ b/server/server_frontend_not_embed.go
@@ -4,6 +4,7 @@
package server
import (
+ "fmt"
"net/http"
"github.com/labstack/echo/v4"
@@ -18,3 +19,13 @@ func embedFrontend(e *echo.Echo) {
return c.HTML(http.StatusOK, "This Bytebase build does not bundle frontend and backend together.")
})
}
+
+// In non embedded mode, the redirect URL is the frontend URL which is different
+// from the external URL. By default, this frontend URL is http://localhost:3000
+func oauthRedirectURL(_ string) string {
+ return "http://localhost:3000"
+}
+
+func oauthErrorMessage(redirectURL string) string {
+ return fmt.Sprintf("Failed to exchange OAuth token. Make sure oauthRedirectURL: %s matches your browser host.", redirectURL)
+}