lib/authlogic_connect/oauth/tokens/oauth_token.rb~ in authlogic-connect-andrewacove-0.5.6 vs lib/authlogic_connect/oauth/tokens/oauth_token.rb~ in authlogic-connect-andrewacove-0.5.7

- old
+ new

@@ -1,6 +1,14 @@ class OauthToken < AccessToken + OAuth::Consumer.class_eval do + alias_method :orig_sign!, :sign! + + def sign!(request, token=nil, request_options={}) + request_options.reverse_merge!(:site => options[:signing_endpoint]) if options[:signing_endpoint] + orig_sign!(request, token, request_options) + end + end def client unless @client if oauth_version == 1.0 @client = OAuth::AccessToken.new(self.consumer, self.token, self.secret) @@ -21,22 +29,23 @@ unless config_options.nil? api_version = config_options[:api_version] user_agent = config_options[:user_agent] end path.insert(0, "/#{api_version}") unless api_version.nil? - options.reverse_merge! {"User-Agent" => user_agent} unless user_agent.nil? + options.reverse_merge!("User-Agent" => user_agent) unless user_agent.nil? client.get(path, options) end def post(path, body='', headers ={}) + debugger config_options = self.class.send(:credentials)[:options] unless config_options.nil? api_version = config_options[:api_version] user_agent = config_options[:user_agent] end path.insert(0, "/#{api_version}") unless api_version.nil? - headers.reverse_merge! {"User-Agent" => user_agent} unless user_agent.nil? + headers.reverse_merge!("User-Agent" => user_agent) unless user_agent.nil? client.post(path, body, headers) end class << self @@ -64,18 +73,28 @@ def oauth_key @oauth_key end - def consumer + def consumer_helper options if oauth_version == 1.0 - OAuth::Consumer.new(credentials[:key], credentials[:secret], config.merge(credentials[:options] || {})) + OAuth::Consumer.new(credentials[:key], credentials[:secret], config.merge(options || {})) else - OAuth2::Client.new(credentials[:key], credentials[:secret], config.merge(credentials[:options] || {})) + OAuth2::Client.new(credentials[:key], credentials[:secret], config.merge(options || {})) end end + + def consumer + consumer_helper credentials[:options] + end + def signing_consumer + signing_endpoint = credentials[:options].try(:fetch, :signing_endpoint, nil) + site_option = {:site => signing_endpoint} unless signing_endpoint.nil? + consumer_helper credentials[:options].try(:merge, site_option||{}) + end + # if we're lucky we can find it by the token. def find_by_key_or_token(key, token, options = {}) result = self.find_by_key(key, options) unless key.nil? unless result if !token.blank? && self.respond_to?(:find_by_token) @@ -135,17 +154,17 @@ return consumer.web_server.authorize_url(options) end end def request_token(token, secret) - OAuth::RequestToken.new(consumer, token, secret) + OAuth::RequestToken.new(signing_consumer, token, secret) end # if you pass a hash as the second parameter to consumer.get_request_token, # ruby oauth will think this is a form and all sorts of bad things happen def get_request_token(callback_url) options = {:scope => config[:scope]} if config[:scope] - consumer.get_request_token({:oauth_callback => callback_url}, options) + signing_consumer.get_request_token({:oauth_callback => callback_url}, options) end def get_access_token(oauth_verifier) request_token.get_access_token(:oauth_verifier => oauth_verifier) end