@@ -27,13 +27,11 @@ type iconfig interface {
2727 Write () error
2828}
2929
30- func AuthFlowWithConfig (cfg iconfig , IO * iostreams.IOStreams , hostname , notice string , additionalScopes []string ) (string , error ) {
30+ func AuthFlowWithConfig (cfg iconfig , IO * iostreams.IOStreams , hostname , notice string , additionalScopes []string , isInteractive bool ) (string , error ) {
3131 // TODO this probably shouldn't live in this package. It should probably be in a new package that
3232 // depends on both iostreams and config.
33- stderr := IO .ErrOut
34- cs := IO .ColorScheme ()
3533
36- token , userLogin , err := authFlow (hostname , IO , notice , additionalScopes )
34+ token , userLogin , err := authFlow (hostname , IO , notice , additionalScopes , isInteractive )
3735 if err != nil {
3836 return "" , err
3937 }
@@ -47,19 +45,10 @@ func AuthFlowWithConfig(cfg iconfig, IO *iostreams.IOStreams, hostname, notice s
4745 return "" , err
4846 }
4947
50- err = cfg .Write ()
51- if err != nil {
52- return "" , err
53- }
54-
55- fmt .Fprintf (stderr , "%s Authentication complete. %s to continue...\n " ,
56- cs .SuccessIcon (), cs .Bold ("Press Enter" ))
57- _ = waitForEnter (IO .In )
58-
59- return token , nil
48+ return token , cfg .Write ()
6049}
6150
62- func authFlow (oauthHost string , IO * iostreams.IOStreams , notice string , additionalScopes []string ) (string , string , error ) {
51+ func authFlow (oauthHost string , IO * iostreams.IOStreams , notice string , additionalScopes []string , isInteractive bool ) (string , string , error ) {
6352 w := IO .ErrOut
6453 cs := IO .ColorScheme ()
6554
@@ -90,7 +79,12 @@ func authFlow(oauthHost string, IO *iostreams.IOStreams, notice string, addition
9079 return nil
9180 },
9281 BrowseURL : func (url string ) error {
93- fmt .Fprintf (w , "- %s to open %s in your browser... " , cs .Bold ("Press Enter" ), oauthHost )
82+ if ! isInteractive {
83+ fmt .Fprintf (w , "%s to continue in your web browser: %s\n " , cs .Bold ("Open this URL" ), url )
84+ return nil
85+ }
86+
87+ fmt .Fprintf (w , "%s to open %s in your browser... " , cs .Bold ("Press Enter" ), oauthHost )
9488 _ = waitForEnter (IO .In )
9589
9690 // FIXME: read the browser from cmd Factory rather than recreating it
@@ -103,7 +97,7 @@ func authFlow(oauthHost string, IO *iostreams.IOStreams, notice string, addition
10397 return nil
10498 },
10599 WriteSuccessHTML : func (w io.Writer ) {
106- fmt .Fprintln (w , oauthSuccessPage )
100+ fmt .Fprint (w , oauthSuccessPage )
107101 },
108102 HTTPClient : httpClient ,
109103 Stdin : IO .In ,
0 commit comments