Skip to content

Found that auth was not following prompt bool #1121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/cmd/cli/command/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ var RootCmd = &cobra.Command{
term.Warn("Please log in to continue.")

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

Expand Down Expand Up @@ -407,7 +407,7 @@ var loginCmd = &cobra.Command{
return err
}
} else {
err := cli.InteractiveLogin(cmd.Context(), client, gitHubClientId, getCluster())
err := cli.InteractiveLogin(cmd.Context(), client, gitHubClientId, getCluster(), false)
if err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions src/pkg/cli/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ func GetExistingToken(fabric string) string {
}

type GitHubAuth interface {
login(ctx context.Context, client client.FabricClient, gitHubClientId, fabric string) (string, error)
login(ctx context.Context, client client.FabricClient, gitHubClientId, fabric string, prompt bool) (string, error)
}

type GitHubAuthService struct{}

func (g GitHubAuthService) login(
ctx context.Context, client client.FabricClient, gitHubClientId, fabric string,
ctx context.Context, client client.FabricClient, gitHubClientId, fabric string, prompt bool,
) (string, error) {
term.Debug("Logging in to", fabric)

code, err := github.StartAuthCodeFlow(ctx, gitHubClientId, false)
code, err := github.StartAuthCodeFlow(ctx, gitHubClientId, prompt)
if err != nil {
return "", err
}
Expand All @@ -68,8 +68,8 @@ func saveAccessToken(fabric, at string) error {
return nil
}

func InteractiveLogin(ctx context.Context, client client.FabricClient, gitHubClientId, fabric string) error {
at, err := githubAuthService.login(ctx, client, gitHubClientId, fabric)
func InteractiveLogin(ctx context.Context, client client.FabricClient, gitHubClientId, fabric string, prompt bool) error {
at, err := githubAuthService.login(ctx, client, gitHubClientId, fabric, prompt)
if err != nil {
return err
}
Expand Down
14 changes: 7 additions & 7 deletions src/pkg/cli/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ func TestGetExistingToken(t *testing.T) {

type MockGitHubAuthService struct {
GitHubAuthService
MockLogin func(ctx context.Context, client client.FabricClient, gitHubClientId, fabric string) (string, error)
MockLogin func(ctx context.Context, client client.FabricClient, gitHubClientId, fabric string, prompt bool) (string, error)
}

func (g MockGitHubAuthService) login(
ctx context.Context, client client.FabricClient, gitHubClientId, fabric string,
ctx context.Context, client client.FabricClient, gitHubClientId, fabric string, prompt bool,
) (string, error) {
return g.MockLogin(ctx, client, gitHubClientId, fabric)
return g.MockLogin(ctx, client, gitHubClientId, fabric, prompt)
}

func TestInteractiveLogin(t *testing.T) {
Expand All @@ -69,13 +69,13 @@ func TestInteractiveLogin(t *testing.T) {
t.Run("Expect accessToken to be stored when InteractiveLogin() succeeds", func(t *testing.T) {
githubAuthService = MockGitHubAuthService{
MockLogin: func(
ctx context.Context, client client.FabricClient, gitHubClientId, fabric string,
ctx context.Context, client client.FabricClient, gitHubClientId, fabric string, prompt bool,
) (string, error) {
return accessToken, nil
},
}

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

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

err := InteractiveLogin(context.Background(), client.MockFabricClient{}, "github-client-id", fabric)
err := InteractiveLogin(context.Background(), client.MockFabricClient{}, "github-client-id", fabric, false)
if err == nil {
t.Fatalf("expected no error, got %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/github/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func StartAuthCodeFlow(ctx context.Context, clientId string, prompt bool) (strin
defer term.Print(strings.Repeat(" ", n), "\r") // TODO: use termenv to clear line

// TODO:This is used to open the browser for GitHub Auth before blocking
if !prompt {
if prompt {
browser.OpenURL(server.URL)
}

Expand Down
2 changes: 1 addition & 1 deletion src/pkg/mcp/tools/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func setupLoginTool(s *server.MCPServer, client client.GrpcClient, cluster strin
term.Info("Adding login tool handler")
s.AddTool(loginTool, func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
// Test token
err := cli.InteractiveLogin(ctx, client, gitHubClientId, cluster)
err := cli.InteractiveLogin(ctx, client, gitHubClientId, cluster, true)
if err != nil {
return mcp.NewToolResultText(fmt.Sprintf("Failed to login: %v", err)), nil
}
Expand Down
Loading