Class OAuth::RequestProxy::Base
In: lib/oauth/request_proxy/base.rb
Parent: Object

Methods

Included Modules

OAuth::Helper

Attributes

options  [RW] 
request  [RW] 

Public Class methods

[Source]

# File lib/oauth/request_proxy/base.rb, line 14
    def initialize(request, options = {})
      @request = request
      @options = options
    end

[Source]

# File lib/oauth/request_proxy/base.rb, line 8
    def self.proxies(klass)
      OAuth::RequestProxy.available_proxies[klass] = self
    end

Public Instance methods

consumer_key()

Alias for oauth_consumer_key

[Source]

# File lib/oauth/request_proxy/base.rb, line 85
    def non_oauth_parameters
      parameters.reject { |k,v| OAuth::PARAMETERS.include?(k) }
    end
nonce()

Alias for oauth_nonce

See 9.1.1. in specs Normalize Request Parameters

[Source]

# File lib/oauth/request_proxy/base.rb, line 96
    def normalized_parameters
      normalize(parameters_for_signature)
    end

See 9.1.2 in specs

[Source]

# File lib/oauth/request_proxy/base.rb, line 90
    def normalized_uri
      u = URI.parse(uri)
      "#{u.scheme.downcase}://#{u.host.downcase}#{(u.scheme.downcase == 'http' && u.port != 80) || (u.scheme.downcase == 'https' && u.port != 443) ? ":#{u.port}" : ""}#{(u.path && u.path != '') ? u.path : '/'}"
    end

OAuth parameters

[Source]

# File lib/oauth/request_proxy/base.rb, line 21
    def oauth_callback
      parameters['oauth_callback']
    end

[Source]

# File lib/oauth/request_proxy/base.rb, line 25
    def oauth_consumer_key
      parameters['oauth_consumer_key']
    end

Authorization header for OAuth

[Source]

# File lib/oauth/request_proxy/base.rb, line 137
    def oauth_header(options = {})
      header_params_str = oauth_parameters.map { |k,v| "#{k}=\"#{escape(v)}\"" }.join(', ')

      realm = "realm=\"#{options[:realm]}\", " if options[:realm]
      "OAuth #{realm}#{header_params_str}"
    end

[Source]

# File lib/oauth/request_proxy/base.rb, line 29
    def oauth_nonce
      parameters['oauth_nonce']
    end

[Source]

# File lib/oauth/request_proxy/base.rb, line 81
    def oauth_parameters
      parameters.select { |k,v| OAuth::PARAMETERS.include?(k) }.reject { |k,v| v == "" }
    end

[Source]

# File lib/oauth/request_proxy/base.rb, line 33
    def oauth_signature
      # TODO can this be nil?
      parameters['oauth_signature'] || ""
    end

[Source]

# File lib/oauth/request_proxy/base.rb, line 38
    def oauth_signature_method
      case parameters['oauth_signature_method']
      when Array
        parameters['oauth_signature_method'].first
      else
        parameters['oauth_signature_method']
      end
    end

[Source]

# File lib/oauth/request_proxy/base.rb, line 47
    def oauth_timestamp
      parameters['oauth_timestamp']
    end

[Source]

# File lib/oauth/request_proxy/base.rb, line 51
    def oauth_token
      parameters['oauth_token']
    end

[Source]

# File lib/oauth/request_proxy/base.rb, line 55
    def oauth_verifier
      parameters['oauth_verifier']
    end

[Source]

# File lib/oauth/request_proxy/base.rb, line 59
    def oauth_version
      parameters["oauth_version"]
    end

Parameter accessors

[Source]

# File lib/oauth/request_proxy/base.rb, line 73
    def parameters
      raise NotImplementedError, "Must be implemented by subclasses"
    end

[Source]

# File lib/oauth/request_proxy/base.rb, line 77
    def parameters_for_signature
      parameters.reject { |k,v| k == "oauth_signature" }
    end

[Source]

# File lib/oauth/request_proxy/base.rb, line 100
    def sign(options = {})
      OAuth::Signature.sign(self, options)
    end

[Source]

# File lib/oauth/request_proxy/base.rb, line 104
    def sign!(options = {})
      parameters["oauth_signature"] = sign(options)
      @signed = true
      signature
    end
signature()

Alias for oauth_signature

See 9.1 in specs

[Source]

# File lib/oauth/request_proxy/base.rb, line 111
    def signature_base_string
      base = [method, normalized_uri, normalized_parameters]
      base.map { |v| escape(v) }.join("&")
    end
signature_method()

Has this request been signed yet?

[Source]

# File lib/oauth/request_proxy/base.rb, line 117
    def signed?
      @signed
    end

URI, including OAuth parameters

[Source]

# File lib/oauth/request_proxy/base.rb, line 122
    def signed_uri(with_oauth = true)
      if signed?
        if with_oauth
          params = parameters
        else
          params = non_oauth_parameters
        end

        [uri, normalize(params)] * "?"
      else
        STDERR.puts "This request has not yet been signed!"
      end
    end
timestamp()

Alias for oauth_timestamp

token()

Alias for oauth_token

Protected Instance methods

[Source]

# File lib/oauth/request_proxy/base.rb, line 146
    def header_params
      %w( X-HTTP_AUTHORIZATION Authorization HTTP_AUTHORIZATION ).each do |header|
        next unless request.env.include?(header)

        header = request.env[header]
        next unless header[0,6] == 'OAuth '

        # parse the header into a Hash
        oauth_params = OAuth::Helper.parse_header(header)

        # remove non-OAuth parameters
        oauth_params.reject! { |k,v| k !~ /^oauth_/ }

        return oauth_params
      end

      return {}
    end

[Validate]