Class: OAuth::RequestProxy::Base
- Inherits:
-
Object
- Object
- OAuth::RequestProxy::Base
show all
- Includes:
- Helper
- Defined in:
- lib/oauth/request_proxy/base.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Helper
_escape, escape, generate_key, generate_timestamp, normalize, normalize_nested_query, parse_header, stringify_keys, unescape
Constructor Details
#initialize(request, options = {}) ⇒ Base
Returns a new instance of Base.
17
18
19
20
21
|
# File 'lib/oauth/request_proxy/base.rb', line 17
def initialize(request, options = {})
@request = request
@unsigned_parameters = (options[:unsigned_parameters] || []).map(&:to_s)
@options = options
end
|
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
15
16
17
|
# File 'lib/oauth/request_proxy/base.rb', line 15
def options
@options
end
|
#request ⇒ Object
Returns the value of attribute request.
15
16
17
|
# File 'lib/oauth/request_proxy/base.rb', line 15
def request
@request
end
|
#unsigned_parameters ⇒ Object
Returns the value of attribute unsigned_parameters.
15
16
17
|
# File 'lib/oauth/request_proxy/base.rb', line 15
def unsigned_parameters
@unsigned_parameters
end
|
Instance Method Details
#non_oauth_parameters ⇒ Object
89
90
91
|
# File 'lib/oauth/request_proxy/base.rb', line 89
def non_oauth_parameters
parameters.select { |k, _v| !OAuth::PARAMETERS.include?(k) }
end
|
#normalized_parameters ⇒ Object
See 9.1.1. in specs Normalize Request Parameters
104
105
106
|
# File 'lib/oauth/request_proxy/base.rb', line 104
def normalized_parameters
normalize(parameters_for_signature)
end
|
#normalized_uri ⇒ Object
98
99
100
101
|
# File 'lib/oauth/request_proxy/base.rb', line 98
def normalized_uri
u = URI.parse(uri)
"#{u.scheme.downcase}://#{u.host.downcase}#{(u.scheme.casecmp("http").zero? && u.port != 80) || (u.scheme.casecmp("https").zero? && u.port != 443) ? ":#{u.port}" : ""}#{u.path && u.path != "" ? u.path : "/"}"
end
|
#oauth_callback ⇒ Object
25
26
27
|
# File 'lib/oauth/request_proxy/base.rb', line 25
def oauth_callback
parameters["oauth_callback"]
end
|
#oauth_consumer_key ⇒ Object
Also known as:
consumer_key
29
30
31
|
# File 'lib/oauth/request_proxy/base.rb', line 29
def oauth_consumer_key
parameters["oauth_consumer_key"]
end
|
Authorization header for OAuth
145
146
147
148
149
150
|
# File 'lib/oauth/request_proxy/base.rb', line 145
def (options = {})
= oauth_parameters.map { |k, v| "#{k}=\"#{escape(v)}\"" }.join(", ")
realm = "realm=\"#{options[:realm]}\", " if options[:realm]
"OAuth #{realm}#{}"
end
|
#oauth_nonce ⇒ Object
Also known as:
nonce
33
34
35
|
# File 'lib/oauth/request_proxy/base.rb', line 33
def oauth_nonce
parameters["oauth_nonce"]
end
|
#oauth_parameters ⇒ Object
85
86
87
|
# File 'lib/oauth/request_proxy/base.rb', line 85
def oauth_parameters
parameters.select { |k, v| OAuth::PARAMETERS.include?(k) && !v.nil? && v != "" }
end
|
#oauth_signature ⇒ Object
Also known as:
signature
37
38
39
40
|
# File 'lib/oauth/request_proxy/base.rb', line 37
def oauth_signature
[parameters["oauth_signature"]].flatten.first || ""
end
|
#oauth_signature_method ⇒ Object
Also known as:
signature_method
42
43
44
45
46
47
48
49
|
# File 'lib/oauth/request_proxy/base.rb', line 42
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
51
52
53
|
# File 'lib/oauth/request_proxy/base.rb', line 51
def oauth_timestamp
parameters["oauth_timestamp"]
end
|
#oauth_token ⇒ Object
Also known as:
token
55
56
57
|
# File 'lib/oauth/request_proxy/base.rb', line 55
def oauth_token
parameters["oauth_token"]
end
|
#oauth_verifier ⇒ Object
59
60
61
|
# File 'lib/oauth/request_proxy/base.rb', line 59
def oauth_verifier
parameters["oauth_verifier"]
end
|
#oauth_version ⇒ Object
63
64
65
|
# File 'lib/oauth/request_proxy/base.rb', line 63
def oauth_version
parameters["oauth_version"]
end
|
#parameters ⇒ Object
77
78
79
|
# File 'lib/oauth/request_proxy/base.rb', line 77
def parameters
raise NotImplementedError, "Must be implemented by subclasses"
end
|
#parameters_for_signature ⇒ Object
81
82
83
|
# File 'lib/oauth/request_proxy/base.rb', line 81
def parameters_for_signature
parameters.select { |k, _v| !signature_and_unsigned_parameters.include?(k) }
end
|
#query_string_blank? ⇒ Boolean
152
153
154
155
156
157
158
|
# File 'lib/oauth/request_proxy/base.rb', line 152
def query_string_blank?
if (uri = request.env["REQUEST_URI"])
uri.split("?", 2)[1].nil?
else
request.query_string.match(/\A\s*\z/)
end
end
|
#sign(options = {}) ⇒ Object
108
109
110
|
# File 'lib/oauth/request_proxy/base.rb', line 108
def sign(options = {})
OAuth::Signature.sign(self, options)
end
|
#sign!(options = {}) ⇒ Object
112
113
114
115
116
|
# File 'lib/oauth/request_proxy/base.rb', line 112
def sign!(options = {})
parameters["oauth_signature"] = sign(options)
@signed = true
signature
end
|
#signature_and_unsigned_parameters ⇒ Object
93
94
95
|
# File 'lib/oauth/request_proxy/base.rb', line 93
def signature_and_unsigned_parameters
unsigned_parameters + ["oauth_signature"]
end
|
#signature_base_string ⇒ Object
119
120
121
122
|
# File 'lib/oauth/request_proxy/base.rb', line 119
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?
125
126
127
|
# File 'lib/oauth/request_proxy/base.rb', line 125
def signed?
@signed
end
|
#signed_uri(with_oauth: true) ⇒ Object
URI, including OAuth parameters
130
131
132
133
134
135
136
137
138
139
140
141
142
|
# File 'lib/oauth/request_proxy/base.rb', line 130
def signed_uri(with_oauth: true)
if signed?
params = if with_oauth
parameters
else
non_oauth_parameters
end
[uri, normalize(params)].join("?")
else
warn "This request has not yet been signed!"
end
end
|