Sha256: 217e6135673294276c648750580f08f707fb26293a9d204b5a1d78091720891e

Contents?: true

Size: 1016 Bytes

Versions: 5

Compression:

Stored size: 1016 Bytes

Contents

module SparkApi
  module Authentication
    # OAuth2 authentication flow to refresh an access token
    module OAuth2Impl
      class GrantTypeRefresh < GrantTypeBase
        attr_accessor :params
        def initialize(client, provider, session)
          super(client, provider, session)
          @params = {}
        end
        
        def authenticate
          new_session = nil
          unless @session.refresh_token.nil?
            SparkApi.logger.debug("[oauth2] Refreshing authentication to #{provider.access_uri} using [#{session.refresh_token}]")
            new_session = create_session(token_params)
          end
          new_session 
        end
        
        private 
        def token_params
          @params.merge({
            "client_id" => @provider.client_id,
            "client_secret" => @provider.client_secret,
            "grant_type" => "refresh_token",
            "refresh_token"=> session.refresh_token,
          }).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_refresh.rb
spark_api-1.0.4 lib/spark_api/authentication/oauth2_impl/grant_type_refresh.rb
spark_api-1.0.2 lib/spark_api/authentication/oauth2_impl/grant_type_refresh.rb
spark_api-1.0.1 lib/spark_api/authentication/oauth2_impl/grant_type_refresh.rb
spark_api-1.0.0 lib/spark_api/authentication/oauth2_impl/grant_type_refresh.rb