@@ -51,6 +51,8 @@ type UserAuthConfig struct {
5151 IsReauthentication bool
5252 // Port defines which port should be used for the UserAuthFlow callback
5353 Port * int
54+ // NoBrowserOpen stops the browser from opening automatically during the login flow
55+ NoBrowserOpen bool
5456}
5557
5658type apiClient interface {
@@ -250,19 +252,28 @@ func AuthorizeUser(p *print.Printer, authConfig UserAuthConfig) error {
250252 }
251253 })
252254
253- p .Debug (print .DebugLevel , "opening browser for authentication: %s" , authorizationURL )
254255 p .Debug (print .DebugLevel , "using authentication server on %s" , idpWellKnownConfig .Issuer )
255256 p .Debug (print .DebugLevel , "using client ID %s for authentication " , idpClientID )
256257
257- // Open a browser window to the authorizationURL
258- err = openBrowser (authorizationURL )
259- if err != nil {
260- return fmt .Errorf ("open browser to URL %s: %w" , authorizationURL , err )
261- }
258+ if authConfig .NoBrowserOpen {
259+ p .Debug (print .DebugLevel , "skipping browser opening since the commandline flag was passed" )
262260
263- // Print the link
264- p .Info ("Your browser has been opened to visit:\n \n " )
265- p .Info ("%s\n \n " , authorizationURL )
261+ // Print the link in terminal
262+ p .Noticeln ("Open the following URL in your browser:\n " )
263+ p .Outputf ("%s\n \n " , authorizationURL )
264+ } else {
265+ p .Debug (print .DebugLevel , "opening browser for authentication: %s" , authorizationURL )
266+
267+ // Open a browser window to the authorizationURL
268+ err = openBrowser (authorizationURL )
269+ if err != nil {
270+ return fmt .Errorf ("open browser to URL %s: %w" , authorizationURL , err )
271+ }
272+
273+ // Print the link
274+ p .Info ("Your browser has been opened to visit:\n \n " )
275+ p .Info ("%s\n \n " , authorizationURL )
276+ }
266277
267278 // Start the blocking web server loop
268279 // It will exit when the handlers get fired and call server.Close()
0 commit comments