Permalink
Browse files

Adds token_options for the same functionality as authorize_options

  • Loading branch information...
1 parent 2953b3c commit 6dca06a1ec12df475a61e258d04bec80e1c105a0 Michael Bleigh committed Oct 14, 2011
Showing with 21 additions and 2 deletions.
  1. +6 −1 lib/omniauth/strategies/oauth2.rb
  2. +15 −1 spec/omniauth/strategies/oauth2_spec.rb
@@ -19,8 +19,9 @@ class OAuth2
option :client_secret, nil
option :client_options, {}
option :authorize_params, {}
- option :token_params, {}
option :authorize_options, [:scope]
+ option :token_params, {}
+ option :token_options, []
attr_accessor :access_token
@@ -46,6 +47,10 @@ def authorize_params
options.authorize_params.merge(options.authorize_options.inject({}){|h,k| h[k.to_sym] = options[k] if options[k]; h})
end
+ def token_params
+ options.token_params.merge(options.token_options.inject({}){|h,k| h[k.to_sym] = options[k] if options[k]; h})
+ end
+
def callback_phase
if request.params['error'] || request.params['error_reason']
raise CallbackError.new(request.params['error'], request.params['error_description'] || request.params['error_reason'], request.params['error_uri'])
@@ -13,7 +13,7 @@ def app; lambda{|env| [200, {}, ["Hello."]]} end
end
end
- describe 'authorize_params' do
+ describe '#authorize_params' do
subject { fresh_strategy }
it 'should include any authorize params passed in the :authorize_params option' do
@@ -26,4 +26,18 @@ def app; lambda{|env| [200, {}, ["Hello."]]} end
instance.authorize_params.should == {'scope' => 'bar', 'foo' => 'baz'}
end
end
+
+ describe '#token_params' do
+ subject { fresh_strategy }
+
+ it 'should include any authorize params passed in the :authorize_params option' do
+ instance = subject.new('abc', 'def', :token_params => {:foo => 'bar', :baz => 'zip'})
+ instance.token_params.should == {'foo' => 'bar', 'baz' => 'zip'}
+ end
+
+ it 'should include top-level options that are marked as :authorize_options' do
+ instance = subject.new('abc', 'def', :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz')
+ instance.token_params.should == {'scope' => 'bar', 'foo' => 'baz'}
+ end
+ end
end

0 comments on commit 6dca06a

Please sign in to comment.