This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Starting to add TwitterUsersController#new

  • Loading branch information...
1 parent e94fb1b commit 4b10c1affd151404fa7d1e7d7ab7aa0474efcc64 @jasonm jasonm committed Mar 14, 2010
View
2 README
@@ -0,0 +1,2 @@
+* You need to add the <%= twitter_connect_button %> to your sessions/new.html.erb
+* You need to add the <%= twitter_connect_button %> to your users/new.html.erb
@@ -0,0 +1,13 @@
+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})
+ 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?
+ redirect_to url
+ end
+end
@@ -0,0 +1,5 @@
+module ClearanceTwitterHelper
+ def twitter_connect_button
+
+ end
+end
@@ -3,10 +3,9 @@ Feature: Sign in with Twitter OAuth
An existing user
Should be able to sign in with Twitter OAuth
- Scenario: User has already signed up with Twitter OAuth
+ Scenario: User signs in with Twitter
Given there are no users
- And remote Twitter user exists with an username of "jerkcity"
- And a user exists that is connected to Twitter account "jerkcity"
+ And a user exists with a twitter username of "jerkcity"
When I go to the sign in page
And I click the Sign in with Twitter button
And I grant access to the Twitter application for Twitter user "jerkcity"
View
@@ -0,0 +1,69 @@
+require 'oauth'
+
+module ClearanceTwitter
+
+ def self.config(environment=RAILS_ENV)
+ {
+ 'oauth_consumer_key' => 'key',
+ 'oauth_consumer_secret' => 'secret'
+ }
+
+ # TODO
+ # @config ||= {}
+ # @config[environment] ||= YAML.load(File.open(RAILS_ROOT + '/config/twitter_auth.yml').read)[environment]
+ end
+
+ def self.base_url
+ config['base_url'] || 'https://twitter.com'
+ end
+
+ def self.consumer
+ options = {:site => ClearanceTwitter.base_url}
+ [ :authorize_path,
+ :request_token_path,
+ :access_token_path,
+ :scheme,
+ :signature_method ].each do |oauth_option|
+ options[oauth_option] = ClearanceTwitter.config[oauth_option.to_s] if ClearanceTwitter.config[oauth_option.to_s]
+ end
+
+ OAuth::Consumer.new(
+ config['oauth_consumer_key'],
+ config['oauth_consumer_secret'],
+ options
+ )
+ end
+
+ # class Error < StandardError; end
+
+ # def self.config(environment=RAILS_ENV)
+ # @config ||= {}
+ # @config[environment] ||= YAML.load(File.open(RAILS_ROOT + '/config/twitter_auth.yml').read)[environment]
+ # end
+
+ # def self.base_url
+ # config['base_url'] || 'https://twitter.com'
+ # end
+
+ # def self.path_prefix
+ # URI.parse(base_url).path
+ # end
+
+ # def self.api_timeout
+ # config['api_timeout'] || 10
+ # end
+
+ # def self.encryption_key
+ # raise TwitterAuth::Cryptify::Error, 'You must specify an encryption_key in config/twitter_auth.yml' if config['encryption_key'].blank?
+ # config['encryption_key']
+ # end
+
+ # def self.oauth_callback?
+ # config.key?('oauth_callback')
+ # end
+
+ # def self.oauth_callback
+ # config['oauth_callback']
+ # end
+
+end

0 comments on commit 4b10c1a

Please sign in to comment.