Skip to content

Commit 8f45946

Browse files
committed
:request_params option for passing content to get_request_token
This is required by the YouTube OAuth strategy, which has to pass a custom :scope variable with the request token.
1 parent c2ae5bf commit 8f45946

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/omniauth/strategies/oauth.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class OAuth
1414
option :open_timeout, 30
1515
option :read_timeout, 30
1616
option :authorize_params, {}
17+
option :request_params, {}
1718

1819
attr_reader :access_token
1920

@@ -25,7 +26,7 @@ def consumer
2526
end
2627

2728
def request_phase
28-
request_token = consumer.get_request_token(:oauth_callback => callback_url)
29+
request_token = consumer.get_request_token({:oauth_callback => callback_url}, options.request_params)
2930
session['oauth'] ||= {}
3031
session['oauth'][name.to_s] = {'callback_confirmed' => request_token.callback_confirmed?, 'request_token' => request_token.token, 'request_secret' => request_token.secret}
3132

spec/omniauth/strategies/oauth_spec.rb

+7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def app
1212
use OmniAuth::Builder do
1313
provider MyOAuthProvider, 'abc', 'def', :client_options => {:site => 'https://api.example.org'}, :name => 'example.org'
1414
provider MyOAuthProvider, 'abc', 'def', :client_options => {:site => 'https://api.example.org'}, :authorize_params => {:abc => 'def'}, :name => 'example.org_with_authorize_params'
15+
provider MyOAuthProvider, 'abc', 'def', :client_options => {:site => 'https://api.example.org'}, :request_params => {:scope => 'http://foobar.example.org'}, :name => 'example.org_with_request_params'
1516
end
1617
run lambda { |env| [404, {'Content-Type' => 'text/plain'}, [env.key?('omniauth.auth').to_s]] }
1718
}.to_app
@@ -53,6 +54,12 @@ def session
5354
it 'should set appropriate session variables' do
5455
session['oauth'].should == {"example.org" => {'callback_confirmed' => true, 'request_token' => 'yourtoken', 'request_secret' => 'yoursecret'}}
5556
end
57+
58+
it 'should pass request_params to get_request_token' do
59+
get '/auth/example.org_with_request_params'
60+
WebMock.should have_requested(:post, 'https://api.example.org/oauth/request_token').
61+
with {|req| req.body == "scope=http%3a%2f%2ffoobar.example.org" }
62+
end
5663
end
5764

5865
context 'unsuccessful' do

0 commit comments

Comments
 (0)