@@ -379,7 +379,7 @@ func promptForInteractivePassword(parameterName string, defaultValue string) str
379379
380380 // Trim newline and check if password is empty; if so, return default
381381 if len (password ) > 0 {
382- password = password [: len (password ) - 1 ]
382+ password = strings . Trim (password , " \n " )
383383 }
384384 if password == "" {
385385 return defaultValue
@@ -442,51 +442,93 @@ func authInteractive(
442442 }
443443 }
444444 } else if serverConf .AuthType == "oauth" {
445- if serverConf .ClientID == "" || forcePrompt {
446- serverConf .ClientID = promptForInteractiveParameter (
447- "Keyfactor Command OAuth Client ID" ,
448- serverConf .ClientID ,
445+ if serverConf .AccessToken == "" || forcePrompt {
446+ log .Debug ().Msg ("prompting for OAuth access token" )
447+ serverConf .AccessToken = promptForInteractiveParameter (
448+ "Keyfactor Command OAuth Access Token (to use client ID and secret, leave blank)" ,
449+ serverConf .AccessToken ,
449450 )
450451 }
451- if serverConf .ClientSecret == "" || forcePrompt {
452- serverConf .ClientSecret = promptForInteractivePassword (
453- "Keyfactor Command OAuth Client Secret" ,
454- serverConf .ClientSecret ,
455- )
456- }
457- if serverConf .OAuthTokenUrl == "" || forcePrompt {
458- serverConf .OAuthTokenUrl = promptForInteractiveParameter (
459- "Keyfactor Command OAuth Token URL" ,
460- serverConf .OAuthTokenUrl ,
461- )
462- }
463- if len (serverConf .Scopes ) == 0 || forcePrompt {
464- scopesCsv := promptForInteractiveParameter (
465- "OAuth Scopes" ,
466- strings .Join (serverConf .Scopes , "," ),
467- )
468- serverConf .Scopes = strings .Split (scopesCsv , "," )
469- }
470- if serverConf .Audience == "" || forcePrompt {
471- serverConf .Audience = promptForInteractiveParameter (
472- "OAuth Audience" ,
473- serverConf .Audience ,
474- )
452+ if serverConf .AccessToken == "" {
453+ log .Debug ().Msg ("no oauth access token provided" )
454+ if serverConf .ClientID == "" || forcePrompt {
455+ log .Debug ().
456+ Str ("serverConf.ClientID" , serverConf .ClientID ).
457+ Msg ("prompting for OAuth client ID" )
458+ serverConf .ClientID = promptForInteractiveParameter (
459+ "Keyfactor Command OAuth Client ID" ,
460+ serverConf .ClientID ,
461+ )
462+ }
463+ if serverConf .ClientSecret == "" || forcePrompt {
464+ log .Debug ().Msg ("prompting for OAuth client secret" )
465+ serverConf .ClientSecret = promptForInteractivePassword (
466+ "Keyfactor Command OAuth Client Secret" ,
467+ serverConf .ClientSecret ,
468+ )
469+ }
470+
471+ if serverConf .OAuthTokenUrl == "" || forcePrompt {
472+ log .Debug ().
473+ Str ("serverConf.OAuthTokenUrl" , serverConf .OAuthTokenUrl ).
474+ Msg ("prompting for OAuth token URL" )
475+ serverConf .OAuthTokenUrl = promptForInteractiveParameter (
476+ "Keyfactor Command OAuth Token URL" ,
477+ serverConf .OAuthTokenUrl ,
478+ )
479+ }
480+ if len (serverConf .Scopes ) == 0 || forcePrompt {
481+ log .Debug ().
482+ Strs ("serverConf.Scopes" , serverConf .Scopes ).
483+ Msg ("prompting for OAuth scopes" )
484+ scopesCsv := promptForInteractiveParameter (
485+ "OAuth Scopes" ,
486+ strings .Join (serverConf .Scopes , "," ),
487+ )
488+ serverConf .Scopes = strings .Split (scopesCsv , "," )
489+ }
490+ if serverConf .Audience == "" || forcePrompt {
491+ log .Debug ().Msg ("prompting for OAuth audience" )
492+ serverConf .Audience = promptForInteractiveParameter (
493+ "OAuth Audience" ,
494+ serverConf .Audience ,
495+ )
496+ }
497+ } else {
498+ log .Debug ().
499+ Str ("serverConf.AccessToken" , hashSecretValue (serverConf .AccessToken )).
500+ Msg ("using provided OAuth access token" )
475501 }
476502 }
477503
478504 if serverConf .APIPath == "" || forcePrompt {
505+ log .Debug ().
506+ Str ("serverConf.APIPath" , serverConf .APIPath ).
507+ Msg ("prompting for API path" )
479508 serverConf .APIPath = promptForInteractiveParameter ("Keyfactor Command API path" , serverConf .APIPath )
480509 }
481510
482511 if serverConf .CACertPath == "" || forcePrompt {
512+ log .Debug ().
513+ Str ("serverConf.CACertPath" , serverConf .CACertPath ).
514+ Msg ("prompting for CA cert path" )
483515 serverConf .CACertPath = promptForInteractiveParameter ("Keyfactor Command CA Cert Path" , serverConf .CACertPath )
484516 }
517+ if ! serverConf .SkipTLSVerify || forcePrompt {
518+ log .Debug ().
519+ Bool ("serverConf.SkipTLSVerify" , serverConf .SkipTLSVerify ).
520+ Msg ("prompting for Skip TLS Verify" )
521+ serverConf .SkipTLSVerify = promptForInteractiveParameter (
522+ "Keyfactor Command Skip TLS Verify [true,false]" ,
523+ fmt .Sprintf ("%t" , serverConf .SkipTLSVerify ),
524+ ) == "true"
525+ }
485526
486527 if profileName == "" {
487- profileName = "default"
528+ profileName = auth_providers . DefaultConfigProfile
488529 }
489530 if configPath == "" {
531+ log .Debug ().Msg ("configPath is empty, calling prepHomeDir()" )
490532 userHomeDir , hErr := prepHomeDir ()
491533 if hErr != nil {
492534 //log.Println("[ERROR] Unable to create home directory: ", hErr)
@@ -502,13 +544,15 @@ func authInteractive(
502544 confFile .Servers [profileName ] = * serverConf
503545
504546 if saveConfig {
547+ log .Debug ().Bool ("saveConfig" , saveConfig ).Msg ("calling writeConfigFile()" )
505548 saveErr := writeConfigFile (& confFile , configPath )
506549 if saveErr != nil {
507550 //log.Println("[ERROR] Unable to save configuration file to disk: ", saveErr)
508551 log .Error ().Err (saveErr )
509552 return confFile , saveErr
510553 }
511554 }
555+ log .Debug ().Msg ("authInteractive() returning" )
512556 return confFile , nil
513557}
514558
0 commit comments