diff --git a/pkg/cmd/auth/status/status.go b/pkg/cmd/auth/status/status.go index 014f3e7b6..417a0773c 100644 --- a/pkg/cmd/auth/status/status.go +++ b/pkg/cmd/auth/status/status.go @@ -187,9 +187,12 @@ func statusRun(opts *StatusOptions) error { stdout := opts.IO.Out cs := opts.IO.ColorScheme() - if opts.ShowToken && opts.Exporter != nil { - fmt.Fprintf(stderr, "`--json` and `--show-token` cannot be used together. To include the token in the JSON output, use `--json token`.") - return nil + if opts.Exporter != nil { + if opts.ShowToken { + fmt.Fprintf(stderr, "`--json` and `--show-token` cannot be used together. To include the token in the JSON output, use `--json token`.") + return nil + } + opts.ShowToken = true } statuses := make(map[string]Entries) diff --git a/pkg/cmd/auth/status/status_test.go b/pkg/cmd/auth/status/status_test.go index 567748d82..43d552394 100644 --- a/pkg/cmd/auth/status/status_test.go +++ b/pkg/cmd/auth/status/status_test.go @@ -651,6 +651,17 @@ func Test_statusRun(t *testing.T) { }, wantOut: `{"github.com":[{"active":true,"host":"github.com","login":"monalisa","scopes":"","state":"timeout"}]}` + "\n", }, + { + name: "token is not masked with json flag", + opts: StatusOptions{ + Hostname: "github.com", + Exporter: addFieldsToExporter(defaultJsonExporter(), []string{"token"}), + }, + cfgStubs: func(t *testing.T, c gh.Config) { + login(t, c, "github.com", "monalisa", "abc123", "https") + }, + wantOut: `{"github.com":[{"active":true,"host":"github.com","login":"monalisa","state":"success","token":"abc123"}]}` + "\n", + }, { name: "Both show token and json flags", opts: StatusOptions{