Class: FlexmlsApi::Authentication::OAuth2Impl::GrantTypeCode
- Inherits:
-
GrantTypeBase
- Object
- GrantTypeBase
- FlexmlsApi::Authentication::OAuth2Impl::GrantTypeCode
- Defined in:
- lib/flexmls_api/authentication/oauth2_impl/grant_type_code.rb
Overview
OAuth2 authentication flow using username and password parameters for the user in the request. This implementation is geared towards authentication styles for web applications that have a OAuth flow for redirects.
Constant Summary
Constants inherited from GrantTypeBase
FlexmlsApi::Authentication::OAuth2Impl::GrantTypeBase::GRANT_TYPES
Instance Attribute Summary
Attributes inherited from GrantTypeBase
Instance Method Summary collapse
- #authenticate ⇒ Object
-
#initialize(client, provider, session) ⇒ GrantTypeCode
constructor
A new instance of GrantTypeCode.
- #refresh ⇒ Object
Methods inherited from GrantTypeBase
Constructor Details
#initialize(client, provider, session) ⇒ GrantTypeCode
Returns a new instance of GrantTypeCode.
9 10 11 |
# File 'lib/flexmls_api/authentication/oauth2_impl/grant_type_code.rb', line 9 def initialize(client, provider, session) super(client, provider, session) end |
Instance Method Details
#authenticate ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/flexmls_api/authentication/oauth2_impl/grant_type_code.rb', line 12 def authenticate if(provider.code.nil?) FlexmlsApi.logger.debug("[oauth2] No authoriztion code present. Redirecting to #{}.") provider.redirect() end if needs_refreshing? new_session = refresh end return new_session unless new_session.nil? create_session(token_params) end |
#refresh ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/flexmls_api/authentication/oauth2_impl/grant_type_code.rb', line 24 def refresh() FlexmlsApi.logger.debug("[oauth2] Refresh oauth session.") refresher = GrantTypeRefresh.new(client,provider,session) refresher.params = {"redirect_uri" => @provider.redirect_uri} refresher.authenticate rescue ClientError => e FlexmlsApi.logger.info("[oauth2] Refreshing token failed, the library will try and authenticate from scratch: #{e.}") nil end |