devise_facebook_connectable 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009-2010 Jonas Grimfelt
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.
data/README.textile ADDED
@@ -0,0 +1,332 @@
1
+ h1. DEVISE / FACEBOOK CONNECTABLE
2
+
3
+ _Devise << Facebook Connect_
4
+
5
+ h2. What is Devise?
6
+
7
+ "http://github.com/plataformatec/devise":http://github.com/plataformatec/devise
8
+
9
+ h2. What is Devise Facebook Connect?
10
+
11
+ *Simple:*
12
+
13
+ A very straightforward *"Facebook Connect":http://wiki.developers.facebook.com/index.php/Facebook_Connect* authentication/linking with the ease of *"Devise":http://github.com/plataformatec/devise* and power of *"Facebooker":http://github.com/mmangino/facebooker*. If I may say it myself: The easiest way to get a Rails app authorized and connected with Facebook Connect. Authentication in Rails should be straightforward, right? Let's build awesome web-apps instead of re-inventing the authentication!
14
+
15
+ h2. Dependencies
16
+
17
+ *You'll need:*
18
+
19
+ * *"devise 0.9.0+":http://github.com/plataformatec/devise* for authentication - based on "warden":http://github.com/hassox/warden/.
20
+ * *"facebooker":http://github.com/mmangino/facebooker* for Facebook API integration.
21
+
22
+ *For Ruby 1.9 support:*
23
+
24
+ * *"rails 2.3.5+":http://github.com/rails/rails* which contains a required Ruby 1.9 patch that Facebooker relies on. See _Important_ for more info.
25
+
26
+ h2. Installation
27
+
28
+ *Gem*
29
+
30
+ <pre>
31
+ $ sudo gem install devise_facebook_connectable
32
+ </pre>
33
+
34
+ ...and in @config/environment.rb@:
35
+
36
+ <pre>
37
+ config.gem 'devise_facebook_connectable'
38
+ </pre>
39
+
40
+ *Dependencies*
41
+
42
+ Note: Should be installed automatically with the gem.
43
+
44
+ <pre>
45
+ $ sudo gem install devise facebooker
46
+ </pre>
47
+
48
+ ...and in @config/environment.rb@:
49
+
50
+ <pre>
51
+ config.gem 'devise'
52
+ config.gem 'facebooker'
53
+ </pre>
54
+
55
+ h2. Setup
56
+
57
+ *Devise: Setup*
58
+
59
+ See "Devise":http://github.com/plataformatec/devise documentation for instructions on how to setup Devise.
60
+
61
+ *Facebook Connectable + Facebooker: Setup*
62
+
63
+ Installs the Facebooker stuff + required Facebook Connect javascript helpers...
64
+
65
+ <pre>
66
+ $ ./script/generate devise_facebook_connectable --api API_KEY --secret SECRET_KEY
67
+ dependency xd_receiver
68
+ create public/xd_receiver.html
69
+ create public/xd_receiver_ssl.html
70
+ create config/facebooker.yml
71
+ create public/javascripts/devise.facebook_connectable.js
72
+ </pre>
73
+
74
+ Note: The @--api@ and @--secret@ arguments only makes sense if you already got Facebook application details ready; can be configured later (see _Configuration_).
75
+
76
+ *Facebook Connectable: Migration*
77
+
78
+ <pre>
79
+ create_table :users do
80
+
81
+ t.facebook_connectable
82
+
83
+ # optional: other devise modules
84
+
85
+ end
86
+ </pre>
87
+
88
+ ...and indexes (optional):
89
+
90
+ <pre>
91
+ add_index :users, :facebook_uid, :unique => true
92
+ </pre>
93
+
94
+ ...and then don't forget: @$ rake db:migrate@.
95
+
96
+ *Facebook Connectable: Model*
97
+
98
+ <pre>
99
+ class User < ActiveRecord::Base
100
+
101
+ devise :facebook_connectable
102
+
103
+ # optional: other devise modules
104
+
105
+ end
106
+ </pre>
107
+
108
+ h2. Configuration
109
+
110
+ *Create a Facebook app*
111
+
112
+ ..if you haven't already:
113
+
114
+ *"Create Facebook Application":http://facebook.com/developers/createapp.php*
115
+
116
+ ...with settings:
117
+
118
+ Application settings > Connect > Facebook Connect Settings > Connect URL: @http://localhost:3000@ (for testing purposes)
119
+ Application settings > Advanced > Advanced Settings > Sandbox Mode: @Enabled@
120
+
121
+ ...and for next step, copy-paste: @API Key@ and @Application Secret@
122
+
123
+ *@config/facebooker.yml@*
124
+
125
+ ...should look something like this:
126
+
127
+ <pre>
128
+ # ...
129
+ defaults: &defaults
130
+ api_key: YOUR_APP_API_KEY
131
+ secret_key: YOUR_APP_SECRET_KEY
132
+ # ...
133
+ </pre>
134
+
135
+ Note: For Facebook Connect only @api_key@, @secret_key@, and @Connect URL@ (configured in Facebook Application settings manager) are required.
136
+
137
+ *I18n*
138
+
139
+ Sign in/out link labels, and Flash error messages can be set using I18n:
140
+
141
+ <pre>
142
+ en:
143
+ devise:
144
+ sessions:
145
+ facebook_invalid: "Could not sign in. Invalid account."
146
+ facebook_timeout: "Facebook session expired., please sign in again to continue."
147
+ facebook_authenticity_token: "Something went wrong. For security reasons, please sign in again."
148
+ facebook_actions:
149
+ sign_in: "Sign in"
150
+ sign_out: "Sign out"
151
+ </pre>
152
+
153
+ Note: The usage of @:sign_in@/@:sign_out@ depends on configration, e.g. not used for the traditional and default Facebook Connect button.
154
+
155
+ h2. Usage
156
+
157
+ In @app/views/layouts/application.html.*@, something like (showing only the relevant parts):
158
+
159
+ <pre>
160
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
161
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
162
+
163
+ <!-- REQUIRED: Include Facebook XMLNS (XML namespace). -->
164
+ <html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
165
+ <head>
166
+ ...
167
+ <!-- REQUIRED: Include Facebook Javascript (with current locale). See Facebooker documentation. -->
168
+ <%= fb_connect_javascript_tag(:lang => ::I18n.locale) %>
169
+
170
+ <!-- REQUIRED: Include devise_facebook_connectable Javascripts. -->
171
+ <%= javascript_include_tag :defaults, 'devise.facebook_connectable' %>
172
+ ...
173
+ </head>
174
+ <body>
175
+ <!-- REQUIRED: Init Facebook Javascript (using jQuery). See Facebooker documentation. -->
176
+ <%= init_fb_connect :XFBML, :js => :jquery %>
177
+ ...
178
+ <%= yield %>
179
+ ...
180
+ </body>
181
+ </html>
182
+ </pre>
183
+
184
+ *View:*
185
+
186
+ ...add the sign in/out (connect) link somewhere - auto-detects scope:
187
+
188
+ <pre>
189
+ <%= facebook_link %>
190
+ </pre>
191
+
192
+ ...or with explicit scope:
193
+
194
+ <pre>
195
+ <%= facebook_link :for => :customer %>
196
+ </pre>
197
+
198
+ ...or even more explicit, something like:
199
+
200
+ <pre>
201
+ <% unless signed_in?(:user) %>
202
+ <%= facebook_sign_in_link :for => :user %>
203
+ <% else %>
204
+ <%= facebook_sign_out_link :for => :user %>
205
+ <% end %>
206
+ </pre>
207
+
208
+ etc.
209
+
210
+ *Model:*
211
+
212
+ ...if you want to fetch and populate any data from Facebook before connect (account creation), and/or after connect (not saved automatically):
213
+
214
+ <pre>
215
+ class User < ActiveRecord::Base
216
+ devise :facebook_connectable
217
+
218
+ def before_facebook_connect(fb_session)
219
+
220
+ # Just fetch what we really need from Facebook...
221
+ fb_session.user.populate(:locale, :current_location, :username, :name, :first_name, :last_name,
222
+ :birthday_date, :sex, :city, :state, :country)
223
+
224
+ self.locale = my_fancy_locale_parser(fb_session.user.locale)
225
+ self.time_zone = fb_session.user.current_location.try(:city)
226
+ self.country = fb_session.user.current_location.try(:country)
227
+
228
+ self.username = fb_session.user.username
229
+
230
+ self.profile.real_name = fb_session.user.name
231
+ self.profile.first_name = fb_session.user.first_name
232
+ self.profile.last_name = fb_session.user.last_name
233
+ self.profile.birthdate = fb_session.user.birthday_date.try(:to_date)
234
+ self.profile.gender = my_fancy_gender_parser(fb_session.user.sex)
235
+
236
+ self.profile.city = fb_session.user.hometown_location.try(:city)
237
+ self.profile.zip_code = fb_session.user.hometown_location.try(:state)
238
+ self.profile.country = fb_session.user.hometown_location.try(:country)
239
+
240
+ # etc...
241
+
242
+ end
243
+
244
+ def after_facebook_connect(fb_session)
245
+
246
+ # ...
247
+
248
+ end
249
+
250
+ end
251
+ </pre>
252
+
253
+ *DONE!*
254
+
255
+ <pre>
256
+ $ ./script/server
257
+ </pre>
258
+
259
+ *Note:* If you experience any issues with connecting and/or signing in/out now, then I simply must have forgot something in these instructions. Please file a GitHub-issue in such case! =)
260
+
261
+ h2. Example:
262
+
263
+ Checkout my little *"live example":http://devise-facebook-connectable.heroku.com*.
264
+
265
+ h2. Advanced Configuration
266
+
267
+ In initializer @config/initializers/devise.rb@:
268
+
269
+ <pre>
270
+ Devise.setup do |config|
271
+ # ...
272
+ config.facebook_uid_field = :facebook_uid
273
+ config.facebook_session_key_field = :facebook_session_key
274
+ config.facebook_auto_create_account = false
275
+ # ...
276
+ end
277
+ </pre>
278
+
279
+ h2. Documentation (RDoc)
280
+
281
+ "Rdoc.info/devise_facebook_connectable":http://rdoc.info/projects/grimen/devise_facebook_connectable
282
+
283
+ h2. Important
284
+
285
+ Stuff that you need to be aware of:
286
+
287
+ * Just to be clear: You need to use the @devise_facebook_connect@-helpers to sign in/out, otherwise it won't work.
288
+ * If you sign in a resource using Facebook Connect (with this extension), you need to sign out using the the Facebook Connect sign out helpers available. If not you will end up being logged into Facebook but not to the account, and vice-versa. Messy. Would be cool with some kind of polling script that logs the user out of Facebook if the account is signed out - but not really needed now; just a bit of common sense and use the helpers and this will not be an issue.
289
+ * For *Ruby 1.9* support you should *AVOID* installing Rails 2.3.4. This version of rails contains a bug in a session helper that Facebooker relies on. More info about the bug/patch "here":https://rails.lighthouseapp.com/projects/8994/tickets/3144. Rails 2.3.4.1 (patch release) should work.
290
+
291
+ h2. References
292
+
293
+ *Examples:*
294
+
295
+ * "Facebooker Showcase":http://facebooker.pjkh.com - not using Devise, but same-same.
296
+
297
+ *Documentation:*
298
+
299
+ * "Facebooker RDoc":http://facebooker.rubyforge.org
300
+ * "Facebook Connect Home":http://wiki.developers.facebook.com/index.php/Facebook_Connect
301
+ * "Facebook Connect Wiki":http://wiki.developers.facebook.com/index.php/Connect/Authorization_Websites
302
+ * "Facebook Connect Javascript SDK":http://developers.facebook.com/docs/?u=facebook.jslib.FB.Connect
303
+
304
+ *Repos:*
305
+
306
+ * "Facebook Connect Javascript client":http://github.com/facebook/connect-js
307
+
308
+ *Similar projects:*
309
+
310
+ * "authlogic_facebook_connect":http://github.com/kalasjocke/authlogic_facebook_connect - Facebook Connect for "Authlogic":http://github.com/binarylogic/authlogic by "Joakim Ekberg":http://github.com/kalasjocke (using "Facebooker":http://github.com/mmangino/facebooker)
311
+ * "authlogic_facebook":http://github.com/GICodeWarrior/authlogic_facebook Facebook Connect for "Authlogic":http://github.com/binarylogic/authlogic by "Rusty Burchfield":http://github.com/GICodeWarrior (using "MiniFB":http://github.com/appoxy/mini_fb)
312
+
313
+ h2. TODO / Known Issues
314
+
315
+ Priority:
316
+
317
+ * *Timeoutable* module should timeout Facebook sessions as well - configurable.
318
+ * *Specs/Features* would be great. Skipped tests so far as I built this using experimenting as I wasn't sure how Devise and Warden was working - trial-n-error style. Would appreciate any help on this. Looking into using Cucumber + "watircuke":http://github.com/richdownie/watircuke / "culerity":http://github.com/langalex/culerity.
319
+ * *Disconnect link helper* would makes sense, i.e. disconnect a Facebook account from the app/site (a.k.a. delete the account Facebook Connect style).
320
+ * *Connect existing accounts* using "Connect.registerUsers":http://wiki.developers.facebook.com/index.php/Connect.registerUsers.
321
+ * *Option: Facebooker vs. MiniFB* - a more slimmed implementation if Facebooker feels to heavy - for those who don't want to depend on Facebooker - want something more light-weight. Most probably implemented using "MiniFB":http://github.com/appoxy/mini_fb.
322
+ * *Review controller logic* - some of my Facebooker hacks in controller might not be best practice. They seem to do the job though. =)
323
+
324
+ Maybe:
325
+
326
+ * *Expired sessions* aka @Facebooker::Session::SessionExpired@ appears less now after some controller filter hacks - but needs thorough testing.
327
+ * *HAML vs ERB clash* - that I right now consider as a HAML bug - breaks the view helpers *if both ERB and HAML is used* in the same project. Can be avoided by either using HAML gem/plugin and use HAML views only, and vice-versa. Note: Something with the @form_for@-helper causing this issue.
328
+
329
+ h2. License
330
+
331
+ Released under the MIT license.<br />
332
+ Copyright (c) 2009-2010 "Jonas Grimfelt":http://github.com/grimen
data/Rakefile CHANGED
@@ -2,33 +2,27 @@
2
2
  require 'rubygems'
3
3
  require 'rake'
4
4
  require 'rake/rdoctask'
5
+ require File.join(File.dirname(__FILE__), 'lib', 'devise_facebook_connectable', 'version')
5
6
 
6
7
  NAME = "devise_facebook_connectable"
7
- SUMMARY = %{Devise << Facebook Connect.}
8
- HOMEPAGE = "http://github.com/grimen/#{NAME}"
9
- AUTHORS = ["Jonas Grimfelt"]
10
- EMAIL = "grimen@gmail.com"
11
- SUPPORT_FILES = %w(README)
12
8
 
13
9
  begin
14
10
  gem 'jeweler'
15
11
  require 'jeweler'
16
- Jeweler::Tasks.new do |gemspec|
17
- gemspec.name = NAME
18
- gemspec.summary = SUMMARY
19
- gemspec.description = SUMMARY
20
- gemspec.homepage = HOMEPAGE
21
- gemspec.authors = AUTHORS
22
- gemspec.email = EMAIL
23
-
24
- gemspec.require_paths = %w{lib}
25
- gemspec.files = SUPPORT_FILES << %w(Rakefile) <<
26
- Dir.glob(File.join(*%w[{generators,lib} ** *]).to_s)
27
- gemspec.extra_rdoc_files = SUPPORT_FILES
28
-
29
- gemspec.add_dependency 'activesupport', '>= 2.3.0'
30
- gemspec.add_dependency 'devise', '>= 0.7.3'
31
- gemspec.add_dependency 'facebooker', '>= 1.0.55'
12
+ Jeweler::Tasks.new do |spec|
13
+ spec.name = NAME
14
+ spec.version = ::Devise::FacebookConnectable::VERSION
15
+ spec.summary = %{Devise << Facebook Connect.}
16
+ spec.description = spec.summary
17
+ spec.homepage = "http://github.com/grimen/#{spec.name}"
18
+ spec.authors = ["Jonas Grimfelt"]
19
+ spec.email = "grimen@gmail.com"
20
+
21
+ spec.files = FileList['[A-Z]*', File.join(*%w[{generators,lib,rails} ** *]).to_s]
22
+
23
+ spec.add_dependency 'activesupport', '>= 2.3.0'
24
+ spec.add_dependency 'devise', '>= 0.9.0'
25
+ spec.add_dependency 'facebooker', '>= 1.0.55'
32
26
  end
