Class: OAuth::RequestProxy::Base

### Home Classes Methods

### In Files

- lib/oauth/request_proxy/base.rb

### Parent

Object

### Methods

- ::new
- ::proxies
- #consumer_key
- #header_params
- #non_oauth_parameters
- #nonce
- #normalized_parameters
- #normalized_uri
- #oauth_callback
- #oauth_consumer_key
- #oauth_header
- #oauth_nonce
- #oauth_parameters
- #oauth_signature
- #oauth_signature_method
- #oauth_timestamp
- #oauth_token
- #oauth_verifier
- #oauth_version
- #parameters
- #parameters_for_signature
- #query_string_blank?
- #sign
- #sign!
- #signature
- #signature_base_string
- #signature_method
- #signed?
- #signed_uri
- #timestamp
- #token

### Included Modules

- OAuth::Helper

### Files

- LICENSE
- README.rdoc
- TODO

### Class/Module Index

Quicksearch

- OAuth
- OAuth::AccessToken
- OAuth::CLI
- OAuth::Client
- OAuth::Client::Helper
- OAuth::Consumer
- OAuth::ConsumerToken
- OAuth::Error
- OAuth::Helper
- OAuth::OAuthTestHelper
- OAuth::Problem
- OAuth::RequestProxy
- OAuth::RequestProxy::ActionControllerRequest
- OAuth::RequestProxy::Base
- OAuth::RequestProxy::Curl
- OAuth::RequestProxy::Curl::Easy
- OAuth::RequestProxy::EventMachine
- OAuth::RequestProxy::EventMachine::HttpRequest
- OAuth::RequestProxy::JabberRequest
- OAuth::RequestProxy::MockRequest
- OAuth::RequestProxy::Net
- OAuth::RequestProxy::Net::HTTP
- OAuth::RequestProxy::Net::HTTP::HTTPRequest
- OAuth::RequestProxy::RackRequest
- OAuth::RequestProxy::Typhoeus
- OAuth::RequestProxy::Typhoeus::Request
- OAuth::RequestProxy::UnknownRequestType
- OAuth::RequestToken
- OAuth::Server
- OAuth::ServerToken
- OAuth::Signature
- OAuth::Signature::Base
- OAuth::Signature::HMAC
- OAuth::Signature::HMAC::Base
- OAuth::Signature::HMAC::MD5
- OAuth::Signature::HMAC::RMD160
- OAuth::Signature::HMAC::SHA1
- OAuth::Signature::HMAC::SHA2
- OAuth::Signature::MD5
- OAuth::Signature::PLAINTEXT
- OAuth::Signature::RSA
- OAuth::Signature::RSA::SHA1
- OAuth::Signature::SHA1
- OAuth::Signature::UnknownSignatureMethod
- OAuth::Token
- OAuth::Unauthorized
- ActionController
- ActionController::Base
- ActionController::TestRequest
- Digest
- Digest::HMAC
- EventMachine
- EventMachine::HttpClient
- Net
- Net::HTTPGenericRequest
- Object
- String

No matching classes.

# OAuth::RequestProxy::Base

### Attributes

options[RW]
request[RW]
unsigned_parameters[RW]

### Public Class Methods

new(request, options = {}) click to toggle source

    # File lib/oauth/request_proxy/base.rb, line 14
    def initialize(request, options = {})
      @request = request
      @unsigned_parameters = (options[:unsigned_parameters] || []).map {|param| param.to_s}
      @options = options
    end

proxies(klass) click to toggle 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() click to toggle source

TODO deprecate these

Alias for: oauth_consumer_key
non_oauth_parameters() click to toggle source

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

nonce() click to toggle source
Alias for: oauth_nonce
normalized_parameters() click to toggle source

See 9.1.1. in specs Normalize Request Parameters

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

normalized_uri() click to toggle source

See 9.1.2 in specs

    # File lib/oauth/request_proxy/base.rb, line 91
    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_callback() click to toggle source

OAuth parameters

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

oauth_consumer_key() click to toggle source

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

Also aliased as: consumer_key
oauth_header(options = {}) click to toggle source

Authorization header for OAuth

    # File lib/oauth/request_proxy/base.rb, line 138
    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

oauth_nonce() click to toggle source

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

Also aliased as: nonce
oauth_parameters() click to toggle source

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

oauth_signature() click to toggle source

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

Also aliased as: signature
oauth_signature_method() click to toggle source

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

Also aliased as: signature_method
oauth_timestamp() click to toggle source

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

Also aliased as: timestamp
oauth_token() click to toggle source

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

Also aliased as: token
oauth_verifier() click to toggle source

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

oauth_version() click to toggle source

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

parameters() click to toggle source

Parameter accessors

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

parameters_for_signature() click to toggle source

    # File lib/oauth/request_proxy/base.rb, line 78
    def parameters_for_signature
      parameters.reject { |k,v| k == "oauth_signature" || unsigned_parameters.include?(k)}
    end

query_string_blank?() click to toggle source

    # File lib/oauth/request_proxy/base.rb, line 145
    def query_string_blank?
      if uri = request.request_uri
        uri.split('?', 2)[1].nil?
      else
        request.query_string.blank?
      end
    end

sign(options = {}) click to toggle source

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

sign!(options = {}) click to toggle source

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

signature() click to toggle source
Alias for: oauth_signature
signature_base_string() click to toggle source

See 9.1 in specs

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

signature_method() click to toggle source
Alias for: oauth_signature_method
signed?() click to toggle source

Has this request been signed yet?

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

signed_uri(with_oauth = true) click to toggle source

URI, including OAuth parameters

    # File lib/oauth/request_proxy/base.rb, line 123
    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() click to toggle source
Alias for: oauth_timestamp
token() click to toggle source
Alias for: oauth_token

### Protected Instance Methods

header_params() click to toggle source

    # File lib/oauth/request_proxy/base.rb, line 155
    def header_params
      %( 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]

Generated with the Darkfish Rdoc Generator 2.