Skip to content

Commit a8f4c7a

Browse files
KevyVoKevyVo
and
KevyVo
authored
Found that auth was not flowing prompt bool (#1121)
Co-authored-by: KevyVo <[email protected]>
1 parent 8311cda commit a8f4c7a

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

src/cmd/cli/command/commands.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ var RootCmd = &cobra.Command{
369369
term.Warn("Please log in to continue.")
370370

371371
defer func() { track.Cmd(nil, "Login", P("reason", err)) }()
372-
if err = cli.InteractiveLogin(cmd.Context(), client, gitHubClientId, getCluster()); err != nil {
372+
if err = cli.InteractiveLogin(cmd.Context(), client, gitHubClientId, getCluster(), false); err != nil {
373373
return err
374374
}
375375

@@ -407,7 +407,7 @@ var loginCmd = &cobra.Command{
407407
return err
408408
}
409409
} else {
410-
err := cli.InteractiveLogin(cmd.Context(), client, gitHubClientId, getCluster())
410+
err := cli.InteractiveLogin(cmd.Context(), client, gitHubClientId, getCluster(), false)
411411
if err != nil {
412412
return err
413413
}

src/pkg/cli/login.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ func GetExistingToken(fabric string) string {
3737
}
3838

3939
type GitHubAuth interface {
40-
login(ctx context.Context, client client.FabricClient, gitHubClientId, fabric string) (string, error)
40+
login(ctx context.Context, client client.FabricClient, gitHubClientId, fabric string, prompt bool) (string, error)
4141
}
4242

4343
type GitHubAuthService struct{}
4444

4545
func (g GitHubAuthService) login(
46-
ctx context.Context, client client.FabricClient, gitHubClientId, fabric string,
46+
ctx context.Context, client client.FabricClient, gitHubClientId, fabric string, prompt bool,
4747
) (string, error) {
4848
term.Debug("Logging in to", fabric)
4949

50-
code, err := github.StartAuthCodeFlow(ctx, gitHubClientId, false)
50+
code, err := github.StartAuthCodeFlow(ctx, gitHubClientId, prompt)
5151
if err != nil {
5252
return "", err
5353
}
@@ -68,8 +68,8 @@ func saveAccessToken(fabric, at string) error {
6868
return nil
6969
}
7070

71-
func InteractiveLogin(ctx context.Context, client client.FabricClient, gitHubClientId, fabric string) error {
72-
at, err := githubAuthService.login(ctx, client, gitHubClientId, fabric)
71+
func InteractiveLogin(ctx context.Context, client client.FabricClient, gitHubClientId, fabric string, prompt bool) error {
72+
at, err := githubAuthService.login(ctx, client, gitHubClientId, fabric, prompt)
7373
if err != nil {
7474
return err
7575
}

src/pkg/cli/login_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ func TestGetExistingToken(t *testing.T) {
4242

4343
type MockGitHubAuthService struct {
4444
GitHubAuthService
45-
MockLogin func(ctx context.Context, client client.FabricClient, gitHubClientId, fabric string) (string, error)
45+
MockLogin func(ctx context.Context, client client.FabricClient, gitHubClientId, fabric string, prompt bool) (string, error)
4646
}
4747

4848
func (g MockGitHubAuthService) login(
49-
ctx context.Context, client client.FabricClient, gitHubClientId, fabric string,
49+
ctx context.Context, client client.FabricClient, gitHubClientId, fabric string, prompt bool,
5050
) (string, error) {
51-
return g.MockLogin(ctx, client, gitHubClientId, fabric)
51+
return g.MockLogin(ctx, client, gitHubClientId, fabric, prompt)
5252
}
5353

5454
func TestInteractiveLogin(t *testing.T) {
@@ -69,13 +69,13 @@ func TestInteractiveLogin(t *testing.T) {
6969
t.Run("Expect accessToken to be stored when InteractiveLogin() succeeds", func(t *testing.T) {
7070
githubAuthService = MockGitHubAuthService{
7171
MockLogin: func(
72-
ctx context.Context, client client.FabricClient, gitHubClientId, fabric string,
72+
ctx context.Context, client client.FabricClient, gitHubClientId, fabric string, prompt bool,
7373
) (string, error) {
7474
return accessToken, nil
7575
},
7676
}
7777

78-
err := InteractiveLogin(context.Background(), client.MockFabricClient{}, "github-client-id", fabric)
78+
err := InteractiveLogin(context.Background(), client.MockFabricClient{}, "github-client-id", fabric, false)
7979
if err != nil {
8080
t.Fatalf("expected no error, got %v", err)
8181
}
@@ -90,12 +90,12 @@ func TestInteractiveLogin(t *testing.T) {
9090

9191
t.Run("Expect error when InteractiveLogin fails", func(t *testing.T) {
9292
githubAuthService = MockGitHubAuthService{
93-
MockLogin: func(ctx context.Context, client client.FabricClient, gitHubClientId, fabric string) (string, error) {
93+
MockLogin: func(ctx context.Context, client client.FabricClient, gitHubClientId, fabric string, prompt bool) (string, error) {
9494
return "", errors.New("test-error")
9595
},
9696
}
9797

98-
err := InteractiveLogin(context.Background(), client.MockFabricClient{}, "github-client-id", fabric)
98+
err := InteractiveLogin(context.Background(), client.MockFabricClient{}, "github-client-id", fabric, false)
9999
if err == nil {
100100
t.Fatalf("expected no error, got %v", err)
101101
}

src/pkg/github/auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func StartAuthCodeFlow(ctx context.Context, clientId string, prompt bool) (strin
107107
defer term.Print(strings.Repeat(" ", n), "\r") // TODO: use termenv to clear line
108108

109109
// TODO:This is used to open the browser for GitHub Auth before blocking
110-
if !prompt {
110+
if prompt {
111111
browser.OpenURL(server.URL)
112112
}
113113

src/pkg/mcp/tools/login.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func setupLoginTool(s *server.MCPServer, client client.GrpcClient, cluster strin
2323
term.Info("Adding login tool handler")
2424
s.AddTool(loginTool, func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
2525
// Test token
26-
err := cli.InteractiveLogin(ctx, client, gitHubClientId, cluster)
26+
err := cli.InteractiveLogin(ctx, client, gitHubClientId, cluster, true)
2727
if err != nil {
2828
return mcp.NewToolResultText(fmt.Sprintf("Failed to login: %v", err)), nil
2929
}

0 commit comments

Comments
 (0)