devise-twitter-amuino 0.1.2.pre1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +40 -0
- data/MIT-LICENSE +21 -0
- data/README.md +147 -0
- data/Rakefile +2 -0
- data/devise-twitter.gemspec +27 -0
- data/lib/devise-twitter.rb +14 -0
- data/lib/devise/twitter.rb +39 -0
- data/lib/devise/twitter/rack.rb +64 -0
- data/lib/devise/twitter/version.rb +5 -0
- data/lib/devise/twitter/warden.rb +59 -0
- data/lib/generators/devise/USAGE +8 -0
- data/lib/generators/devise/templates/README +1 -0
- data/lib/generators/devise/templates/initializer.rb +6 -0
- data/lib/generators/devise/templates/migration.rb +27 -0
- data/lib/generators/devise/twitter_generator.rb +47 -0
- data/spec/spec_helper.rb +17 -0
- metadata +154 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
devise-twitter (0.1.1)
|
5
|
+
devise (>= 1.1.0)
|
6
|
+
warden_oauth (~> 0.1.1)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
bcrypt-ruby (2.1.2)
|
12
|
+
devise (1.1.2)
|
13
|
+
bcrypt-ruby (~> 2.1.2)
|
14
|
+
warden (~> 0.10.7)
|
15
|
+
diff-lcs (1.1.2)
|
16
|
+
oauth (0.4.3)
|
17
|
+
rack (1.2.1)
|
18
|
+
rspec (2.0.0.beta.20)
|
19
|
+
rspec-core (= 2.0.0.beta.20)
|
20
|
+
rspec-expectations (= 2.0.0.beta.20)
|
21
|
+
rspec-mocks (= 2.0.0.beta.20)
|
22
|
+
rspec-core (2.0.0.beta.20)
|
23
|
+
rspec-expectations (2.0.0.beta.20)
|
24
|
+
diff-lcs (>= 1.1.2)
|
25
|
+
rspec-mocks (2.0.0.beta.20)
|
26
|
+
warden (0.10.7)
|
27
|
+
rack (>= 1.0.0)
|
28
|
+
warden_oauth (0.1.1)
|
29
|
+
oauth
|
30
|
+
warden (>= 0.8.1)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
ruby
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
bundler (>= 1.0.0)
|
37
|
+
devise (>= 1.1.0)
|
38
|
+
devise-twitter!
|
39
|
+
rspec (~> 2.0.0.beta)
|
40
|
+
warden_oauth (~> 0.1.1)
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright 2010 Martin Schuerrer. http://www.schuerrer.org
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
data/README.md
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
devise-twitter
|
2
|
+
==========
|
3
|
+
|
4
|
+
Devise-twitter adds **Sign in via Twitter** and **Connect your account to
|
5
|
+
Twitter** functionality to your [devise][1] app.
|
6
|
+
|
7
|
+
It requires at least Devise 1.1 and ONLY works with Rails 3.
|
8
|
+
|
9
|
+
Current status
|
10
|
+
--------------
|
11
|
+
|
12
|
+
Devise-twitter currently supports *Sign in via Twitter* and *Connect your
|
13
|
+
account to Twitter*, but no proper API for *Connect your account to Twitter*
|
14
|
+
exists so far.
|
15
|
+
|
16
|
+
This plugin is in use in an upcoming product and continues to be improved.
|
17
|
+
|
18
|
+
Installation
|
19
|
+
------------
|
20
|
+
|
21
|
+
Simply add devise-twitter to your Gemfile and bundle it up:
|
22
|
+
|
23
|
+
gem 'devise-twitter-amuino', :require => 'devise-twitter'
|
24
|
+
|
25
|
+
Run the generator, supplying the name of the model (e.g. User)
|
26
|
+
|
27
|
+
$ rails generate devise:twitter user
|
28
|
+
|
29
|
+
Add your OAuth credentials to `config/initializers/devise_twitter.rb`
|
30
|
+
|
31
|
+
Devise::Twitter.setup do |config|
|
32
|
+
config.consumer_key = <YOUR CONSUMER KEY HERE>
|
33
|
+
config.consumer_secret = <YOUR CONSUMER SECRET HERE>
|
34
|
+
config.scope = :user
|
35
|
+
end
|
36
|
+
|
37
|
+
Modify your user model like so
|
38
|
+
|
39
|
+
class User < ActiveRecord::Base
|
40
|
+
# To use devise-twitter don't forget to include the :twitter_oauth module:
|
41
|
+
# e.g. devise :database_authenticatable, ... , :twitter_oauth
|
42
|
+
|
43
|
+
# IMPORTANT: If you want to support sign in via twitter you MUST remove the
|
44
|
+
# :validatable module, otherwise the user will never be saved
|
45
|
+
# since it's email and password is blank.
|
46
|
+
# :validatable checks only email and password so it's safe to remove
|
47
|
+
|
48
|
+
# Include default devise modules. Others available are:
|
49
|
+
# :token_authenticatable, :confirmable, :lockable and :timeoutable
|
50
|
+
devise :database_authenticatable, :registerable,
|
51
|
+
:recoverable, :rememberable, :trackable :twitter_oauth
|
52
|
+
|
53
|
+
# Setup accessible (or protected) attributes for your model
|
54
|
+
attr_accessible :email, :password, :password_confirmation, :remember_me
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
Modify the generated routes (in `config/routes.rb`) to your liking
|
59
|
+
|
60
|
+
Application.routes.draw do
|
61
|
+
devise_for :user do
|
62
|
+
match '/user/sign_in/twitter' => Devise::Twitter::Rack::Signin
|
63
|
+
match '/user/connect/twitter' => Devise::Twitter::Rack::Connect
|
64
|
+
end
|
65
|
+
...
|
66
|
+
|
67
|
+
Run the generated migration
|
68
|
+
|
69
|
+
$ rake db:migrate
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
Signing in via Twitter
|
74
|
+
----------------------
|
75
|
+
|
76
|
+
When signing in via Twitter, after authorizing access on www.twitter.com,
|
77
|
+
devise-twitter will sign in an existing user or create a new one, if no user
|
78
|
+
with the same twitter id exists.
|
79
|
+
|
80
|
+
|
81
|
+
Connect your account to Twitter
|
82
|
+
-------------------------------
|
83
|
+
|
84
|
+
Devise-twitter supports adding Twitter credentials to an existing user account
|
85
|
+
(e.g. one that registered via email/password) but currently the API to expose
|
86
|
+
this feature is far from perfect:
|
87
|
+
|
88
|
+
After navigating to `/user/connect/twitter` and authorizing access on
|
89
|
+
www.twitter.com, devise-twitter checks if there is another user with the same
|
90
|
+
twitter id. If not devise-twitter adds twitter handle and oauth credentials
|
91
|
+
to the current user and saves.
|
92
|
+
|
93
|
+
If another user with the same twitter id is found devise-twitter sets the
|
94
|
+
session variable `warden.user.twitter.connected_user.key` to the id of this
|
95
|
+
user. Your application can check if this variable is set and display an option
|
96
|
+
to merge the two users.
|
97
|
+
|
98
|
+
if connected_user = session['warden.user.twitter.connected_user.key'].present?
|
99
|
+
connected_user = User.find(connected_user)
|
100
|
+
|
101
|
+
# Ask user if she/he wants to merge her/his accounts
|
102
|
+
# (or just go ahead and merge them)
|
103
|
+
end
|
104
|
+
|
105
|
+
If you have any idea how to improve it, please message me.
|
106
|
+
|
107
|
+
Database changes
|
108
|
+
----------------
|
109
|
+
|
110
|
+
The generated migration adds three fields to your user model:
|
111
|
+
|
112
|
+
change_table(:users) do |t|
|
113
|
+
t.column :twitter_id, :integer
|
114
|
+
t.column :twitter_handle, :string
|
115
|
+
t.column :twitter_oauth_token, :string
|
116
|
+
t.column :twitter_oauth_secret, :string
|
117
|
+
end
|
118
|
+
|
119
|
+
add_index :users, :twitter_id, :unique => true
|
120
|
+
add_index :users, :twitter_handle, :unique => true
|
121
|
+
add_index :users, [:twitter_oauth_token, :twitter_oauth_secret]
|
122
|
+
|
123
|
+
Currently the names of these fields are hard coded, but making them
|
124
|
+
customizable is on the roadmap.
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
Acknowledgements
|
129
|
+
----------------
|
130
|
+
|
131
|
+
Thanks to
|
132
|
+
|
133
|
+
* [Daniel Neighman](http://twitter.com/hassox) for creating warden, the framework Devise uses
|
134
|
+
* [Jose Valim](http://twitter.com/josevalim) for creating Devise
|
135
|
+
* [Pelle Braendgaard](http://stakeventures.com/pages/whoami) for implementing oauth support in Ruby
|
136
|
+
* [Roman Gonzalez](http://www.romanandreg.com/) for creating warden_oauth, the framework devise-twitter uses
|
137
|
+
* all the other giants who's shoulders this project stands on
|
138
|
+
|
139
|
+
|
140
|
+
Meta
|
141
|
+
----
|
142
|
+
|
143
|
+
* Code: `git clone http://github.com/MSch/devise-twitter`
|
144
|
+
* Bugs: <http://github.com/MSch/devise-twitter/issues>
|
145
|
+
* Gems: <http://rubygems.org/gems/devise-twitter>
|
146
|
+
|
147
|
+
[1]:http://github.com/plataformatec/devise
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path("../lib/devise/twitter/version", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "devise-twitter-amuino"
|
6
|
+
s.version = Devise::Twitter::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ['Martin Schuerrer', "Abel Muiño"]
|
9
|
+
s.email = ['martin@schuerrer.org', 'amuino@abelmuino.com']
|
10
|
+
s.homepage = "http://github.com/amuino/devise-twitter"
|
11
|
+
s.summary = "Sign in via Twitter and Connect your account to Twitter functionality for your Devise/Rails app"
|
12
|
+
s.description = "Sign in via Twitter and Connect your account to Twitter functionality for your Devise/Rails app"
|
13
|
+
|
14
|
+
s.required_rubygems_version = ">= 1.3.6"
|
15
|
+
s.rubyforge_project = "devise-twitter"
|
16
|
+
|
17
|
+
# FIXME: Seems like bundler can't handle [">= 1.1.0", "< 1.3.0"]
|
18
|
+
s.add_dependency "devise", ">= 1.1.0"
|
19
|
+
s.add_dependency "warden_oauth", "~> 0.1.1"
|
20
|
+
s.add_development_dependency "bundler", ">= 1.0.0"
|
21
|
+
s.add_development_dependency "rspec", "~> 2.0.0.beta"
|
22
|
+
|
23
|
+
s.files = `git ls-files`.split("\n")
|
24
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
25
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
26
|
+
s.require_paths = ["lib"]
|
27
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Devise
|
2
|
+
module Twitter
|
3
|
+
end
|
4
|
+
end
|
5
|
+
|
6
|
+
require "rack"
|
7
|
+
require "warden"
|
8
|
+
require "oauth"
|
9
|
+
require "warden_oauth"
|
10
|
+
require "devise"
|
11
|
+
require "devise/twitter"
|
12
|
+
require "devise/twitter/rack"
|
13
|
+
require "devise/twitter/warden"
|
14
|
+
require "devise/twitter/version"
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Devise
|
2
|
+
module Twitter
|
3
|
+
@@setup_done = false
|
4
|
+
|
5
|
+
mattr_accessor :consumer_key
|
6
|
+
@@consumer_key = nil
|
7
|
+
|
8
|
+
# Private methods to interface with Warden.
|
9
|
+
mattr_accessor :consumer_secret
|
10
|
+
@@consumer_secret = nil
|
11
|
+
|
12
|
+
mattr_accessor :scope
|
13
|
+
@@scope = nil
|
14
|
+
|
15
|
+
# Default way to setup Devise. Run rails generate devise_install to create
|
16
|
+
# a fresh initializer with all configuration values.
|
17
|
+
def self.setup
|
18
|
+
raise "Can not invoke setup twice" if @@setup_done
|
19
|
+
yield self
|
20
|
+
@@setup_done = true
|
21
|
+
|
22
|
+
Devise.warden do |manager|
|
23
|
+
manager.oauth(:twitter) do |twitter|
|
24
|
+
twitter.consumer_key = @@consumer_key
|
25
|
+
twitter.consumer_secret = @@consumer_secret
|
26
|
+
twitter.options = {
|
27
|
+
:site => "https://api.twitter.com",
|
28
|
+
:request_token_path => "/oauth/request_token",
|
29
|
+
:access_token_path => "/oauth/access_token",
|
30
|
+
:authorize_path => "/oauth/authenticate",
|
31
|
+
:realm => "http://api.twitter.com/"
|
32
|
+
}
|
33
|
+
end
|
34
|
+
manager.default_strategies(:scope => @@scope).unshift :twitter_oauth
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Devise
|
2
|
+
module Twitter
|
3
|
+
module Rack
|
4
|
+
Signin = proc do |env|
|
5
|
+
warden = env['warden']
|
6
|
+
session = env['rack.session']
|
7
|
+
request = ::Rack::Request.new(env)
|
8
|
+
scope = env["devise.mapping"].singular
|
9
|
+
|
10
|
+
if request.params.include?('oauth_token')
|
11
|
+
# We got a redirect from Twitter back
|
12
|
+
|
13
|
+
# Perform _only_ the twitter_oauth strategy.
|
14
|
+
# Emulate _perform_authentication in _warden/proxy.rb
|
15
|
+
strategy = warden.send(:_fetch_strategy, :twitter_oauth, scope)
|
16
|
+
strategy.authenticate!
|
17
|
+
if strategy.user
|
18
|
+
warden.set_user(strategy.user, :event => :authentication, :scope => scope)
|
19
|
+
end
|
20
|
+
|
21
|
+
redirect_to Warden::OAuth::Utils.host_with_port(request)
|
22
|
+
else
|
23
|
+
# Perform the redirect to Twitter
|
24
|
+
strategy = warden.send(:_fetch_strategy, :twitter_oauth, scope)
|
25
|
+
|
26
|
+
# warden_oauth would always redirect to / so we need to hook into it
|
27
|
+
request_token = strategy.consumer.get_request_token(:oauth_callback => request.url)
|
28
|
+
strategy.instance_variable_set(:@request_token, request_token)
|
29
|
+
|
30
|
+
# warden_oauth does exactly this if params.include? warden_oauth_provider
|
31
|
+
# which we also hack around
|
32
|
+
strategy.send(:store_request_token_on_session)
|
33
|
+
redirect_to request_token.authorize_url
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
Connect = proc do |env|
|
38
|
+
# Check that user exists in DB, otherwise we'll get 'user with access token not found'
|
39
|
+
# But since connecting to twitter only makes sense for existing users that's ok
|
40
|
+
# TODO: If our user is unobtrusive redirect_to :back
|
41
|
+
scope = env["devise.mapping"].singular
|
42
|
+
env["warden.#{scope}.twitter.perform_connect"] = true
|
43
|
+
|
44
|
+
Signin.call(env)
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
# Stolen from action_dispatch/routing/mapper.rb
|
50
|
+
def self.redirect_to(url)
|
51
|
+
status = 302 # Found
|
52
|
+
body = %(<html><body>You are being <a href="#{ERB::Util.h(url.to_s)}">redirected</a>.</body></html>)
|
53
|
+
|
54
|
+
headers = {
|
55
|
+
'Location' => url.to_s,
|
56
|
+
'Content-Type' => 'text/html',
|
57
|
+
'Content-Length' => body.length.to_s
|
58
|
+
}
|
59
|
+
|
60
|
+
[ status, headers, [body] ]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
Warden::OAuth.access_token_user_finder(:twitter) do |access_token|
|
2
|
+
perform_connect = (env["warden.#{@scope}.twitter.perform_connect"] == true)
|
3
|
+
twitter_handle = access_token.params[:screen_name]
|
4
|
+
twitter_id = access_token.params[:user_id]
|
5
|
+
klass = @env['devise.mapping'].class_name.constantize
|
6
|
+
|
7
|
+
if perform_connect
|
8
|
+
# Add twitter_handle to current user
|
9
|
+
already_existing_user = klass.where(:twitter_id => twitter_id).first
|
10
|
+
if already_existing_user.blank?
|
11
|
+
# We don't know anyone with this handle, therefore continue with connecting
|
12
|
+
user = @env['warden'].user
|
13
|
+
user.twitter_handle = twitter_handle if User.column_names.include? "twitter_handle"
|
14
|
+
user.twitter_id = twitter_id
|
15
|
+
user.twitter_oauth_token = access_token.token
|
16
|
+
user.twitter_oauth_secret = access_token.secret
|
17
|
+
user.save
|
18
|
+
return user
|
19
|
+
else
|
20
|
+
# We already have such a user in our DB
|
21
|
+
# We might need to update the twitter_handle if the user has changed it
|
22
|
+
if User.column_names.include?("twitter_handle") && twitter_handle != user.twitter_handle
|
23
|
+
user.twitter_handle = twitter_handle
|
24
|
+
user.save
|
25
|
+
end
|
26
|
+
session["warden.#{@scope}.twitter.connected_user.key"] = already_existing_user.id
|
27
|
+
return @env['warden'].user
|
28
|
+
end
|
29
|
+
else
|
30
|
+
previous_user = @env['warden'].user
|
31
|
+
|
32
|
+
# Try to find user
|
33
|
+
user = klass.where(:twitter_id => twitter_id).first if user.nil?
|
34
|
+
|
35
|
+
# Since we are logging in a new user we want to make sure the before_logout hook is called
|
36
|
+
@env['warden'].logout if previous_user.present?
|
37
|
+
|
38
|
+
if user.nil?
|
39
|
+
# Create user if we don't know him yet
|
40
|
+
user = klass.new
|
41
|
+
user.twitter_handle = twitter_handle if User.column_names.include? "twitter_handle"
|
42
|
+
user.twitter_id = twitter_id
|
43
|
+
user.twitter_oauth_token = access_token.token
|
44
|
+
user.twitter_oauth_secret = access_token.secret
|
45
|
+
user.save
|
46
|
+
else
|
47
|
+
# We might need to update the twitter_handle if the user has changed it
|
48
|
+
if User.column_names.include?("twitter_handle") && twitter_handle != user.twitter_handle
|
49
|
+
user.twitter_handle = twitter_handle
|
50
|
+
end
|
51
|
+
# We also might need to update the oauth tokens
|
52
|
+
user.twitter_oauth_token = access_token.token if user.twitter_oauth_token != access_token.token
|
53
|
+
user.twitter_oauth_secret = access_token.secret if user.twitter_oauth_secret != access_token.secret
|
54
|
+
user.save if user.changed?
|
55
|
+
end
|
56
|
+
|
57
|
+
return user
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
What you need to do now
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class AddDeviseTwitterFieldsTo<%= table_name.camelize %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
change_table(:<%= table_name %>) do |t|
|
4
|
+
t.column :twitter_handle, :string #optional
|
5
|
+
t.column :twitter_id, :integer
|
6
|
+
t.column :twitter_oauth_token, :string
|
7
|
+
t.column :twitter_oauth_secret, :string
|
8
|
+
end
|
9
|
+
|
10
|
+
add_index :<%= table_name %>, :twitter_handle, :unique => true #optional
|
11
|
+
add_index :<%= table_name %>, :twitter_id, :unique => true
|
12
|
+
add_index :<%= table_name %>, [:twitter_oauth_token, :twitter_oauth_secret]
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.down
|
16
|
+
remove_index :<%= table_name %>, :column => :twitter_handle
|
17
|
+
remove_index :<%= table_name %>, :column => :twitter_id
|
18
|
+
remove_index :<%= table_name %>, :column => [:twitter_oauth_token, :twitter_oauth_secret]
|
19
|
+
|
20
|
+
change_table(:<%= table_name %>) do |t|
|
21
|
+
t.remove :twitter_handle
|
22
|
+
t.remove :twitter_id
|
23
|
+
t.remove :twitter_oauth_token
|
24
|
+
t.remove :twitter_oauth_secret
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
|
3
|
+
module Devise
|
4
|
+
module Generators
|
5
|
+
class TwitterGenerator < ActiveRecord::Generators::Base
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
def add_migration
|
8
|
+
migration_template "migration.rb", "db/migrate/add_devise_twitter_fields_to_#{table_name}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def inject_devise_twitter_intomodel
|
12
|
+
inject_into_class model_path, class_name, <<-CONTENT
|
13
|
+
# To use devise-twitter don't forget to include the :twitter_oauth module:
|
14
|
+
# e.g. devise :database_authenticatable, ... , :twitter_oauth
|
15
|
+
|
16
|
+
# IMPORTANT: If you want to support sign in via twitter you MUST remove the
|
17
|
+
# :validatable module, otherwise the user will never be saved
|
18
|
+
# since it's email and password is blank.
|
19
|
+
# :validatable checks only email and password so it's safe to remove
|
20
|
+
|
21
|
+
CONTENT
|
22
|
+
end
|
23
|
+
|
24
|
+
def copy_initializer
|
25
|
+
template "initializer.rb", "config/initializers/devise_twitter.rb"
|
26
|
+
end
|
27
|
+
|
28
|
+
def add_devise_twitter_routes
|
29
|
+
route <<-CONTENT
|
30
|
+
devise_for :#{singular_name} do
|
31
|
+
match '/#{singular_name}/sign_in/twitter' => Devise::Twitter::Rack::Signin
|
32
|
+
match '/#{singular_name}/connect/twitter' => Devise::Twitter::Rack::Connect
|
33
|
+
end
|
34
|
+
CONTENT
|
35
|
+
end
|
36
|
+
|
37
|
+
def show_readme
|
38
|
+
readme "README" if behavior == :invoke
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
def model_path
|
43
|
+
@model_path ||= File.join("app", "models", "#{file_path}.rb")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
|
3
|
+
# Requires supporting files with custom matchers and macros, etc,
|
4
|
+
# in ./support/ and its subdirectories.
|
5
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
# == Mock Framework
|
9
|
+
#
|
10
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
11
|
+
#
|
12
|
+
# config.mock_with :mocha
|
13
|
+
# config.mock_with :flexmock
|
14
|
+
# config.mock_with :rr
|
15
|
+
config.mock_with :rspec
|
16
|
+
end
|
17
|
+
|
metadata
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: devise-twitter-amuino
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: -1876988192
|
5
|
+
prerelease: true
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 2
|
10
|
+
- pre1
|
11
|
+
version: 0.1.2.pre1
|
12
|
+
platform: ruby
|
13
|
+
authors:
|
14
|
+
- Martin Schuerrer
|
15
|
+
- "Abel Mui\xC3\xB1o"
|
16
|
+
autorequire:
|
17
|
+
bindir: bin
|
18
|
+
cert_chain: []
|
19
|
+
|
20
|
+
date: 2010-10-11 00:00:00 +02:00
|
21
|
+
default_executable:
|
22
|
+
dependencies:
|
23
|
+
- !ruby/object:Gem::Dependency
|
24
|
+
name: devise
|
25
|
+
prerelease: false
|
26
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
hash: 19
|
32
|
+
segments:
|
33
|
+
- 1
|
34
|
+
- 1
|
35
|
+
- 0
|
36
|
+
version: 1.1.0
|
37
|
+
type: :runtime
|
38
|
+
version_requirements: *id001
|
39
|
+
- !ruby/object:Gem::Dependency
|
40
|
+
name: warden_oauth
|
41
|
+
prerelease: false
|
42
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
hash: 25
|
48
|
+
segments:
|
49
|
+
- 0
|
50
|
+
- 1
|
51
|
+
- 1
|
52
|
+
version: 0.1.1
|
53
|
+
type: :runtime
|
54
|
+
version_requirements: *id002
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
prerelease: false
|
58
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
hash: 23
|
64
|
+
segments:
|
65
|
+
- 1
|
66
|
+
- 0
|
67
|
+
- 0
|
68
|
+
version: 1.0.0
|
69
|
+
type: :development
|
70
|
+
version_requirements: *id003
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: rspec
|
73
|
+
prerelease: false
|
74
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ~>
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
hash: 31098209
|
80
|
+
segments:
|
81
|
+
- 2
|
82
|
+
- 0
|
83
|
+
- 0
|
84
|
+
- beta
|
85
|
+
version: 2.0.0.beta
|
86
|
+
type: :development
|
87
|
+
version_requirements: *id004
|
88
|
+
description: Sign in via Twitter and Connect your account to Twitter functionality for your Devise/Rails app
|
89
|
+
email:
|
90
|
+
- martin@schuerrer.org
|
91
|
+
- amuino@abelmuino.com
|
92
|
+
executables: []
|
93
|
+
|
94
|
+
extensions: []
|
95
|
+
|
96
|
+
extra_rdoc_files: []
|
97
|
+
|
98
|
+
files:
|
99
|
+
- .gitignore
|
100
|
+
- Gemfile
|
101
|
+
- Gemfile.lock
|
102
|
+
- MIT-LICENSE
|
103
|
+
- README.md
|
104
|
+
- Rakefile
|
105
|
+
- devise-twitter.gemspec
|
106
|
+
- lib/devise-twitter.rb
|
107
|
+
- lib/devise/twitter.rb
|
108
|
+
- lib/devise/twitter/rack.rb
|
109
|
+
- lib/devise/twitter/version.rb
|
110
|
+
- lib/devise/twitter/warden.rb
|
111
|
+
- lib/generators/devise/USAGE
|
112
|
+
- lib/generators/devise/templates/README
|
113
|
+
- lib/generators/devise/templates/initializer.rb
|
114
|
+
- lib/generators/devise/templates/migration.rb
|
115
|
+
- lib/generators/devise/twitter_generator.rb
|
116
|
+
- spec/spec_helper.rb
|
117
|
+
has_rdoc: true
|
118
|
+
homepage: http://github.com/amuino/devise-twitter
|
119
|
+
licenses: []
|
120
|
+
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
|
124
|
+
require_paths:
|
125
|
+
- lib
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
hash: 3
|
132
|
+
segments:
|
133
|
+
- 0
|
134
|
+
version: "0"
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
none: false
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
hash: 23
|
141
|
+
segments:
|
142
|
+
- 1
|
143
|
+
- 3
|
144
|
+
- 6
|
145
|
+
version: 1.3.6
|
146
|
+
requirements: []
|
147
|
+
|
148
|
+
rubyforge_project: devise-twitter
|
149
|
+
rubygems_version: 1.3.7
|
150
|
+
signing_key:
|
151
|
+
specification_version: 3
|
152
|
+
summary: Sign in via Twitter and Connect your account to Twitter functionality for your Devise/Rails app
|
153
|
+
test_files:
|
154
|
+
- spec/spec_helper.rb
|