Skip to content

Commit ac75dd3

Browse files
author
Jerry Cheung
committed
deep symbolize keys for oauth client options
1 parent 63652d2 commit ac75dd3

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/omniauth/strategies/oauth2.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class OAuth2
2727
attr_accessor :access_token
2828

2929
def client
30-
::OAuth2::Client.new(options.client_id, options.client_secret, options.client_options.inject({}){|h,(k,v)| h[k.to_sym] = v; h})
30+
::OAuth2::Client.new(options.client_id, options.client_secret, deep_symbolize(options.client_options))
3131
end
3232

3333
def callback_url
@@ -75,6 +75,13 @@ def callback_phase
7575

7676
protected
7777

78+
def deep_symbolize(hash)
79+
hash.inject({}) do |h, (k,v)|
80+
h[k.to_sym] = v.is_a?(Hash) ? deep_symbolize(v) : v
81+
h
82+
end
83+
end
84+
7885
def build_access_token
7986
verifier = request.params['code']
8087
client.auth_code.get_token(verifier, {:redirect_uri => callback_url}.merge(token_params.to_hash(:symbolize_keys => true)))

spec/omniauth/strategies/oauth2_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ def app; lambda{|env| [200, {}, ["Hello."]]} end
1111
instance = subject.new(app, :client_options => {'authorize_url' => 'https://example.com'})
1212
instance.client.options[:authorize_url].should == 'https://example.com'
1313
end
14+
15+
it 'should set ssl options as connection options' do
16+
instance = subject.new(app, :client_options => {'ssl' => {'ca_path' => 'foo'}})
17+
instance.client.options[:connection_opts][:ssl] =~ {:ca_path => 'foo'}
18+
end
1419
end
1520

1621
describe '#authorize_params' do

0 commit comments

Comments
 (0)