Skip to content

Commit

Permalink
Adding some options to Twitter and Foursquare, closes omniauth#36, cl…
Browse files Browse the repository at this point in the history
…oses omniauth#40, closes omniauth#29
  • Loading branch information
Michael Bleigh committed Nov 3, 2010
1 parent 3843745 commit e72f72a
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 4 deletions.
13 changes: 12 additions & 1 deletion oa-oauth/lib/omniauth/strategies/foursquare.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
module OmniAuth
module Strategies
class Foursquare < OAuth
# Initialize the middleware
#
# @option options [Boolean, true] :sign_in When true, use a sign-in flow instead of the authorization flow.
# @option options [Boolean, false] :mobile When true, use the mobile sign-in interface.
def initialize(app, consumer_key, consumer_secret, options = {})
super(app, :foursquare, consumer_key, consumer_secret, {:site => 'http://foursquare.com'}, options)
client_options = {:site => 'http://foursquare.com'}

auth_path = (options[:sign_in] == false) ? '/oauth/authorize' : '/oauth/authenticate'
auth_path = "/mobile#{auth_path}" if options[:mobile]

client_options[:authorize_path] = auth_path

super(app, :foursquare, consumer_key, consumer_secret, client_options, options)
end

def auth_hash
Expand Down
12 changes: 9 additions & 3 deletions oa-oauth/lib/omniauth/strategies/twitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ module Strategies
# use OmniAuth::Strategies::Twitter, 'consumerkey', 'consumersecret'
#
class Twitter < OmniAuth::Strategies::OAuth
# Initialize the middleware
#
# @option options [Boolean, true] :sign_in When true, use the "Sign in with Twitter" flow instead of the authorization flow.
def initialize(app, consumer_key, consumer_secret, options = {})
super(app, :twitter, consumer_key, consumer_secret,
{:site => 'https://api.twitter.com',
:authorize_path => '/oauth/authenticate'}, options)
client_options = {
:site => 'https://api.twitter.com'
}

client_options[:authorize_path] = '/oauth/authenticate' unless options[:sign_in] == false
super(app, :twitter, consumer_key, consumer_secret, client_options, options)
end

def auth_hash
Expand Down
19 changes: 19 additions & 0 deletions oa-oauth/spec/omniauth/strategies/foursquare_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'spec_helper'

describe OmniAuth::Strategies::Foursquare do
context 'changing authentication path' do
subject{ OmniAuth::Strategies::Foursquare.new app, 'key', 'secret', (@options || {})}

[
['/oauth/authenticate',{}],
['/oauth/authorize',{:sign_in => false}],
['/mobile/oauth/authenticate', {:mobile => true}],
['/mobile/oauth/authorize', {:mobile => true, :sign_in => false}]
].each do |(path, opts)|
it "should be #{path} with options #{opts.inspect}" do
@options = opts
subject.consumer.options[:authorize_path].should == path
end
end
end
end
10 changes: 10 additions & 0 deletions oa-oauth/spec/omniauth/strategies/twitter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,14 @@

describe OmniAuth::Strategies::Twitter do
it_should_behave_like 'an oauth strategy'

it 'should use the authenticate (sign in) path by default' do
s = strategy_class.new(app, 'abc', 'def')
s.consumer.options[:authorize_path].should == '/oauth/authenticate'
end

it 'should use the authorize path if :sign_in is false' do
s = strategy_class.new(app, 'abc', 'def', :sign_in => false)
s.consumer.options[:authorize_path].should == '/oauth/authorize'
end
end
4 changes: 4 additions & 0 deletions oa-oauth/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ def strategy_class
meta[:describes]
end

def app
lambda{|env| [200, {}, ['Hello']]}
end

WebMock.disable_net_connect!

0 comments on commit e72f72a

Please sign in to comment.