MCPcopy
hub / github.com/cloudfoundry/cli / authenticate

Method authenticate

cf/commands/login.go:214–288  ·  view source on GitHub ↗
(c flags.FlagContext)

Source from the content-addressed store, hash-verified

212}
213
214func (cmd Login) authenticate(c flags.FlagContext) error {
215 if cmd.config.UAAGrantType() == "client_credentials" {
216 return errors.New(T("Service account currently logged in. Use 'cf logout' to log out service account and try again."))
217 }
218
219 usernameFlagValue := c.String("u")
220 passwordFlagValue := c.String("p")
221
222 prompts, err := cmd.authenticator.GetLoginPromptsAndSaveUAAServerURL()
223 if err != nil {
224 return err
225 }
226 passwordKeys := []string{}
227 credentials := make(map[string]string)
228
229 if value, ok := prompts["username"]; ok {
230 if prompts["username"].Type == coreconfig.AuthPromptTypeText && usernameFlagValue != "" {
231 credentials["username"] = usernameFlagValue
232 } else {
233 credentials["username"] = cmd.ui.Ask(T(value.DisplayName))
234 }
235 }
236
237 for key, prompt := range prompts {
238 if prompt.Type == coreconfig.AuthPromptTypePassword {
239 if key == "passcode" || key == "password" {
240 continue
241 }
242
243 passwordKeys = append(passwordKeys, key)
244 } else if key == "username" {
245 continue
246 } else {
247 credentials[key] = cmd.ui.Ask(T(prompt.DisplayName))
248 }
249 }
250
251 for i := 0; i < maxLoginTries; i++ {
252
253 // ensure that password gets prompted before other codes (eg. mfa code)
254 if passPrompt, ok := prompts["password"]; ok {
255 if passwordFlagValue != "" {
256 credentials["password"] = passwordFlagValue
257 passwordFlagValue = ""
258 } else {
259 credentials["password"] = cmd.ui.AskForPassword(T(passPrompt.DisplayName))
260 }
261 }
262
263 for _, key := range passwordKeys {
264 credentials[key] = cmd.ui.AskForPassword(T(prompts[key].DisplayName))
265 }
266
267 credentialsCopy := make(map[string]string, len(credentials))
268 for k, v := range credentials {
269 credentialsCopy[k] = v
270 }
271

Callers 1

ExecuteMethod · 0.95

Calls 9

UAAGrantTypeMethod · 0.65
StringMethod · 0.65
AskMethod · 0.65
AskForPasswordMethod · 0.65
SayMethod · 0.65
AuthenticateMethod · 0.65
OkMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected