Skip to content

Commit

Permalink
Add signup URL to authconfig payload (#464)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeykazakov authored Sep 23, 2024
1 parent cbd0f40 commit d7ff96d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (r RegistrationServiceConfig) LogLevel() string {
}

func (r RegistrationServiceConfig) RegistrationServiceURL() string {
return commonconfig.GetString(r.cfg.Host.RegistrationService.RegistrationServiceURL, "https://registration.crt-placeholder.com")
return commonconfig.GetString(r.cfg.Host.RegistrationService.RegistrationServiceURL, "")
}

func (r RegistrationServiceConfig) Verification() VerificationConfig {
Expand Down
2 changes: 1 addition & 1 deletion pkg/configuration/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestRegistrationService(t *testing.T) {
// then
assert.Equal(t, "prod", regServiceCfg.Environment())
assert.Equal(t, "info", regServiceCfg.LogLevel())
assert.Equal(t, "https://registration.crt-placeholder.com", regServiceCfg.RegistrationServiceURL())
assert.Equal(t, "", regServiceCfg.RegistrationServiceURL())
assert.Empty(t, regServiceCfg.Analytics().SegmentWriteKey())
assert.Empty(t, regServiceCfg.Analytics().DevSpacesSegmentWriteKey())
assert.Equal(t, "https://sso.devsandbox.dev/auth/js/keycloak.js", regServiceCfg.Auth().AuthClientLibraryURL())
Expand Down
4 changes: 4 additions & 0 deletions pkg/controller/authconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ type configResponse struct {
// this holds the raw config. Note: this is intentionally a string
// not json as this field may also hold non-json configs!
AuthClientConfigRaw string `json:"auth-client-config"`
// The signup page URL. After user logs into SSO but has not signed up yet then this URL can be used to redirect the user to
// sign up. If not set then the base URL of the registration service is supposed to be used by the clients.
SignupURL string `json:"signup-url"`
}

// AuthConfig implements the auth config endpoint, which is invoked to
Expand All @@ -30,6 +33,7 @@ func (ac *AuthConfig) GetHandler(ctx *gin.Context) {
configRespData := configResponse{
AuthClientLibraryURL: cfg.Auth().AuthClientLibraryURL(),
AuthClientConfigRaw: cfg.Auth().AuthClientConfigRaw(),
SignupURL: cfg.RegistrationServiceURL(),
}
ctx.JSON(http.StatusOK, configRespData)
}
9 changes: 9 additions & 0 deletions pkg/controller/authconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"net/http/httptest"
"testing"

testconfig "github.com/codeready-toolchain/toolchain-common/pkg/test/config"

"github.com/codeready-toolchain/registration-service/pkg/configuration"
"github.com/codeready-toolchain/registration-service/test"

Expand All @@ -31,6 +33,9 @@ func (s *TestAuthConfigSuite) TestAuthClientConfigHandler() {

// Check if the config is set to testing mode, so the handler may use this.
assert.True(s.T(), configuration.IsTestingMode(), "testing mode not set correctly to true")
s.OverrideApplicationDefault(testconfig.RegistrationService().
RegistrationServiceURL("https://signup.domain.com"))
defer s.DefaultConfig()
cfg := configuration.GetRegistrationServiceConfig()

// Create handler instance.
Expand Down Expand Up @@ -115,5 +120,9 @@ func (s *TestAuthConfigSuite) TestAuthClientConfigHandler() {
assert.Equal(s.T(), config["public-client"], valBool, "wrong 'public-client' in authconfig response")
})
})

s.Run("envelope signup url", func() {
assert.Equal(s.T(), "https://signup.domain.com", dataEnvelope.SignupURL)
})
})
}

0 comments on commit d7ff96d

Please sign in to comment.