lib/omniauth/strategies/oauth.rb in oa-oauth-0.1.6 vs lib/omniauth/strategies/oauth.rb in oa-oauth-0.2.0.beta1
- old
+ new
@@ -4,26 +4,43 @@
module OmniAuth
module Strategies
class OAuth
include OmniAuth::Strategy
- def initialize(app, name, consumer_key, consumer_secret, options = {})
+ def initialize(app, name, consumer_key = nil, consumer_secret = nil, consumer_options = {}, options = {}, &block)
+ self.consumer_key = consumer_key
+ self.consumer_secret = consumer_secret
+ self.consumer_options = consumer_options
super
- @consumer = ::OAuth::Consumer.new(consumer_key, consumer_secret, options)
end
- attr_reader :name, :consumer
-
+
+ def consumer
+ ::OAuth::Consumer.new(consumer_key, consumer_secret, consumer_options.merge(options[:client_options] || options[:consumer_options] || {}))
+ end
+
+ attr_reader :name
+ attr_accessor :consumer_key, :consumer_secret, :consumer_options
+
def request_phase
request_token = consumer.get_request_token(:oauth_callback => callback_url)
(session[:oauth]||={})[name.to_sym] = {:callback_confirmed => request_token.callback_confirmed?, :request_token => request_token.token, :request_secret => request_token.secret}
r = Rack::Response.new
- r.redirect request_token.authorize_url
+
+ if request_token.callback_confirmed?
+ r.redirect(request_token.authorize_url)
+ else
+ r.redirect(request_token.authorize_url(:oauth_callback => callback_url))
+ end
+
r.finish
end
def callback_phase
request_token = ::OAuth::RequestToken.new(consumer, session[:oauth][name.to_sym].delete(:request_token), session[:oauth][name.to_sym].delete(:request_secret))
- @access_token = request_token.get_access_token(:oauth_verifier => request.params['oauth_verifier'])
+
+ opts = {}
+ opts[:oauth_callback] = callback_url if session[:oauth][:callback_confirmed]
+ @access_token = request_token.get_access_token(opts)
super
rescue ::OAuth::Unauthorized => e
fail!(:invalid_credentials, e)
end