@@ -196,13 +196,6 @@ func (lf *loginFlags) Bind(local *pflag.FlagSet, global *internal.GlobalCommandO
196196 lf .global = global
197197}
198198
199- func newLoginFlags (cmd * cobra.Command , global * internal.GlobalCommandOptions ) * loginFlags {
200- flags := & loginFlags {}
201- flags .Bind (cmd .Flags (), global )
202-
203- return flags
204- }
205-
206199func newLoginCmd (parent string ) * cobra.Command {
207200 return & cobra.Command {
208201 Use : "login" ,
@@ -237,9 +230,6 @@ type loginAction struct {
237230 commandRunner exec.CommandRunner
238231}
239232
240- // it is important to update both newAuthLoginAction and newLoginAction at the same time
241- // newAuthLoginAction is the action that is bound to `azd auth login`,
242- // and newLoginAction is the action that is bound to `azd login`
243233func newAuthLoginAction (
244234 formatter output.Formatter ,
245235 writer io.Writer ,
@@ -262,32 +252,36 @@ func newAuthLoginAction(
262252 }
263253}
264254
265- // it is important to update both newAuthLoginAction and newLoginAction at the same time
266- // newAuthLoginAction is the action that is bound to `azd auth login`,
267- // and newLoginAction is the action that is bound to `azd login`
268- func newLoginAction (
269- formatter output.Formatter ,
270- writer io.Writer ,
271- authManager * auth.Manager ,
272- accountSubManager * account.SubscriptionsManager ,
273- flags * loginFlags ,
274- console input.Console ,
275- annotations CmdAnnotations ,
276- commandRunner exec.CommandRunner ,
277- ) actions.Action {
278- return & loginAction {
279- formatter : formatter ,
280- writer : writer ,
281- console : console ,
282- authManager : authManager ,
283- accountSubManager : accountSubManager ,
284- flags : flags ,
285- annotations : annotations ,
286- commandRunner : commandRunner ,
255+ func (la * loginAction ) Run (ctx context.Context ) (* actions.ActionResult , error ) {
256+ loginMode , err := la .authManager .Mode ()
257+ if err != nil {
258+ return nil , err
259+ }
260+ if loginMode != auth .AzdBuiltIn && ! la .flags .onlyCheckStatus {
261+ la .console .MessageUxItem (ctx , & ux.WarningAltMessage {
262+ Message : fmt .Sprintf (
263+ "azd is not using the built-in authentication mode, but rather '%s'" , loginMode ),
264+ })
265+ la .console .Message (ctx , "If you want to use 'azd auth login', you need to disable the current auth mode." )
266+ response , err := la .console .Confirm (ctx , input.ConsoleOptions {
267+ Message : "Do you want to switch back to azd built-in authentication?" ,
268+ DefaultValue : false ,
269+ Help : "azd supports multiple authentication modes, including " + string (auth .AzDelegated ) + " and " +
270+ string (auth .ExternalRequest ) + " for Auth." +
271+ " Switching back to azd built-in authentication will try to disable the current mode." ,
272+ })
273+ if err != nil {
274+ return nil , err
275+ }
276+ if ! response {
277+ return nil , fmt .Errorf ("log in is not supported on current mode: %s" , loginMode )
278+ }
279+ if err := la .authManager .SetBuiltInAuthMode (); err != nil {
280+ return nil , fmt .Errorf ("setting auth mode: %w" , err )
281+ }
282+ la .console .Message (ctx , "Authentication mode set to azd built-in. Continuing login..." )
287283 }
288- }
289284
290- func (la * loginAction ) Run (ctx context.Context ) (* actions.ActionResult , error ) {
291285 if len (la .flags .scopes ) == 0 {
292286 la .flags .scopes = la .authManager .LoginScopes ()
293287 }
0 commit comments