Class: HammerCLIForeman::Auth::LoginCommand::Oauth

Inherits:
HammerCLI::AbstractCommand
  • Object
show all
Extended by:
HammerCLIForeman::Authenticate::Login
Defined in:
lib/hammer_cli_foreman/auth.rb

Instance Method Summary collapse

Methods included from HammerCLIForeman::Authenticate::Login

execute_with_params

Instance Method Details

#executeObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/hammer_cli_foreman/auth.rb', line 79

def execute
  if option_two_factor?
    Oauth.execute_with_params(
      AUTH_TYPES[:oauth_authentication_code_grant],
      option_oidc_token_endpoint || HammerCLI::Settings.get(:foreman, :oidc_token_endpoint),
      option_oidc_authorization_endpoint || HammerCLI::Settings.get(:foreman, :oidc_authorization_endpoint),
      option_oidc_client_id || HammerCLI::Settings.get(:foreman, :oidc_client_id),
      option_oidc_redirect_uri || HammerCLI::Settings.get(:foreman, :oidc_redirect_uri)
    )
  else
    Oauth.execute_with_params(
      AUTH_TYPES[:oauth_password_grant],
      option_oidc_token_endpoint || HammerCLI::Settings.get(:foreman, :oidc_token_endpoint),
      option_oidc_client_id || HammerCLI::Settings.get(:foreman, :oidc_client_id),
      option_username || HammerCLI::Settings.get('_params', 'username'),
      option_password || HammerCLI::Settings.get('_params', 'password')
    )
  end
  logged_user = HammerCLIForeman.foreman_api_connection.authenticator.user
  print_message(_("Successfully logged in as '%s'.") % logged_user)
  HammerCLI::EX_OK
end