Class: OAuth::RequestProxy::Base
- Inherits:
-
Object
- Object
- OAuth::RequestProxy::Base
- Includes:
- Helper
- Defined in:
- lib/oauth/request_proxy/base.rb
Direct Known Subclasses
ActionControllerRequest, JabberRequest, MockRequest, Net::HTTP::HTTPRequest, RackRequest
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#request ⇒ Object
Returns the value of attribute request.
-
#unsigned_parameters ⇒ Object
Returns the value of attribute unsigned_parameters.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(request, options = {}) ⇒ Base
constructor
A new instance of Base.
- #non_oauth_parameters ⇒ Object
-
#normalized_parameters ⇒ Object
See 9.1.1.
-
#normalized_uri ⇒ Object
See 9.1.2 in specs.
-
#oauth_callback ⇒ Object
OAuth parameters.
- #oauth_consumer_key ⇒ Object (also: #consumer_key)
-
#oauth_header(options = {}) ⇒ Object
Authorization header for OAuth.
- #oauth_nonce ⇒ Object (also: #nonce)
- #oauth_parameters ⇒ Object
- #oauth_signature ⇒ Object (also: #signature)
- #oauth_signature_method ⇒ Object (also: #signature_method)
- #oauth_timestamp ⇒ Object (also: #timestamp)
- #oauth_token ⇒ Object (also: #token)
- #oauth_verifier ⇒ Object
- #oauth_version ⇒ Object
-
#parameters ⇒ Object
Parameter accessors.
- #parameters_for_signature ⇒ Object
- #sign(options = {}) ⇒ Object
- #sign!(options = {}) ⇒ Object
-
#signature_base_string ⇒ Object
See 9.1 in specs.
-
#signed? ⇒ Boolean
Has this request been signed yet?.
-
#signed_uri(with_oauth = true) ⇒ Object
URI, including OAuth parameters.
Methods included from Helper
#escape, #generate_key, #generate_timestamp, #normalize, #parse_header, #unescape
Constructor Details
#initialize(request, options = {}) ⇒ Base
Returns a new instance of Base.
14 15 16 17 18 |
# File 'lib/oauth/request_proxy/base.rb', line 14 def initialize(request, = {}) @request = request @unsigned_parameters = ([:unsigned_parameters] || []).map {|param| param.to_s} @options = end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
12 13 14 |
# File 'lib/oauth/request_proxy/base.rb', line 12 def @options end |
#request ⇒ Object
Returns the value of attribute request.
12 13 14 |
# File 'lib/oauth/request_proxy/base.rb', line 12 def request @request end |
#unsigned_parameters ⇒ Object
Returns the value of attribute unsigned_parameters.
12 13 14 |
# File 'lib/oauth/request_proxy/base.rb', line 12 def unsigned_parameters @unsigned_parameters end |
Class Method Details
.proxies(klass) ⇒ Object
8 9 10 |
# File 'lib/oauth/request_proxy/base.rb', line 8 def self.proxies(klass) OAuth::RequestProxy.available_proxies[klass] = self end |
Instance Method Details
#non_oauth_parameters ⇒ Object
86 87 88 |
# File 'lib/oauth/request_proxy/base.rb', line 86 def non_oauth_parameters parameters.reject { |k,v| OAuth::PARAMETERS.include?(k) } end |
#normalized_parameters ⇒ Object
See 9.1.1. in specs Normalize Request Parameters
97 98 99 |
# File 'lib/oauth/request_proxy/base.rb', line 97 def normalized_parameters normalize(parameters_for_signature) end |
#normalized_uri ⇒ Object
See 9.1.2 in specs
91 92 93 94 |
# 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 ⇒ Object
OAuth parameters
22 23 24 |
# File 'lib/oauth/request_proxy/base.rb', line 22 def oauth_callback parameters['oauth_callback'] end |
#oauth_consumer_key ⇒ Object Also known as: consumer_key
26 27 28 |
# File 'lib/oauth/request_proxy/base.rb', line 26 def oauth_consumer_key parameters['oauth_consumer_key'] end |
#oauth_header(options = {}) ⇒ Object
Authorization header for OAuth
138 139 140 141 142 143 |
# File 'lib/oauth/request_proxy/base.rb', line 138 def oauth_header( = {}) header_params_str = oauth_parameters.map { |k,v| "#{k}=\"#{escape(v)}\"" }.join(', ') realm = "realm=\"#{[:realm]}\", " if [:realm] "OAuth #{realm}#{header_params_str}" end |
#oauth_nonce ⇒ Object Also known as: nonce
30 31 32 |
# File 'lib/oauth/request_proxy/base.rb', line 30 def oauth_nonce parameters['oauth_nonce'] end |
#oauth_parameters ⇒ Object
82 83 84 |
# 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 ⇒ Object Also known as: signature
34 35 36 37 |
# File 'lib/oauth/request_proxy/base.rb', line 34 def oauth_signature # TODO can this be nil? parameters['oauth_signature'] || "" end |
#oauth_signature_method ⇒ Object Also known as: signature_method
39 40 41 42 43 44 45 46 |
# 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 |
#oauth_timestamp ⇒ Object Also known as: timestamp
48 49 50 |
# File 'lib/oauth/request_proxy/base.rb', line 48 def parameters['oauth_timestamp'] end |
#oauth_token ⇒ Object Also known as: token
52 53 54 |
# File 'lib/oauth/request_proxy/base.rb', line 52 def oauth_token parameters['oauth_token'] end |
#oauth_verifier ⇒ Object
56 57 58 |
# File 'lib/oauth/request_proxy/base.rb', line 56 def oauth_verifier parameters['oauth_verifier'] end |
#oauth_version ⇒ Object
60 61 62 |
# File 'lib/oauth/request_proxy/base.rb', line 60 def oauth_version parameters["oauth_version"] end |
#parameters ⇒ Object
Parameter accessors
74 75 76 |
# File 'lib/oauth/request_proxy/base.rb', line 74 def parameters raise NotImplementedError, "Must be implemented by subclasses" end |
#parameters_for_signature ⇒ Object
78 79 80 |
# 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 |
#sign(options = {}) ⇒ Object
101 102 103 |
# File 'lib/oauth/request_proxy/base.rb', line 101 def sign( = {}) OAuth::Signature.sign(self, ) end |
#sign!(options = {}) ⇒ Object
105 106 107 108 109 |
# File 'lib/oauth/request_proxy/base.rb', line 105 def sign!( = {}) parameters["oauth_signature"] = sign() @signed = true signature end |
#signature_base_string ⇒ Object
See 9.1 in specs
112 113 114 115 |
# 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 |
#signed? ⇒ Boolean
Has this request been signed yet?
118 119 120 |
# File 'lib/oauth/request_proxy/base.rb', line 118 def signed? @signed end |
#signed_uri(with_oauth = true) ⇒ Object
URI, including OAuth parameters
123 124 125 126 127 128 129 130 131 132 133 134 135 |
# 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 |