Class: OAuth::Signature::Base
- Inherits:
-
Object
- Object
- OAuth::Signature::Base
- Includes:
- Helper
- Defined in:
- lib/oauth/signature/base.rb
Instance Attribute Summary collapse
-
#consumer_secret ⇒ Object
readonly
Returns the value of attribute consumer_secret.
-
#options ⇒ Object
Returns the value of attribute options.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#token_secret ⇒ Object
readonly
Returns the value of attribute token_secret.
Class Method Summary collapse
Instance Method Summary collapse
- #==(cmp_signature) ⇒ Object
-
#initialize(request, options = {}, &block) ⇒ Base
constructor
A new instance of Base.
- #signature ⇒ Object
- #signature_base_string ⇒ Object
- #verify ⇒ Object
Methods included from Helper
#escape, #generate_key, #generate_timestamp, #normalize, #parse_header, #unescape
Constructor Details
#initialize(request, options = {}, &block) ⇒ Base
Returns a new instance of Base.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/oauth/signature/base.rb', line 22 def initialize(request, = {}, &block) raise TypeError unless request.kind_of?(OAuth::RequestProxy::Base) @request = request @options = ## consumer secret was determined beforehand @consumer_secret = [:consumer].secret if [:consumer] # presence of :consumer_secret option will override any Consumer that's provided @consumer_secret = [:consumer_secret] if [:consumer_secret] ## token secret was determined beforehand @token_secret = [:token].secret if [:token] # presence of :token_secret option will override any Token that's provided @token_secret = [:token_secret] if [:token_secret] # override secrets based on the values returned from the block (if any) if block_given? # consumer secret and token secret need to be looked up based on pieces of the request secrets = yield block.arity == 1 ? request : [token, consumer_key, nonce, request.] if secrets.is_a?(Array) && secrets.size == 2 @token_secret = secrets[0] @consumer_secret = secrets[1] end end end |
Instance Attribute Details
#consumer_secret ⇒ Object (readonly)
Returns the value of attribute consumer_secret.
11 12 13 |
# File 'lib/oauth/signature/base.rb', line 11 def consumer_secret @consumer_secret end |
#options ⇒ Object
Returns the value of attribute options.
10 11 12 |
# File 'lib/oauth/signature/base.rb', line 10 def @options end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
11 12 13 |
# File 'lib/oauth/signature/base.rb', line 11 def request @request end |
#token_secret ⇒ Object (readonly)
Returns the value of attribute token_secret.
11 12 13 |
# File 'lib/oauth/signature/base.rb', line 11 def token_secret @token_secret end |
Class Method Details
.digest_class(digest_class = nil) ⇒ Object
17 18 19 20 |
# File 'lib/oauth/signature/base.rb', line 17 def self.digest_class(digest_class = nil) return @digest_class if digest_class.nil? @digest_class = digest_class end |
.implements(signature_method) ⇒ Object
13 14 15 |
# File 'lib/oauth/signature/base.rb', line 13 def self.implements(signature_method) OAuth::Signature.available_methods[signature_method] = self end |
Instance Method Details
#==(cmp_signature) ⇒ Object
57 58 59 |
# File 'lib/oauth/signature/base.rb', line 57 def ==(cmp_signature) Base64.decode64(signature) == Base64.decode64(cmp_signature) end |
#signature ⇒ Object
53 54 55 |
# File 'lib/oauth/signature/base.rb', line 53 def signature Base64.encode64(digest).chomp.gsub(/\n/,'') end |
#signature_base_string ⇒ Object
73 74 75 |
# File 'lib/oauth/signature/base.rb', line 73 def signature_base_string request.signature_base_string end |
#verify ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/oauth/signature/base.rb', line 61 def verify self.request.parameters.select{|k,v|v.respond_to?(:read)}.each do |p, val| unless self.request.parameters["#{p}_signature"] && Base64.decode64(self.request.parameters["#{p}_signature"]) == self.class.digest_class.digest(secret, val.length.to_s) Rails.logger.error("Invalid or missing signature for #{param}") return false else Rails.logger.info("Signature verified for #{p}") end end self == self.request.signature end |