Skip to content

Commit

Permalink
fix: clear existing token when using BASIC loginType (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
reubenmiller authored Mar 20, 2023
1 parent b5c2afd commit d3d2984
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pkg/cmd/sessions/set/set.manual.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func NewCmdSet(f *cmdutil.Factory) *CmdSet {
cmd.Flags().StringVar(&ccmd.sessionFilter, "sessionFilter", "", "Filter to be applied to the list of sessions even before the values can be selected")
cmd.Flags().StringVar(&ccmd.TFACode, "tfaCode", "", "Two Factor Authentication code")
cmd.Flags().StringVar(&ccmd.Shell, "shell", defaultShell, "Shell type to return the environment variables")
cmd.Flags().StringVar(&ccmd.LoginType, "loginType", "", "Login type preference, e.g. OAUTH2_INTERNAL or BASIC")
cmd.Flags().StringVar(&ccmd.LoginType, "loginType", "", "Login type preference, e.g. OAUTH2_INTERNAL or BASIC. When set to BASIC, any existing token will be cleared")
cmd.Flags().BoolVar(&ccmd.ClearToken, "clear", false, "Clear any existing tokens")

completion.WithOptions(
Expand Down Expand Up @@ -126,6 +126,16 @@ func (n *CmdSet) RunE(cmd *cobra.Command, args []string) error {
}
}

// Clear existing token when using basic auth
if n.LoginType == c8y.AuthMethodBasic {
cfg.Logger.Infof("Clearing any existing token when using %s auth", c8y.AuthMethodBasic)
os.Unsetenv("C8Y_TOKEN")
if cfg.MustGetToken() != "" {
cfg.SetToken("")
n.onSave(nil)
}
}

cfg.SetSessionFile(sessionFile)
_, err = cfg.ReadConfigFiles(nil)
if err != nil {
Expand Down

0 comments on commit d3d2984

Please sign in to comment.