Sha256: 41e801b2547a2e3a001e8690b446e2388ee4ddb678c72b1a91750d1911359712

Contents?: true

Size: 1.9 KB

Versions: 5

Compression:

Stored size: 1.9 KB

Contents

if defined? ActionDispatch
  require 'oauth/request_proxy/rack_request'
  require 'oauth/request_proxy/action_dispatch_request'
  require 'action_dispatch/testing/test_process'
else
  require 'oauth/request_proxy/action_controller_request'
  require 'action_controller/test_process'
end

module ActionController
  class Base
    if defined? ActionDispatch
      def process_with_new_base_test(request, response=nil)
        request.apply_oauth! if request.respond_to?(:apply_oauth!)
        super(request, response)
      end
    else
      def process_with_oauth(request, response=nil)
        request.apply_oauth! if request.respond_to?(:apply_oauth!)
        process_without_oauth(request, response)
      end
      alias_method_chain :process, :oauth
    end
  end

  class TestRequest
    def self.use_oauth=(bool)
      @use_oauth = bool
    end

    def self.use_oauth?
      @use_oauth
    end

    def configure_oauth(consumer = nil, token = nil, options = {})
      @oauth_options = { :consumer  => consumer,
                         :token     => token,
                         :scheme    => 'header',
                         :signature_method => nil,
                         :nonce     => nil,
                         :timestamp => nil }.merge(options)
    end

    def apply_oauth!
      return unless ActionController::TestRequest.use_oauth? && @oauth_options

      @oauth_helper = OAuth::Client::Helper.new(self, @oauth_options.merge(:request_uri => (respond_to?(:fullpath) ? fullpath : request_uri)))
      @oauth_helper.amend_user_agent_header(env)

      self.send("set_oauth_#{@oauth_options[:scheme]}")
    end

    def set_oauth_header
      env['Authorization'] = @oauth_helper.header
    end

    def set_oauth_parameters
      @query_parameters = @oauth_helper.parameters_with_oauth
      @query_parameters.merge!(:oauth_signature => @oauth_helper.signature)
    end

    def set_oauth_query_string
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/oauth-0.5.6/lib/oauth/client/action_controller_request.rb
oauth-0.5.6 lib/oauth/client/action_controller_request.rb
oauth-0.5.5 lib/oauth/client/action_controller_request.rb
tdiary-5.0.8 vendor/bundle/gems/oauth-0.5.4/lib/oauth/client/action_controller_request.rb
oauth-0.5.4 lib/oauth/client/action_controller_request.rb