Skip to content

Commit

Permalink
Added support for custom callbacks via YML config.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Bleigh committed Mar 18, 2009
1 parent c34d3f4 commit db7f116
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
/spec/debug.log
5 changes: 4 additions & 1 deletion app/controllers/sessions_controller.rb
Expand Up @@ -4,7 +4,10 @@ def new
@request_token = TwitterAuth.consumer.get_request_token
session[:request_token] = @request_token.token
session[:request_token_secret] = @request_token.secret
redirect_to @request_token.authorize_url

url = @request_token.authorize_url
url << "&oauth_callback=#{CGI.escape(TwitterAuth.oauth_callback)}" if TwitterAuth.oauth_callback?
redirect_to url
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/twitter_auth/basic_user.rb
@@ -1,6 +1,6 @@
module TwitterAuth
class BasicUser < TwitterAuth::GenericUser

attr_protected :cryped_password, :salt
end
end

11 changes: 10 additions & 1 deletion lib/twitter_auth.rb
Expand Up @@ -3,7 +3,16 @@ module TwitterAuth
self.base_url = 'https://twitter.com'

def self.config(environment=RAILS_ENV)
YAML.load(File.open(RAILS_ROOT + '/config/twitter_auth.yml').read)[environment]
@config ||= {}
@config[environment] ||= YAML.load(File.open(RAILS_ROOT + '/config/twitter_auth.yml').read)[environment]
end

def self.oauth_callback?
config.key?('oauth_callback')
end

def self.oauth_callback
config['oauth_callback']
end

# The authentication strategy employed by this
Expand Down
8 changes: 8 additions & 0 deletions spec/controllers/sessions_controller_spec.rb
Expand Up @@ -37,6 +37,14 @@
get :new
response.should redirect_to('https://twitter.com/oauth/authorize?oauth_token=faketoken')
end

it 'should redirect to the oauth_callback if one is specified' do
TwitterAuth.stub!(:oauth_callback).and_return('http://localhost:3000/development')
TwitterAuth.stub!(:oauth_callback?).and_return(true)

get :new
response.should redirect_to('https://twitter.com/oauth/authorize?oauth_token=faketoken&oauth_callback=' + CGI.escape(TwitterAuth.oauth_callback))
end
end

describe '#oauth_callback' do
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/config/twitter_auth.yml
Expand Up @@ -2,6 +2,7 @@ development:
strategy: oauth
oauth_consumer_key: devkey
oauth_consumer_secret: devsecret
oauth_callback: "http://localhost:3000"
test:
strategy: oauth
oauth_consumer_key: testkey
Expand Down

0 comments on commit db7f116

Please sign in to comment.