lib/authlogic_connect/oauth/tokens/oauth_token.rb in authlogic-connect-0.0.4.06 vs lib/authlogic_connect/oauth/tokens/oauth_token.rb in authlogic-connect-0.0.5

- old
+ new

@@ -10,19 +10,23 @@ end @client end + def clear + @client = nil + end + def oauth_version self.class.oauth_version end def get(path, options = {}) client.get(path, options) end - def post(path, body='', headers ={}) + def post(path, body = "", headers = {}) client.post(path, body, headers) end class << self @@ -50,19 +54,15 @@ def oauth_key @oauth_key end def consumer - unless @consumer - if oauth_version == 1.0 - @consumer = OAuth::Consumer.new(credentials[:key], credentials[:secret], config.merge(credentials[:options] || {})) - else - @consumer = OAuth2::Client.new(credentials[:key], credentials[:secret], config.merge(credentials[:options] || {})) - end + if oauth_version == 1.0 + OAuth::Consumer.new(credentials[:key], credentials[:secret], config.merge(credentials[:options] || {})) + else + OAuth2::Client.new(credentials[:key], credentials[:secret], config.merge(credentials[:options] || {})) end - - @consumer 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? @@ -82,11 +82,12 @@ def get_token_and_secret(options = {}) oauth_verifier = options[:oauth_verifier] redirect_uri = options[:redirect_uri] token = options[:token] secret = options[:secret] - + consumer = self.consumer # cached + if oauth_version == 1.0 access = request_token(token, secret).get_access_token(:oauth_verifier => oauth_verifier) result = {:token => access.token, :secret => access.secret, :key => nil} if self.oauth_key if oauth_key.is_a?(Proc) @@ -107,12 +108,14 @@ end # this is a cleaner method so we can access the authorize_url # from oauth 1 or 2 def authorize_url(callback_url, &block) + consumer = self.consumer # cached + if oauth_version == 1.0 - request = get_request_token(callback_url) + request = get_request_token(callback_url, consumer) yield request if block_given? return request.authorize_url else options = {:redirect_uri => callback_url} @@ -129,11 +132,12 @@ OAuth::RequestToken.new(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) + def get_request_token(callback_url, consumer = nil) options = {:scope => config[:scope]} if config[:scope] + consumer ||= self.consumer 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)