diff --git a/utils/const.go b/utils/const.go index 362adfef..3afc70fe 100644 --- a/utils/const.go +++ b/utils/const.go @@ -1,12 +1,13 @@ package utils import ( + "fmt" "log" "os" ) func GetFeatureExperimentationHost() string { - if os.Getenv("FS_STAGING") == "true" { + if os.Getenv("ABT_STAGING") == "true" { return "https://staging-api.flagship.io" } @@ -14,7 +15,7 @@ func GetFeatureExperimentationHost() string { } func GetWebExperimentationHost() string { - if os.Getenv("FS_STAGING") == "true" { + if os.Getenv("ABT_STAGING") == "true" { return "https://staging-api.abtasty.com/api" } @@ -22,7 +23,7 @@ func GetWebExperimentationHost() string { } func GetHostFeatureExperimentationAuth() string { - if os.Getenv("FS_STAGING") == "true" { + if os.Getenv("ABT_STAGING") == "true" { return "https://staging-auth.flagship.io" } @@ -30,13 +31,29 @@ func GetHostFeatureExperimentationAuth() string { } func GetHostWebExperimentationAuth() string { - if os.Getenv("FS_STAGING") == "true" { + if os.Getenv("ABT_STAGING") == "true" { return "https://staging-api-auth.abtasty.com" } return "https://api-auth.abtasty.com" } +func GetWebExperimentationBrowserAuth(clientId, clientSecret string) string { + if os.Getenv("ABT_STAGING") == "true" { + return fmt.Sprintf(`https://staging-auth.abtasty.com/authorize?client_id=%s&client_secret=%s&redirect_uri=http://localhost:8010/auth/callback`, clientId, clientSecret) + } + + return fmt.Sprintf(`https://auth.abtasty.com/authorize?client_id=%s&client_secret=%s&redirect_uri=http://localhost:8010/auth/callback`, clientId, clientSecret) +} + +func GetWebExperimentationBrowserAuthSuccess() string { + if os.Getenv("ABT_STAGING") == "true" { + return "https://staging-auth.abtasty.com/authorization-granted" + } + + return "https://auth.abtasty.com/authorization-granted" +} + func DefaultGlobalCodeWorkingDir() string { wdDir, err := os.Getwd() if err != nil { diff --git a/utils/http_request/common/token.go b/utils/http_request/common/token.go index b675ada1..9766dd88 100644 --- a/utils/http_request/common/token.go +++ b/utils/http_request/common/token.go @@ -41,7 +41,7 @@ func handleCallback(w http.ResponseWriter, r *http.Request, codeChan chan<- stri codeChan <- code - http.Redirect(w, r, "https://auth.abtasty.com/authorization-granted", http.StatusSeeOther) + http.Redirect(w, r, utils.GetWebExperimentationBrowserAuthSuccess(), http.StatusSeeOther) go func() { time.Sleep(5 * time.Second) @@ -112,7 +112,7 @@ func InitiateBrowserAuth(username, clientID, clientSecret string) (models.TokenR } codeChan := make(chan string) - var url = fmt.Sprintf("https://auth.abtasty.com/authorize?client_id=%s&client_secret=%s&redirect_uri=http://localhost:8010/auth/callback", clientID, clientSecret) + var url = utils.GetWebExperimentationBrowserAuth(clientID, clientSecret) if err := openLink(url); err != nil { log.Fatalf("Error opening link: %s", err)