Sha256: e2e0c2f161f20d50221934da176ae1af6b13dad19fe9dc2aabdc7b7584672f30

Contents?: true

Size: 1.3 KB

Versions: 4

Compression:

Stored size: 1.3 KB

Contents

module FlexmlsApi
  module Authentication
    module OAuth2Impl
      # 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
      class GrantTypePassword < GrantTypeBase
        def initialize(client, provider, session)
          super(client, provider, session)
        end
        def authenticate
          new_session = nil
          if needs_refreshing?
            new_session = refresh
          end
          return new_session unless new_session.nil?
          create_session(token_params)
        end
        
        def refresh()
          GrantTypeRefresh.new(client,provider,session).authenticate
        rescue ClientError => e
          FlexmlsApi.logger.info("Refreshing token failed, the library will try and authenticate from scratch: #{e.message}")
          nil
        end

        private 
        def token_params
          params = {
            "client_id" => @provider.client_id,
            "client_secret" => @provider.client_secret,
            "grant_type" => "password",
            "username" => @provider.username,
            "password" => @provider.password,
          }.to_json 
        end
      end
    end
  end
end



 

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
flexmls_api-0.7.3 lib/flexmls_api/authentication/oauth2_impl/grant_type_password.rb
flexmls_api-0.7.0 lib/flexmls_api/authentication/oauth2_impl/grant_type_password.rb
flexmls_api-0.6.5 lib/flexmls_api/authentication/oauth2_impl/grant_type_password.rb
flexmls_api-0.6.4 lib/flexmls_api/authentication/oauth2_impl/grant_type_password.rb