Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions cli/azd/cmd/auth_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,32 @@ func newLoginAction(
}

func (la *loginAction) Run(ctx context.Context) (*actions.ActionResult, error) {
loginMode, err := la.authManager.Mode()
if err != nil {
return nil, err
}
if loginMode != auth.AzdBuiltIn {
la.console.MessageUxItem(ctx, &ux.WarningAltMessage{
Message: fmt.Sprintf(
"Azd is not using the built-in authentication mode, but rather '%s'", loginMode),
})
la.console.Message(ctx, "If you want to use 'azd auth login', you need to disable the current auth mode.")
Comment on lines +296 to +300
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This removes the use for azd auth login --check-status to verify azd is logged in using az.

response, err := la.console.Confirm(ctx, input.ConsoleOptions{
Message: "Do you want to switch back to azd built-in authentication?",
DefaultValue: "N",
Help: "",
})
if err != nil {
return nil, err
}
if !response {
return nil, fmt.Errorf("log in is not supported on current mode: %s", loginMode)
}
if err := la.authManager.SetMode(ctx, auth.AzdBuiltIn); err != nil {
return nil, fmt.Errorf("setting auth mode: %w", err)
}
}

if len(la.flags.scopes) == 0 {
la.flags.scopes = la.authManager.LoginScopes()
}
Expand Down
43 changes: 43 additions & 0 deletions cli/azd/pkg/auth/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1409,3 +1409,46 @@ func (m *Manager) LogInDetails(ctx context.Context) (*LogInDetails, error) {

return nil, ErrNoCurrentUser
}

type AuthMode string

const (
AzdBuiltIn AuthMode = "azd built in"
AzDelegated AuthMode = "delegated to az cli"
ExternalRequest AuthMode = "external token request"
)

func (m *Manager) Mode() (AuthMode, error) {
// Check external
if m.UseExternalAuth() {
return ExternalRequest, nil
}

// check az delegation
cfg, err := m.userConfigManager.Load()
if err != nil {
return "", fmt.Errorf("fetching current user: %w", err)
}

if shouldUseLegacyAuth(cfg) {
return AzDelegated, nil
}

// default to azd
return AzdBuiltIn, nil
}

func (m *Manager) SetMode(mode AuthMode) error {
currentMode, err := m.Mode()
if err != nil {
return fmt.Errorf("fetching current auth mode: %w", err)
}

if currentMode == mode {
return nil
}

if currentMode == ExternalRequest {

}
}
Loading