33
27
  Jeweler::GemcutterTasks.new
34
28
  rescue LoadError
@@ -41,6 +35,6 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
41
35
  rdoc.rdoc_dir = 'rdoc'
42
36
  rdoc.title = NAME
43
37
  rdoc.options << '--line-numbers' << '--inline-source' << '--charset=UTF-8'
44
- rdoc.rdoc_files.include(SUPPORT_FILES)
38
+ rdoc.rdoc_files.include('README.textile')
45
39
  rdoc.rdoc_files.include(File.join(*%w[lib ** *.rb]))
46
40
  end
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * JavaScript Helpers for devise_facebook_connectable,
3
3
  * to make sign in/out (connect) with Devise seamless.
4
- *
4
+ *
5
5
  * Note: JavaScript framework agnostic.
6
6
  */
7
-
7
+
8
8
  if (typeof devise === 'undefined' || devise === null) {
9
9
  devise = {};
10
10
  }
@@ -13,7 +13,7 @@ if (typeof devise.facebook_connectable === 'undefined' || devise.facebook_connec
13
13
  devise.facebook_connectable = {};
14
14
  }
15
15
 
16
- /*
16
+ /*
17
17
  * Connect/Login.
18
18
  */
19
19
  devise.facebook_connectable.sign_in = function fbc_sign_in() {
@@ -21,7 +21,7 @@ devise.facebook_connectable.sign_in = function fbc_sign_in() {
21
21
  return false;
22
22
  };
23
23
 
24
- /*
24
+ /*
25
25
  * Connect/Login - with callback.
26
26
  */
27
27
  devise.facebook_connectable.sign_in_with_callback = function fbc_sign_in_with_callback() {
@@ -29,7 +29,7 @@ devise.facebook_connectable.sign_in_with_callback = function fbc_sign_in_with_ca
29
29
  return false;
30
30
  };
31
31
 
32
- /*
32
+ /*
33
33
  * Logout.
34
34
  */
35
35
  devise.facebook_connectable.sign_out = function fbc_sign_out() {
@@ -37,7 +37,7 @@ devise.facebook_connectable.sign_out = function fbc_sign_out() {
37
37
  return false;
38
38
  };
39
39
 
40
- /*
40
+ /*
41
41
  * Logout - with callback.
42
42
  */
43
43
  devise.facebook_connectable.sign_out_with_callback = function fbc_sign_out_with_callback() {
@@ -45,7 +45,7 @@ devise.facebook_connectable.sign_out_with_callback = function fbc_sign_out_with_
45
45
  return false;
46
46
  };
47
47
 
48
- /*
48
+ /*
49
49
  * TODO: Logout.
50
50
  */
51
51
  devise.facebook_connectable.disconnect = function fbc_disconnect() {
@@ -53,7 +53,7 @@ devise.facebook_connectable.disconnect = function fbc_disconnect() {
53
53
  return false;
54
54
  };
55
55
 
56
- /*
56
+ /*
57
57
  * TODO: Disconnect - with callback.
58
58
  */
59
59
  devise.facebook_connectable.disconnect_with_callback = function fbc_disconnect_with_callback() {
@@ -2,32 +2,32 @@ defaults: &defaults
2
2
  # Required.
3
3
  api_key: <%= options[:api_key] %>
4
4
  secret_key: <%= options[:secret_key] %>
5
-
5
+
6
6
  # Optional for Facebook Connect.
7
7
  # canvas_page_name: YOUR_APP_CANVAS_NAME
8
8
  # Optional for Facebook Connect. Depends on your Facebook App settings.
9
9
  # callback_url: http://localhost:3000
10
-
10
+
11
11
  # Optional options.
12
12
  # pretty_errors: true
13
13
  # set_asset_host_to_callback_url: false
14
14
  # tunnel:
15
- # public_host_username:
16
- # public_host:
15
+ # public_host_username:
16
+ # public_host:
17
17
  # public_port: 4007
18
18
  # local_port: 3000
19
-
19
+
20
20
  development:
21
21
  <<: *defaults
22
-
22
+
23
23
  test: &test
24
24
  <<: *defaults
25
-
25
+
26
26
  production: &production
27
27
  <<: *defaults
28
-
28
+
29
29
  # staging:
30
30
  # <<: *production
31
- #
31
+ #
32
32
  # cucumber:
33
33
  # <<: *test
@@ -13,7 +13,7 @@ rescue
13
13
  require 'facebooker'
14
14
  end
15
15
 
16
- require 'devise_facebook_connectable/model'
16
+ require 'devise_facebook_connectable/model' # QUESTION: should this really be here? Autoloaded below...
17
17
  require 'devise_facebook_connectable/strategy'
18
18
  require 'devise_facebook_connectable/schema'
19
19
  require 'devise_facebook_connectable/routes'
@@ -26,13 +26,13 @@ module Devise
26
26
  # generic column if different authentication solutions are used.
27
27
  mattr_accessor :facebook_uid_field
28
28
  @@facebook_uid_field = :facebook_uid
29
-
29
+
30
30
  # Specifies the name of the database column name used for storing
31
31
  # the user Facebook session key. Useful if this info should be saved in a
32
32
  # generic column if different authentication solutions are used.
33
33
  mattr_accessor :facebook_session_key_field
34
34
  @@facebook_session_key_field = :facebook_session_key
35
-
35
+
36
36
  # Specifies if account should be created if no account exists for
37
37
  # a specified Facebook UID or not.
38
38
  mattr_accessor :facebook_auto_create_account
@@ -45,10 +45,7 @@ I18n.load_path.unshift File.join(File.dirname(__FILE__), *%w[devise_facebook_con
45
45
 
46
46
  # Add +:facebook_connectable+ strategies to defaults.
47
47
  #
48
- Devise::ALL.unshift :facebook_connectable
49
- Devise::STRATEGIES.unshift :facebook_connectable
50
- Devise::CONTROLLERS[:sessions].unshift :facebook_connectable
51
-
52
- Devise::Models.module_eval do
53
- autoload :FacebookConnectable, 'devise_facebook_connectable/model'
54
- end
48
+ Devise.add_module(:facebook_connectable,
49
+ :strategy => true,
50
+ :controller => :sessions,
51
+ :model => 'devise_facebook_connectable/model')
@@ -4,7 +4,7 @@ require 'facebooker/session'
4
4
  module Devise #:nodoc:
5
5
  module FacebookConnectable #:nodoc:
6
6
  module Controllers #:nodoc:
7
-
7
+
8
8
  # Controller filters (extensions) needed for Facebook Connect.
9
9
  #
10
10
  module Filters
@@ -7,7 +7,7 @@ module Devise #:nodoc:
7
7
  # module FacebookConnectable #:nodoc:
8
8
  module Models #:nodoc:
9
9
 
10
- # Facebook Connectable Module, responsible for validating authenticity of a
10
+ # Facebook Connectable Module, responsible for validating authenticity of a
11
11
  # user and storing credentials while signing in using their Facebook account.
12
12
  #
13
13
  # == Configuration:
@@ -32,7 +32,6 @@ module Devise #:nodoc:
32
32
  def self.included(base) #:nodoc:
33
33
  base.class_eval do
34
34
  extend ClassMethods
35
- extend ::Devise::Models::SessionSerializer
36
35
  end
37
36
  end
38
37
 
@@ -72,31 +71,31 @@ module Devise #:nodoc:
72
71
  # # Overridden in Facebook Connect:able model, e.g. "User".
73
72
  # #
74
73
  # def before_facebook_connect(fb_session)
75
- #
74
+ #
76
75
  # # Just fetch what we really need from Facebook...
77
76
  # fb_session.user.populate(:locale, :current_location, :username, :name,
78
77
  # :first_name, :last_name, :birthday_date, :sex,
79
78
  # :city, :state, :country)
80
- #
79
+ #
81
80
  # self.locale = my_fancy_locale_parser(fb_session.user.locale)
82
81
  # "Stockholm" => "(GMT+01:00) Stockholm", "Never-Never-land" => "(GMT+00:00) UTC"
83
82
  # self.time_zone = fb_session.user.current_location.try(:city)
84
83
  # self.country = fb_session.user.current_location.try(:country)
85
- #
84
+ #
86
85
  # self.username = fb_session.user.username
87
- #
86
+ #
88
87
  # self.profile.real_name = fb_session.user.name
89
88
  # self.profile.first_name = fb_session.user.first_name
90
89
  # self.profile.last_name = fb_session.user.last_name
91
90
  # self.profile.birthdate = fb_session.user.birthday_date.try(:to_date)
92
91
  # self.profile.gender = my_fancy_gender_parser(fb_session.user.sex)
93
- #
92
+ #
94
93
  # self.profile.city = fb_session.user.hometown_location.try(:city)
95
94
  # self.profile.zip_code = fb_session.user.hometown_location.try(:state)
96
95
  # self.profile.country = fb_session.user.hometown_location.try(:country)
97
- #
96
+ #
98
97
  # # etc...
99
- #
98
+ #
100
99
  # end
101
100
  #
102
101
  # == For more info:
@@ -108,7 +107,7 @@ module Devise #:nodoc:
108
107
  self.send(:before_facebook_connect, facebook_session) rescue nil
109
108
  end
110
109
  end
111
-
110
+
112
111
  # Hook that gets called *after* connect (each time). Useful for
113
112
  # fetching additional user info (etc.) from Facebook.
114
113
  #
@@ -180,7 +179,7 @@ module Devise #:nodoc:
180
179
  self.facebook_auto_create_account
181
180
  end
182
181
 
183
- # Authenticate using a Facebook UID.
182
+ # Authenticate a user based on Facebook UID.
184
183
  #
185
184
  def facebook_connect(attributes = {})
186
185
  if attributes[:uid].present?
@@ -196,13 +195,13 @@ module Devise #:nodoc:
196
195
  #
197
196
  # == Example:
198
197
  #
199
- # def self.find_for_facebook_connect(conditions = {})
198
+ # def self.find_for_facebook_connect(uid, conditions = {})
200
199
  # conditions[:active] = true
201
- # self.find(:first, :conditions => conditions)
200
+ # self.find_by_facebook_uid(uid, :conditions => conditions)
202
201
  # end
203
202
  #
204
- def find_for_facebook_connect(uid)
205
- self.find_by_facebook_uid(uid)
203
+ def find_for_facebook_connect(uid, conditions = {})
204
+ self.find_by_facebook_uid(uid, :conditions => conditions)
206
205
  end
207
206
 
208
207
  # Contains the logic used in authentication. Overwritten by other devise modules.
@@ -9,9 +9,7 @@ module Devise #:nodoc:
9
9
  # Default strategy for signing in a user using Facebook Connect (a Facebook account).
10
10
  # Redirects to sign_in page if it's not authenticated
11
11
  #
12
- class FacebookConnectable < ::Warden::Strategies::Base
13
-
14
- include ::Devise::Strategies::Base
12
+ class FacebookConnectable < ::Devise::Strategies::Base
15
13
 
16
14
  # Without a Facebook session authentication cannot proceed.
17
15
  #
@@ -0,0 +1,5 @@
1
+ module Devise
2
+ module FacebookConnectable
3
+ VERSION = "0.1.9".freeze
4
+ end
5
+ end
@@ -26,7 +26,7 @@ module Devise #:nodoc:
26
26
  # to trigger submit on the sign out form to destroy the Warden session.
27
27
  # Best solution now is either to hook the even manually on click,
28
28
  # or use regular link like propsed here:
29
- #
29
+ #
30
30
  # http://forum.developers.facebook.com/viewtopic.php?pid=121283
31
31
  #
32
32
 
@@ -62,7 +62,7 @@ module Devise #:nodoc:
62
62
  # *Case 1:* If Facebook account already connected to the app/site, this is same as
63
63
  # a traditional "account sign in" but with the Facebook dialog unless already
64
64
  # logged in to Facebook.
65
- #
65
+ #
66
66
  # *Case 2:* If account is not connected to the app/site already;
67
67
  # then this is the same as a traditional "create account".
68
68
  #
@@ -126,7 +126,7 @@ module Devise #:nodoc:
126
126
  #
127
127
  def facebook_disconnect_link(*args)
128
128
  raise "facebook_disconnect_link: Not implemented yet."
129
- # TODO:
129
+ # TODO:
130
130
  # options.reverse_merge!(
131
131
  # :label => ::I18n.t(:facebook_disconnect, :scope => [:devise, :sessions, :actions]),
132
132
  # )
@@ -143,22 +143,22 @@ module Devise #:nodoc:
143
143
  #
144
144
  def auto_detect_scope(*args)
145
145
  options = args.extract_options!
146
-
146
+
147
147
  if options.key?(:for)
148
148
  options[:scope] = options[:for]
149
149
  ::ActiveSupport::Deprecation.warn("DEPRECATION: " <<
150
150
  "Devise scope :for option is deprecated. " <<
151
151
  "Use: facebook_*_link(:some_scope), or facebook_*_link(:scope => :some_scope)")
152
152
  end
153
-
153
+
154
154
  scope = args.detect { |arg| arg.is_a?(Symbol) } || options[:scope]
155
155
  scope ||= ::Warden::Manager.default_scope
156
156
  mapping = ::Devise.mappings[scope]
157
-
157
+
158
158
  if mapping.for.include?(:facebook_connectable)
159
159
  scope
160
160
  else
161
- error_message =
161
+ error_message =
162
162
  "%s" <<
163
163
  " Did you forget to devise facebook_connect in your model? Like this: devise :facebook_connectable." <<
164
164
  " You can also specify scope explicitly, e.g.: facebook_*link :for => :customer."
data/rails/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ # encoding: utf-8
2
+ require 'devise_facebook_connectable'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devise_facebook_connectable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Grimfelt
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-08 00:00:00 +01:00
12
+ date: 2010-01-26 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -30,7 +30,7 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.7.3
33
+ version: 0.9.0
34
34
  version:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: facebooker
@@ -49,19 +49,10 @@ executables: []
49
49
  extensions: []
50
50
 
51
51
  extra_rdoc_files:
52
- - Rakefile
53
- - generators/devise_facebook_connectable/devise_facebook_connectable_generator.rb
54
- - generators/devise_facebook_connectable/templates/devise.facebook_connectable.js
55
- - generators/devise_facebook_connectable/templates/facebooker.yml
56
- - lib/devise_facebook_connectable.rb
57
- - lib/devise_facebook_connectable/controller_filters.rb
58
- - lib/devise_facebook_connectable/locales/en.yml
59
- - lib/devise_facebook_connectable/model.rb
60
- - lib/devise_facebook_connectable/routes.rb
61
- - lib/devise_facebook_connectable/schema.rb
62
- - lib/devise_facebook_connectable/strategy.rb
63
- - lib/devise_facebook_connectable/view_helpers.rb
52
+ - README.textile
64
53
  files:
54
+ - MIT-LICENSE
55
+ - README.textile
65
56
  - Rakefile
66
57
  - generators/devise_facebook_connectable/devise_facebook_connectable_generator.rb
67
58
  - generators/devise_facebook_connectable/templates/devise.facebook_connectable.js
@@ -73,7 +64,9 @@ files:
73
64
  - lib/devise_facebook_connectable/routes.rb
74
65
  - lib/devise_facebook_connectable/schema.rb
75
66
  - lib/devise_facebook_connectable/strategy.rb
67
+ - lib/devise_facebook_connectable/version.rb
76
68
  - lib/devise_facebook_connectable/view_helpers.rb
69
+ - rails/init.rb
77
70
  has_rdoc: true
78
71
  homepage: http://github.com/grimen/devise_facebook_connectable
79
72
  licenses: []