Skip to content
This repository has been archived by the owner on Nov 11, 2017. It is now read-only.

Commit

Permalink
Starting to add TwitterUsersController#new
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Morrison committed Mar 14, 2010
1 parent e94fb1b commit 4b10c1a
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions app/controllers/clearance_twitter/twitter_users_controller.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions app/helpers/clearance_twitter_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module ClearanceTwitterHelper
def twitter_connect_button

end
end
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
69 changes: 69 additions & 0 deletions lib/clearance_twitter.rb
Original file line number Diff line number Diff line change
@@ -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.