Permalink
Browse files

add oauth callback_url to oauth authorize_url

  • Loading branch information...
1 parent 575f106 commit 7dafa744eeb19aa4b3431cfc0c41bbcf5fbc4a8e @jasonm jasonm committed Mar 14, 2010
@@ -1,22 +1,16 @@
class ClearanceTwitter::TwitterUsersController < ApplicationController
def new
oauth_callback = request.protocol + request.host_with_port + '/oauth_callback'
- @request_token = ClearanceTwitter.consumer.get_request_token({:oauth_callback=>oauth_callback})
+ @request_token = ClearanceTwitter.consumer.get_request_token # what is this needed for? ...get_request_token({:oauth_callback=>oauth_callback})
session[:request_token] = @request_token.token
session[:request_token_secret] = @request_token.secret
url = @request_token.authorize_url
- # TODO: Test for this
- # url << "&oauth_callback=#{CGI.escape(ClearanceTwitter.oauth_callback)}" if ClearanceTwitter.oauth_callback?
+ url << "&oauth_callback=#{CGI.escape(ClearanceTwitter.oauth_callback)}"
redirect_to url
end
def oauth_callback
- puts "Doing the #oauth_callback"
- puts "---Session---"
- p session
- puts "---Params---"
- p params
unless session[:request_token] && session[:request_token_secret]
deny_access('No authentication information was found in the session. Please try again.') and return
end
@@ -1,5 +1,6 @@
module ClearanceTwitterHelper
def twitter_connect_button
-
+ twitter_image_tag = image_tag('sign_in_with_twitter.png', :alt => 'Sign in using Twitter')
+ link_to twitter_image_tag, new_twitter_user_path
end
end
@@ -74,23 +74,6 @@ def assign_twitter_attributes(hash)
send("#{att}=", hash[att.to_s]) if respond_to?("#{att}=")
end
end
-
- # def facebook_user
- # if facebook_user?
- # Facebooker::User.new(fb_user_id)
- # else
- # nil
- # end
- # end
-
- # def linked_on_facebook_to?(facebook_user)
- # facebook_user.uid == fb_user_id
- # end
-
- # def link_on_facebook_to(facebook_user)
- # self.fb_user_id = facebook_user.uid
- # save
- # end
end
module ClassMethods
@@ -102,26 +85,14 @@ def identify_or_create_from_access_token(token, secret=nil)
response = token.get(ClearanceTwitter.path_prefix + '/account/verify_credentials.json')
user_info = handle_response(response)
- puts "*"*80
- puts "user_info:"
- p user_info
-
if user = User.find_by_twitter_username(user_info['screen_name'].to_s)
- puts "found existing user with twitter_username"
user.twitter_username = user_info['screen_name']
user.assign_twitter_attributes(user_info)
user.twitter_access_token = token.token
user.twitter_access_secret = token.secret
- raise "Inside #identify_or_create_from_access_token, trying to save invalid user:\n#{user.errors.full_messages}" if !user.valid?
user.save
-
- puts "*"*80
- puts "the new User:"
- p user
-
user
else
- puts "found existing user with twitter_username"
User.create_from_twitter_hash_and_token(user_info, token)
end
end
@@ -130,7 +101,6 @@ def create_from_twitter_hash_and_token(user_info, access_token)
user = User.new_from_twitter_hash(user_info)
user.twitter_access_token = access_token.token
user.twitter_access_secret = access_token.secret
- raise "Inside #create_from_twitter_hash_and_token, trying to save invalid user:\n#{user.errors.full_messages}" if !user.valid?
user.save
user
end
@@ -140,11 +110,9 @@ def new_from_twitter_hash(hash)
# raise ArgumentError, 'Invalid hash: must include id.' unless hash.key?('id')
user = User.new
- # TODO Add test to motivate #twitter_id
user.twitter_id = hash['id'].to_s
user.twitter_username = hash['screen_name']
user.assign_twitter_attributes(hash)
-
user
end
end
@@ -8,8 +8,8 @@ def manifest
'db/migrate',
:migration_file_name => "add_clearance_twitter_fields_to_users"
end
-# m.insert_into 'app/controllers/application_controller.rb',
-# 'helper :clearance_twitter'
+ m.insert_into 'app/controllers/application_controller.rb',
+ 'helper :clearance_twitter'
# m.insert_into 'app/controllers/application_controller.rb',
# 'include ClearanceTwitter::Authentication',
# :after => 'include Clearance::Authentication'
@@ -10,7 +10,6 @@ development:
# api_timeout: 10
# remember_for: 14 # days
- oauth_callback: "http://localhost:3000/oauth_callback_twitter_users"
test:
strategy: oauth
oauth_consumer_key: testkey
@@ -19,7 +18,6 @@ test:
authorize_path: "/oauth/authenticate"
# api_timeout: 10
# remember_for: 14 # days
- oauth_callback: "http://localhost:3000/oauth_callback_twitter_users"
cucumber:
strategy: oauth
oauth_consumer_key: testkey
@@ -28,4 +26,3 @@ cucumber:
authorize_path: "/oauth/authenticate"
# api_timeout: 10
# remember_for: 14 # days
- oauth_callback: "http://localhost:3000/oauth_callback_twitter_users"
@@ -16,9 +16,13 @@
click_link 'Sign in using Twitter'
end
-# Then 'I should be directed to sign in with Twitter' do
-# assert_redirected_to 'foo.com'
-# end
+Then 'I should be directed to sign in with Twitter' do
+ request_token = ClearanceTwitter.consumer.get_request_token
+ authorize_url = request_token.authorize_url
+ authorize_url << "&oauth_callback=#{CGI.escape(ClearanceTwitter.oauth_callback)}"
+
+ assert_redirected_to authorize_url
+end
Then /^there should be (\d+) users? in the system$/ do |count|
assert_equal count.to_i, User.count, User.all.inspect
@@ -40,33 +44,6 @@
When 'I deny access to the Twitter application' do
end
-# Given /^remote Twitter user exists with an username of "([^\"]*)"$/ do |arg1|
-# pending # express the regexp above with the code you wish you had
-# end
-#
-# Given /^a user exists that is connected to Twitter account "([^\"]*)"$/ do |arg1|
-# pending # express the regexp above with the code you wish you had
-# end
-#
-# When /^I am signed into Twitter account "([^\"]*)"$/ do |arg1|
-# pending # express the regexp above with the code you wish you had
-# end
-
Given /^Twitter OAuth is faked$/ do
FakeTwitter.stub_oauth
- # [TwitterAuth.config['authorize_path'], '/oauth/request_token', '/oauth/authorize', '/oauth/access_token'].each do |path|
- # FakeWeb.register_uri(:any, TwitterAuth.config['base_url'] + path, :body => '')
- # end
-
- # request_token = stub('request_token',
- # :authorize_url => TwitterAuth.config['base_url'] + TwitterAuth.config['authorize_path'],
- # :token => 'token',
- # :secret => 'secret')
- # consumer = stub('consumer', :get_request_token => request_token)
- # TwitterAuth.stubs(:consumer).returns(consumer)
end
-
-# Then /^I should be directed to Twitter OAuth$/ do
-# assert_redirected_to(TwitterAuth.config['base_url'] + TwitterAuth.config['authorize_path'] + '&oauth_callback=' + CGI.escape(TwitterAuth.config['oauth_callback']))
-# end
-
@@ -11,7 +11,7 @@ Feature: Sign in with Twitter OAuth
| jerkcity | 999 |
When I go to the sign in page
And I click the Sign in with Twitter button
- # Then I should be directed to sign in with Twitter
+ Then I should be directed to sign in with Twitter
When I grant access to the Twitter application for Twitter user "jerkcity" with ID 999
Then I should see "Successfully signed in with Twitter."
And there should be 1 user in the system
@@ -8,7 +8,7 @@ Feature: Sign up with Twitter OAuth
And Twitter OAuth is faked
And I go to the sign up page
And I click the Sign in with Twitter button
- # Then I should be directed to sign in with Twitter
+ Then I should be directed to sign in with Twitter
When I grant access to the Twitter application for Twitter user "jerkcity" with ID 999
Then I should see "Successfully signed in with Twitter."
And there should be 1 user in the system
View
@@ -56,8 +56,8 @@ def self.path_prefix
# config.key?('oauth_callback')
# end
- # def self.oauth_callback
- # config['oauth_callback']
- # end
+ def self.oauth_callback
+ config['oauth_callback'] || '/twitter_users/oauth_callback'
+ end
end

0 comments on commit 7dafa74

Please sign in to comment.