Class: HammerCLIForeman::Api::Oauth::PasswordGrant
- Inherits:
-
ApipieBindings::Authenticators::TokenAuth
- Object
- ApipieBindings::Authenticators::TokenAuth
- HammerCLIForeman::Api::Oauth::PasswordGrant
- Defined in:
- lib/hammer_cli_foreman/api/oauth/password_grant.rb
Instance Attribute Summary collapse
-
#oidc_client_id ⇒ Object
Returns the value of attribute oidc_client_id.
-
#oidc_token_endpoint ⇒ Object
Returns the value of attribute oidc_token_endpoint.
-
#password ⇒ Object
Returns the value of attribute password.
-
#token ⇒ Object
Returns the value of attribute token.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #authenticate(request, token) ⇒ Object
- #error(ex) ⇒ Object
-
#initialize(oidc_token_endpoint, oidc_client_id, user, password) ⇒ PasswordGrant
constructor
A new instance of PasswordGrant.
- #set_token(input_oidc_token_endpoint, input_oidc_client_id, input_user, input_password) ⇒ Object
- #set_token_interactively ⇒ Object
Constructor Details
#initialize(oidc_token_endpoint, oidc_client_id, user, password) ⇒ PasswordGrant
Returns a new instance of PasswordGrant.
9 10 11 12 13 14 15 |
# File 'lib/hammer_cli_foreman/api/oauth/password_grant.rb', line 9 def initialize(oidc_token_endpoint, oidc_client_id, user, password) @oidc_token_endpoint = oidc_token_endpoint @oidc_client_id = oidc_client_id @user = user @password = password super set_token(oidc_token_endpoint, oidc_client_id, user, password) end |
Instance Attribute Details
#oidc_client_id ⇒ Object
Returns the value of attribute oidc_client_id.
7 8 9 |
# File 'lib/hammer_cli_foreman/api/oauth/password_grant.rb', line 7 def oidc_client_id @oidc_client_id end |
#oidc_token_endpoint ⇒ Object
Returns the value of attribute oidc_token_endpoint.
7 8 9 |
# File 'lib/hammer_cli_foreman/api/oauth/password_grant.rb', line 7 def oidc_token_endpoint @oidc_token_endpoint end |
#password ⇒ Object
Returns the value of attribute password.
7 8 9 |
# File 'lib/hammer_cli_foreman/api/oauth/password_grant.rb', line 7 def password @password end |
#token ⇒ Object
Returns the value of attribute token.
7 8 9 |
# File 'lib/hammer_cli_foreman/api/oauth/password_grant.rb', line 7 def token @token end |
#user ⇒ Object
Returns the value of attribute user.
7 8 9 |
# File 'lib/hammer_cli_foreman/api/oauth/password_grant.rb', line 7 def user @user end |
Instance Method Details
#authenticate(request, token) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/hammer_cli_foreman/api/oauth/password_grant.rb', line 17 def authenticate(request, token) if HammerCLI.interactive? set_token_interactively end super end |
#error(ex) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/hammer_cli_foreman/api/oauth/password_grant.rb', line 41 def error(ex) if ex.is_a?(RestClient::InternalServerError) @user = @password = @oidc_token_endpoint = @oidc_client_id = nil = _("Invalid credentials or oidc-client-id or oidc-token-endpoint.\n") begin = JSON.parse(ex.response.body)['error']['message'] rescue end UnauthorizedError.new( << ) end end |
#set_token(input_oidc_token_endpoint, input_oidc_client_id, input_user, input_password) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/hammer_cli_foreman/api/oauth/password_grant.rb', line 28 def set_token(input_oidc_token_endpoint, input_oidc_client_id, input_user, input_password) @oidc_token_endpoint = input_oidc_token_endpoint if input_oidc_token_endpoint @user = input_user @password = input_password @oidc_client_id = input_oidc_client_id if input_oidc_client_id if @user.to_s.empty? || @password.to_s.empty? || @oidc_token_endpoint.to_s.empty? || @oidc_client_id.to_s.empty? @token = nil else @token = HammerCLIForeman::OpenidConnect.new( @oidc_token_endpoint, @oidc_client_id).get_token(@user, @password) end end |
#set_token_interactively ⇒ Object
24 25 26 |
# File 'lib/hammer_cli_foreman/api/oauth/password_grant.rb', line 24 def set_token_interactively @token ||= set_token(get_oidc_token_endpoint, get_oidc_client_id, get_user, get_password) end |