Class: FlexmlsApi::Authentication::OAuth2Impl::GrantTypePassword

Inherits:
GrantTypeBase
  • Object
show all
Defined in:
lib/flexmls_api/authentication/oauth2_impl/grant_type_password.rb

Overview

OAuth2 authentication flow using username and password parameters for the user in the request. This implementation is geared towards authentication styles for native applications that need to use OAuth2

Constant Summary

Constants inherited from GrantTypeBase

FlexmlsApi::Authentication::OAuth2Impl::GrantTypeBase::GRANT_TYPES

Instance Attribute Summary

Attributes inherited from GrantTypeBase

#client, #provider, #session

Instance Method Summary collapse

Methods inherited from GrantTypeBase

create

Constructor Details

#initialize(client, provider, session) ⇒ GrantTypePassword

Returns a new instance of GrantTypePassword.



9
10
11
# File 'lib/flexmls_api/authentication/oauth2_impl/grant_type_password.rb', line 9

def initialize(client, provider, session)
  super(client, provider, session)
end

Instance Method Details

#authenticateObject



12
13
14
15
16
17
18
19
# File 'lib/flexmls_api/authentication/oauth2_impl/grant_type_password.rb', line 12

def authenticate
  new_session = nil
  if needs_refreshing?
    new_session = refresh
  end
  return new_session unless new_session.nil?
  create_session(token_params)
end

#refreshObject



21
22
23
24
25
26
# File 'lib/flexmls_api/authentication/oauth2_impl/grant_type_password.rb', line 21

def refresh()
  GrantTypeRefresh.new(client,provider,session).authenticate
rescue ClientError => e
  FlexmlsApi.logger.info("[oauth2] Refreshing token failed, the library will try and authenticate from scratch: #{e.message}")
  nil
end