Sha256: d6db711e1630a4984a80452f1217a90256f503eac6a1b1731e4f93455d7f500e

Contents?: true

Size: 1.3 KB

Versions: 5

Compression:

Stored size: 1.3 KB

Contents

module SparkApi
  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
          SparkApi.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

5 entries across 5 versions & 1 rubygems

Version Path
spark_api-1.1.0 lib/spark_api/authentication/oauth2_impl/grant_type_password.rb
spark_api-1.0.4 lib/spark_api/authentication/oauth2_impl/grant_type_password.rb
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