Skip to content

Commit

Permalink
fix(cli): fix oauth flow (#3169)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgeepc committed Sep 20, 2023
1 parent b5cb94e commit 23aff08
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cli/config/config.go
Expand Up @@ -17,6 +17,8 @@ var (
Version = "dev"
Env = "dev"
DefaultCloudAPIEndpoint = "http://localhost:8090"
DefaultCloudDomain = "tracetest.io"
DefaultCloudPath = "/"
)

type ConfigFlags struct {
Expand Down
5 changes: 5 additions & 0 deletions cli/config/configurator.go
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/http"
"strings"

"github.com/kubeshop/tracetest/cli/analytics"
"github.com/kubeshop/tracetest/cli/pkg/oauth"
Expand Down Expand Up @@ -60,6 +61,10 @@ func (c Configurator) Start(ctx context.Context, prev Config, flags ConfigFlags)
return err
}

if strings.Contains(serverURL, DefaultCloudDomain) {
path = &DefaultCloudPath
}

cfg := Config{
Scheme: scheme,
Endpoint: endpoint,
Expand Down
3 changes: 2 additions & 1 deletion cli/pkg/oauth/oauth.go
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"net"
"net/http"
"strings"
"sync"

"github.com/kubeshop/tracetest/cli/ui"
Expand Down Expand Up @@ -115,7 +116,7 @@ func (s *OAuthServer) start() error {

func (s *OAuthServer) callback(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.Header().Set("Access-Control-Allow-Origin", s.frontendEndpoint)
w.Header().Set("Access-Control-Allow-Origin", strings.TrimSuffix(s.frontendEndpoint, "/"))

w.WriteHeader(http.StatusOK)
w.Write([]byte(`{"success": true}`))
Expand Down

0 comments on commit 23aff08

Please sign in to comment.