Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

: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.
  • Loading branch information...
commit 8f4594629a79ae1ba77b99cc3abdf708fbf7b62b 1 parent c2ae5bf
Jamie Wilkinson jamiew authored
3  lib/omniauth/strategies/oauth.rb
View
@@ -14,6 +14,7 @@ class OAuth
option :open_timeout, 30
option :read_timeout, 30
option :authorize_params, {}
+ option :request_params, {}
attr_reader :access_token
@@ -25,7 +26,7 @@ def consumer
end
def request_phase
- request_token = consumer.get_request_token(:oauth_callback => callback_url)
+ request_token = consumer.get_request_token({:oauth_callback => callback_url}, options.request_params)
session['oauth'] ||= {}
session['oauth'][name.to_s] = {'callback_confirmed' => request_token.callback_confirmed?, 'request_token' => request_token.token, 'request_secret' => request_token.secret}
7 spec/omniauth/strategies/oauth_spec.rb
View
@@ -12,6 +12,7 @@ def app
use OmniAuth::Builder do
provider MyOAuthProvider, 'abc', 'def', :client_options => {:site => 'https://api.example.org'}, :name => 'example.org'
provider MyOAuthProvider, 'abc', 'def', :client_options => {:site => 'https://api.example.org'}, :authorize_params => {:abc => 'def'}, :name => 'example.org_with_authorize_params'
+ provider MyOAuthProvider, 'abc', 'def', :client_options => {:site => 'https://api.example.org'}, :request_params => {:scope => 'http://foobar.example.org'}, :name => 'example.org_with_request_params'
end
run lambda { |env| [404, {'Content-Type' => 'text/plain'}, [env.key?('omniauth.auth').to_s]] }
}.to_app
@@ -53,6 +54,12 @@ def session
it 'should set appropriate session variables' do
session['oauth'].should == {"example.org" => {'callback_confirmed' => true, 'request_token' => 'yourtoken', 'request_secret' => 'yoursecret'}}
end
+
+ it 'should pass request_params to get_request_token' do
+ get '/auth/example.org_with_request_params'
+ WebMock.should have_requested(:post, 'https://api.example.org/oauth/request_token').
+ with {|req| req.body == "scope=http%3a%2f%2ffoobar.example.org" }
+ end
end
context 'unsuccessful' do

1 comment on commit 8f45946

Jamie Wilkinson

Thanks for the speedy merge.

I'm putting some finishing touches on omniauth-tumblr and omniauth-youtube, both 1.0-friendly

Please sign in to comment.
Something went wrong with that request. Please try again.