Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/majormajors/omniauth
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Bleigh committed Apr 5, 2011
2 parents 6a48fdb + cad82c4 commit 71a8905
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
5 changes: 3 additions & 2 deletions oa-oauth/lib/omniauth/strategies/oauth.rb
Expand Up @@ -13,6 +13,7 @@ def initialize(app, name, consumer_key = nil, consumer_secret = nil, consumer_op
super
self.options[:open_timeout] ||= 30
self.options[:read_timeout] ||= 30
self.options[:authorize_params] = options[:authorize_params] || {}
end

def consumer
Expand All @@ -32,9 +33,9 @@ def request_phase
r = Rack::Response.new

if request_token.callback_confirmed?
r.redirect(request_token.authorize_url)
r.redirect(request_token.authorize_url(options[:authorize_params]))
else
r.redirect(request_token.authorize_url(:oauth_callback => callback_url))
r.redirect(request_token.authorize_url(options[:authorize_params].merge(:oauth_callback => callback_url)))
end

r.finish
Expand Down
1 change: 1 addition & 0 deletions oa-oauth/lib/omniauth/strategies/twitter.rb
Expand Up @@ -20,6 +20,7 @@ def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &bl
:site => 'https://api.twitter.com'
}

options[:authorize_params] = {:force_login => 'true'} if options.delete(:force_login) == true
client_options[:authorize_path] = '/oauth/authenticate' unless options[:sign_in] == false
super(app, :twitter, consumer_key, consumer_secret, client_options, options)
end
Expand Down
7 changes: 7 additions & 0 deletions oa-oauth/spec/omniauth/strategies/oauth_spec.rb
Expand Up @@ -7,6 +7,7 @@ def app
use OmniAuth::Test::PhonySession
use OmniAuth::Builder do
provider :oauth, 'example.org', 'abc', 'def', :site => 'https://api.example.org'
provider :oauth, 'example.org_with_authorize_params', 'abc', 'def', { :site => 'https://api.example.org' }, :authorize_params => {:abc => 'def'}
end
run lambda { |env| [404, {'Content-Type' => 'text/plain'}, [env.key?('omniauth.auth').to_s]] }
}.to_app
Expand All @@ -30,6 +31,12 @@ def session
last_response.headers['Location'].should == 'https://api.example.org/oauth/authorize?oauth_token=yourtoken'
end

it 'should redirect to authorize_url with authorize_params when set' do
get '/auth/example.org_with_authorize_params'
last_response.should be_redirect
last_response.headers['Location'].should == 'https://api.example.org/oauth/authorize?abc=def&oauth_token=yourtoken'
end

it 'should set appropriate session variables' do
session['oauth'].should == {"example.org" => {'callback_confirmed' => true, 'request_token' => 'yourtoken', 'request_secret' => 'yoursecret'}}
end
Expand Down
5 changes: 5 additions & 0 deletions oa-oauth/spec/omniauth/strategies/twitter_spec.rb
Expand Up @@ -7,6 +7,11 @@
s = strategy_class.new(app, 'abc', 'def')
s.consumer.options[:authorize_path].should == '/oauth/authenticate'
end

it 'should set options[:authorize_params] to { :force_login => "true" } if :force_login is true' do
s = strategy_class.new(app, 'abc', 'def', :force_login => true)
s.options[:authorize_params].should == { :force_login => 'true' }
end

it 'should use the authorize path if :sign_in is false' do
s = strategy_class.new(app, 'abc', 'def', :sign_in => false)
Expand Down

0 comments on commit 71a8905

Please sign in to comment.