Skip to content

Commit

Permalink
Adds authorize_options with :scope as a default. Closes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Bleigh committed Oct 14, 2011
1 parent 841767f commit 2953b3c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'http://rubygems.org'

gem 'omniauth', '1.0.0.alpha', :git => 'git://github.com/intridea/omniauth.git'
gem 'omniauth', '1.0.0.pr2', :git => 'git://github.com/intridea/omniauth.git'
# Specify your gem's dependencies in omniauth-oauth2.gemspec
gemspec

Expand Down
7 changes: 6 additions & 1 deletion lib/omniauth/strategies/oauth2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class OAuth2
option :client_options, {}
option :authorize_params, {}
option :token_params, {}
option :authorize_options, [:scope]

attr_accessor :access_token

Expand All @@ -38,7 +39,11 @@ def callback_url
end

def request_phase
redirect client.auth_code.authorize_url({:redirect_uri => callback_url}.merge(options.authorize_params))
redirect client.auth_code.authorize_url({:redirect_uri => callback_url}.merge(authorize_params))
end

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 callback_phase
Expand Down
14 changes: 14 additions & 0 deletions spec/omniauth/strategies/oauth2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,18 @@ def app; lambda{|env| [200, {}, ["Hello."]]} end
instance.client.options[:authorize_url].should == 'https://example.com'
end
end

describe 'authorize_params' do
subject { fresh_strategy }

it 'should include any authorize params passed in the :authorize_params option' do
instance = subject.new('abc', 'def', :authorize_params => {:foo => 'bar', :baz => 'zip'})
instance.authorize_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', :authorize_options => [:scope, :foo], :scope => 'bar', :foo => 'baz')
instance.authorize_params.should == {'scope' => 'bar', 'foo' => 'baz'}
end
end
end

0 comments on commit 2953b3c

Please sign in to comment.