11//
2- // Copyright 2023 The Chainloop Authors.
2+ // Copyright 2024 The Chainloop Authors.
33//
44// Licensed under the Apache License, Version 2.0 (the "License");
55// you may not use this file except in compliance with the License.
@@ -41,18 +41,20 @@ type app struct {
4141}
4242
4343func newAuthLoginCmd () * cobra.Command {
44+ var forceHeadlessLogin bool
4445 cmd := & cobra.Command {
4546 Use : "login" ,
4647 Short : "authenticate the CLI with the Control Plane" ,
4748 RunE : func (cmd * cobra.Command , args []string ) error {
48- return interactiveAuth ()
49+ return interactiveAuth (forceHeadlessLogin )
4950 },
5051 }
5152
53+ cmd .Flags ().BoolVar (& forceHeadlessLogin , "skip-browser" , false , "perform a headless login process without opening a browser" )
5254 return cmd
5355}
5456
55- func interactiveAuth () error {
57+ func interactiveAuth (forceHeadless bool ) error {
5658 var a app
5759
5860 listener , callbackURL , err := localListenerAndCallbackURL ()
@@ -75,6 +77,10 @@ func interactiveAuth() error {
7577 q .Set (oauth .QueryParamLongLived , "true" )
7678 serverLoginURL .RawQuery = q .Encode ()
7779
80+ if forceHeadless {
81+ return headlessAuth (serverLoginURL )
82+ }
83+
7884 err = openbrowser (serverLoginURL .String ())
7985 if err != nil {
8086 logger .Debug ().Err (err ).Msg ("falling back to manual login" )
0 commit comments