Skip to content

Commit 404f381

Browse files
authored
Print debug info to stderr (#77)
1 parent 0af68f7 commit 404f381

File tree

7 files changed

+21
-14
lines changed

7 files changed

+21
-14
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ The available flags are:
9494
--idp-hint string identity provider hint
9595
--insecure allow insecure connections
9696
--login-hint string user identifier hint
97+
--no-prompt disable prompt
9798
--par enable pushed authorization requests (PAR)
9899
--password string resource owner password credentials grant flow password
99100
--pkce enable proof key for code exchange (PKCE)

cmd/log.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"crypto/x509"
88
"encoding/json"
99
"encoding/pem"
10+
"os"
1011
"strconv"
1112
"strings"
1213

@@ -19,6 +20,10 @@ import (
1920
"github.com/tidwall/pretty"
2021
)
2122

23+
func init() {
24+
pterm.SetDefaultOutput(os.Stderr)
25+
}
26+
2227
func Logln() {
2328
if silent {
2429
return
@@ -59,6 +64,7 @@ func LogAction(msg string) func(string) {
5964
done, _ := pterm.DefaultSpinner.Start(msg)
6065
return func(s string) {
6166
done.Success(s)
67+
pterm.Println()
6268
}
6369
}
6470

cmd/oauth2.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import (
1919
)
2020

2121
var (
22-
silent bool
22+
silent bool
23+
noPrompt bool
2324
)
2425

2526
type OAuth2Cmd struct {
@@ -75,6 +76,7 @@ func NewOAuth2Cmd() (cmd *OAuth2Cmd) {
7576
cmd.PersistentFlags().DurationVar(&cconfig.BrowserTimeout, "browser-timeout", 10*time.Minute, "browser timeout")
7677
cmd.PersistentFlags().BoolVar(&cconfig.Insecure, "insecure", false, "allow insecure connections")
7778
cmd.PersistentFlags().BoolVarP(&silent, "silent", "s", false, "silent mode")
79+
cmd.PersistentFlags().BoolVar(&noPrompt, "no-prompt", false, "disable prompt")
7880
cmd.PersistentFlags().BoolVar(&cconfig.DPoP, "dpop", false, "use DPoP")
7981
cmd.PersistentFlags().StringVar(&cconfig.Claims, "claims", "", "use claims")
8082
cmd.PersistentFlags().StringVar(&cconfig.RAR, "rar", "", "use rich authorization request (RAR)")
@@ -108,6 +110,8 @@ func (c *OAuth2Cmd) Run(cconfig *oauth2.ClientConfig) func(cmd *cobra.Command, a
108110

109111
if silent {
110112
browser.Stdout = io.Discard
113+
} else {
114+
browser.Stdout = os.Stderr
111115
}
112116

113117
tr := &http.Transport{
@@ -169,7 +173,7 @@ func (c *OAuth2Cmd) Authorize(clientConfig oauth2.ClientConfig, hc *http.Client)
169173
return err
170174
}
171175

172-
if !silent {
176+
if !silent && !noPrompt {
173177
clientConfig = PromptForClientConfig(clientConfig, serverConfig)
174178
}
175179

@@ -198,10 +202,6 @@ func (c *OAuth2Cmd) Authorize(clientConfig oauth2.ClientConfig, hc *http.Client)
198202
}
199203

200204
func (c *OAuth2Cmd) PrintResult(result interface{}) {
201-
if !silent {
202-
return
203-
}
204-
205205
output, err := json.Marshal(result)
206206

207207
if err != nil {

cmd/oauth2_authorize_code.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ func (c *OAuth2Cmd) AuthorizationCodeGrantFlow(clientConfig oauth2.ClientConfig,
9898
LogRequestAndResponse(tokenRequest, tokenResponse)
9999
LogTokenPayloadln(tokenResponse)
100100

101-
c.PrintResult(tokenResponse)
102-
103101
exchangeStatus("Exchanged authorization code for access token")
104102

103+
c.PrintResult(tokenResponse)
104+
105105
return nil
106106
}

cmd/oauth2_device.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ func (c *OAuth2Cmd) DeviceGrantFlow(clientConfig oauth2.ClientConfig, serverConf
9292
LogRequestAndResponse(tokenRequest, tokenResponse)
9393
LogTokenPayloadln(tokenResponse)
9494

95-
c.PrintResult(tokenResponse)
96-
9795
tokenStatus("Obtained token")
9896

97+
c.PrintResult(tokenResponse)
98+
9999
return nil
100100
}

cmd/oauth2_implicit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ func (c *OAuth2Cmd) ImplicitGrantFlow(clientConfig oauth2.ClientConfig, serverCo
4747
LogTokenPayloadln(tokenResponse)
4848
Logln()
4949

50-
c.PrintResult(tokenResponse)
51-
5250
callbackStatus("Obtained authorization")
5351

52+
c.PrintResult(tokenResponse)
53+
5454
return nil
5555
}

cmd/oauth2_token.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ func (c *OAuth2Cmd) tokenEndpointFlow(
6666
LogRequestAndResponse(tokenRequest, tokenResponse)
6767
LogTokenPayloadln(tokenResponse)
6868

69-
c.PrintResult(tokenResponse)
70-
7169
authorizationStatus("Authorization completed")
7270

71+
c.PrintResult(tokenResponse)
72+
7373
return nil
7474
}

0 commit comments

Comments
 (0)