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



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/hammer_cli_foreman/auth.rb', line 45

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