Skip to content

Commit

Permalink
Added support for custom OAuth paths. Closes GH-3
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Bleigh committed Apr 18, 2009
1 parent 1fe312e commit f5accd5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
5 changes: 4 additions & 1 deletion generators/twitter_auth/templates/twitter_auth.yml
Expand Up @@ -4,6 +4,7 @@ development:
oauth_consumer_key: devkey
oauth_consumer_secret: devsecret
base_url: "https://twitter.com"
authorize_path: "/oauth/authenticate"
api_timeout: 10
remember_for: 14 # days
oauth_callback: "http://localhost:3000/oauth_callback"
Expand All @@ -12,13 +13,15 @@ test:
oauth_consumer_key: testkey
oauth_consumer_secret: testsecret
base_url: "https://twitter.com"
authorize_path: "/oauth/authenticate"
api_timeout: 10
remember_for: 14 # days
oauth_callback: "http://localhost:3000/oauth_callback"
production:
strategy: oauth
oauth_consumer_key: prodkey
oauth_consumer_secret: prodsecret
oauth_consumer_secret: prodsecret
authorize_path: "/oauth/authenticate"
base_url: "https://twitter.com"
api_timeout: 10
remember_for: 14 # days
Expand Down
14 changes: 13 additions & 1 deletion lib/twitter_auth.rb
Expand Up @@ -56,10 +56,18 @@ def self.basic?

# The OAuth consumer used by TwitterAuth for authentication. The consumer key and secret are set in your application's +config/twitter.yml+
def self.consumer
options = {:site => TwitterAuth.base_url}
[ :authorize_path,
:request_token_path,
:access_token_path,
:scheme ].each do |oauth_option|
options[oauth_option] = TwitterAuth.config[oauth_option.to_s] if TwitterAuth.config[oauth_option.to_s]
end

OAuth::Consumer.new(
config['oauth_consumer_key'],
config['oauth_consumer_secret'],
:site => TwitterAuth.base_url
options
)
end

Expand All @@ -70,6 +78,10 @@ def self.net
net.read_timeout = TwitterAuth.api_timeout
net
end

def self.authorize_path
config['authorize_path'] || '/oauth/authorize'
end
end

require 'twitter_auth/controller_extensions'
Expand Down
6 changes: 6 additions & 0 deletions spec/twitter_auth_spec.rb
Expand Up @@ -11,6 +11,12 @@
TwitterAuth.stub!(:config).and_return({'base_url' => 'https://example.com'})
TwitterAuth.base_url.should == 'https://example.com'
end

it 'should utilize oauth consumer settings' do
@config = TwitterAuth.config
TwitterAuth.stub!(:config).and_return(@config.merge('authorize_path' => '/somewhere_else'))
TwitterAuth.consumer.authorize_path.should == '/somewhere_else'
end
end

describe ".path_prefix" do
Expand Down

0 comments on commit f5accd5

Please sign in to comment.