Sha256: 59bdc27b363c4cf1570658b29de1c8e34befb14279b8fc7ddf0310c896feb5c4

Contents?: true

Size: 1.31 KB

Versions: 4

Compression:

Stored size: 1.31 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("[oauth2] 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 & 2 rubygems

Version Path
spark_api-1.0.2 lib/spark_api/authentication/oauth2_impl/grant_type_password.rb~
spark_api-1.0.1 lib/spark_api/authentication/oauth2_impl/grant_type_password.rb~
spark_api-1.0.0 lib/spark_api/authentication/oauth2_impl/grant_type_password.rb~
flexmls_api-0.7.5 lib/flexmls_api/authentication/oauth2_impl/grant_type_password.rb