devise_facebook_connectable 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/generators/devise_facebook_connectable/devise_facebook_connectable_generator.rb +22 -0
- data/generators/devise_facebook_connectable/templates/devise.facebook_connectable.js +40 -8
- data/generators/devise_facebook_connectable/templates/facebooker.yml +29 -24
- data/lib/devise_facebook_connectable.rb +2 -2
- data/lib/devise_facebook_connectable/controller_filters.rb +2 -0
- data/lib/devise_facebook_connectable/model.rb +7 -7
- data/lib/devise_facebook_connectable/strategy.rb +3 -3
- data/lib/devise_facebook_connectable/view_helpers.rb +21 -4
- metadata +2 -2
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
class DeviseFacebookConnectableGenerator < Rails::Generator::Base
|
4
4
|
|
5
|
+
default_options :api_key => "YOUR_APP_API_KEY",
|
6
|
+
:secret_key => "YOUR_APP_SECRET_KEY"
|
7
|
+
|
5
8
|
def manifest
|
6
9
|
record do |m|
|
7
10
|
m.dependency 'xd_receiver', [], options.merge(:collision => :skip)
|
@@ -10,4 +13,23 @@ class DeviseFacebookConnectableGenerator < Rails::Generator::Base
|
|
10
13
|
end
|
11
14
|
end
|
12
15
|
|
16
|
+
protected
|
17
|
+
|
18
|
+
def add_options!(opt)
|
19
|
+
opt.separator ''
|
20
|
+
opt.separator 'Options:'
|
21
|
+
|
22
|
+
opt.on('--api API_KEY', "Facebook Application API key.") do |v|
|
23
|
+
options[:api_key] = v if v.present?
|
24
|
+
end
|
25
|
+
|
26
|
+
opt.on('--secret SECRET_KEY', "Facebook Application Secret key.") do |v|
|
27
|
+
options[:secret_key] = v if v.present?
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def banner
|
32
|
+
"Usage: #{$0} devise_facebook_connectable [--api API_KEY] [--secret SECRET_KEY]"
|
33
|
+
end
|
34
|
+
|
13
35
|
end
|
@@ -1,5 +1,8 @@
|
|
1
1
|
/**
|
2
|
-
* Helpers for devise_facebook_connectable,
|
2
|
+
* JavaScript Helpers for devise_facebook_connectable,
|
3
|
+
* to make connect/login/logout with Devise seamless.
|
4
|
+
*
|
5
|
+
* Note: JavaScript framework agnostic.
|
3
6
|
*/
|
4
7
|
|
5
8
|
if (typeof devise === 'undefined' || devise === null) {
|
@@ -10,22 +13,51 @@ if (typeof devise.facebook_connectable === 'undefined' || devise.facebook_connec
|
|
10
13
|
devise.facebook_connectable = {};
|
11
14
|
}
|
12
15
|
|
13
|
-
|
16
|
+
/*
|
17
|
+
* Connect/Login.
|
18
|
+
*/
|
19
|
+
devise.facebook_connectable.login = function fbc_login() {
|
14
20
|
document.getElementById('fb_connect_login_form').submit();
|
15
21
|
return false;
|
16
22
|
};
|
17
23
|
|
18
|
-
|
19
|
-
|
24
|
+
/*
|
25
|
+
* Connect/Login - with callback.
|
26
|
+
*/
|
27
|
+
devise.facebook_connectable.login_with_callback = function fbc_login_with_callback() {
|
28
|
+
FB.Connect.requireSession(devise.facebook_connectable.login);
|
20
29
|
return false;
|
21
30
|
};
|
22
31
|
|
23
|
-
|
32
|
+
/*
|
33
|
+
* Logout.
|
34
|
+
*/
|
35
|
+
devise.facebook_connectable.logout = function fbc_logout() {
|
24
36
|
document.getElementById('fb_connect_logout_form').submit();
|
25
37
|
return false;
|
26
38
|
};
|
27
39
|
|
28
|
-
|
29
|
-
|
40
|
+
/*
|
41
|
+
* Logout - with callback.
|
42
|
+
*/
|
43
|
+
devise.facebook_connectable.logout_with_callback = function fbc_logout_with_callback() {
|
44
|
+
FB.Connect.logout(devise.facebook_connectable.logout);
|
30
45
|
return false;
|
31
|
-
};
|
46
|
+
};
|
47
|
+
|
48
|
+
/*
|
49
|
+
* TODO: Logout.
|
50
|
+
*/
|
51
|
+
devise.facebook_connectable.disconnect = function fbc_disconnect() {
|
52
|
+
// TODO: Implement
|
53
|
+
return false;
|
54
|
+
};
|
55
|
+
|
56
|
+
/*
|
57
|
+
* TODO: Disconnect - with callback.
|
58
|
+
*/
|
59
|
+
devise.facebook_connectable.disconnect_with_callback = function fbc_disconnect_with_callback() {
|
60
|
+
// FIXME: FB.api don't seems to be loaded correctly - Facebooker issue?
|
61
|
+
// FB.api({method: 'Auth.revokeAuthorization'}, devise.facebook_connectable.disconnect);
|
62
|
+
return false;
|
63
|
+
};
|
@@ -1,28 +1,33 @@
|
|
1
1
|
defaults: &defaults
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
callback_url: http://localhost:3000 # for testing - depends on your Facebook App settings though.
|
6
|
-
pretty_errors: true
|
7
|
-
set_asset_host_to_callback_url: false
|
8
|
-
tunnel:
|
9
|
-
public_host_username:
|
10
|
-
public_host:
|
11
|
-
public_port: 4007
|
12
|
-
local_port: 3000
|
13
|
-
|
14
|
-
development:
|
15
|
-
<<: *defaults
|
2
|
+
# Required.
|
3
|
+
api_key: <%= options[:api_key] %>
|
4
|
+
secret_key: <%= options[:secret_key] %>
|
16
5
|
|
17
|
-
|
18
|
-
|
6
|
+
# Optional for Facebook Connect.
|
7
|
+
# canvas_page_name: YOUR_APP_CANVAS_NAME
|
8
|
+
# Optional for Facebook Connect. Depends on your Facebook App settings.
|
9
|
+
# callback_url: http://localhost:3000
|
19
10
|
|
20
|
-
|
21
|
-
|
11
|
+
# Optional options.
|
12
|
+
# pretty_errors: true
|
13
|
+
# set_asset_host_to_callback_url: false
|
14
|
+
# tunnel:
|
15
|
+
# public_host_username:
|
16
|
+
# public_host:
|
17
|
+
# public_port: 4007
|
18
|
+
# local_port: 3000
|
22
19
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
20
|
+
development:
|
21
|
+
<<: *defaults
|
22
|
+
|
23
|
+
test: &test
|
24
|
+
<<: *defaults
|
25
|
+
|
26
|
+
production: &production
|
27
|
+
<<: *defaults
|
28
|
+
|
29
|
+
# staging:
|
30
|
+
# <<: *production
|
31
|
+
#
|
32
|
+
# cucumber:
|
33
|
+
# <<: *test
|
@@ -36,8 +36,8 @@ module Devise
|
|
36
36
|
|
37
37
|
# Specifies if account should be created if no account exists for
|
38
38
|
# a specified Facebook UID or not.
|
39
|
-
mattr_accessor :
|
40
|
-
@@
|
39
|
+
mattr_accessor :facebook_auto_create_account
|
40
|
+
@@facebook_auto_create_account = true
|
41
41
|
end
|
42
42
|
|
43
43
|
# Load core I18n locales: en
|
@@ -20,8 +20,8 @@ module Devise
|
|
20
20
|
#
|
21
21
|
# facebook_session_key_field: Defines the name of the Facebook session key database attribute/column.
|
22
22
|
#
|
23
|
-
#
|
24
|
-
#
|
23
|
+
# facebook_auto_create_account: Speifies if account should automatically be created upon connect
|
24
|
+
# if not already exists.
|
25
25
|
#
|
26
26
|
# Examples:
|
27
27
|
#
|
@@ -140,19 +140,19 @@ module Devise
|
|
140
140
|
# Devise.setup do |config|
|
141
141
|
# config.facebook_uid_field = :facebook_uid
|
142
142
|
# config.facebook_session_key_field = :facebook_session_key
|
143
|
-
# config.
|
143
|
+
# config.facebook_auto_create_account = true
|
144
144
|
# end
|
145
145
|
#
|
146
146
|
::Devise::Models.config(self,
|
147
147
|
:facebook_uid_field,
|
148
148
|
:facebook_session_key_field,
|
149
|
-
:
|
149
|
+
:facebook_auto_create_account
|
150
150
|
)
|
151
151
|
|
152
152
|
# Alias don't work for some reason, so...a more Ruby-ish alias
|
153
|
-
# for +
|
154
|
-
def
|
155
|
-
self.
|
153
|
+
# for +facebook_auto_create_account+.
|
154
|
+
def facebook_auto_create_account?
|
155
|
+
self.facebook_auto_create_account
|
156
156
|
end
|
157
157
|
|
158
158
|
# Authenticate using a Facebook UID.
|
@@ -31,9 +31,7 @@ module Devise
|
|
31
31
|
if user.present?
|
32
32
|
success!(user)
|
33
33
|
else
|
34
|
-
if klass.
|
35
|
-
fail!(:facebook_invalid)
|
36
|
-
else
|
34
|
+
if klass.facebook_auto_create_account?
|
37
35
|
user = returning(klass.new) do |u|
|
38
36
|
u.store_facebook_credentials!(
|
39
37
|
:session_key => facebook_session.session_key,
|
@@ -48,6 +46,8 @@ module Devise
|
|
48
46
|
rescue
|
49
47
|
fail!(:facebook_invalid)
|
50
48
|
end
|
49
|
+
else
|
50
|
+
fail!(:facebook_invalid)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
# NOTE: Handled in the controller.
|
@@ -1,6 +1,12 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'devise/mapping'
|
3
3
|
|
4
|
+
# Facebook Connect view helpers, i.e. connect/login/logout links, etc.
|
5
|
+
#
|
6
|
+
# Dependencies:
|
7
|
+
#
|
8
|
+
# +devise.facebook_connectable.js+ (is generated with the generator)
|
9
|
+
#
|
4
10
|
module Devise
|
5
11
|
module FacebookConnectable
|
6
12
|
module Helpers
|
@@ -62,12 +68,12 @@ module Devise
|
|
62
68
|
# It seems Devise using :get method for session destroy. Not really RESTful?
|
63
69
|
# options.merge!(:method => :delete) if options[:autologoutlink] && signed_in?(options[:for])
|
64
70
|
|
65
|
-
content_tag(:
|
71
|
+
content_tag(:span, :class => 'fb_connect_login_link') do
|
66
72
|
facebook_connect_form(resource, options.slice(:method)) <<
|
67
73
|
if options[:button]
|
68
74
|
fb_login_button('devise.facebook_connectable.login();', options)
|
69
75
|
else
|
70
|
-
fb_logout_link(options[:label], 'devise.facebook_connectable.
|
76
|
+
fb_logout_link(options[:label], 'devise.facebook_connectable.login_with_callback();')
|
71
77
|
end
|
72
78
|
end
|
73
79
|
end
|
@@ -86,7 +92,7 @@ module Devise
|
|
86
92
|
:button => false
|
87
93
|
)
|
88
94
|
|
89
|
-
content_tag(:
|
95
|
+
content_tag(:span, :class => 'fb_connect_logout_link') do
|
90
96
|
facebook_connect_form(options.delete(:for), :logout => true, :method => :get) <<
|
91
97
|
if options[:button]
|
92
98
|
fb_login_button('devise.facebook_connectable.logout();', options.merge(:autologoutlink => true))
|
@@ -96,12 +102,23 @@ module Devise
|
|
96
102
|
end
|
97
103
|
end
|
98
104
|
|
99
|
-
#
|
105
|
+
# Agnostic Facebook Connect disconnect button/link.
|
100
106
|
# Disconnects, i.e. deletes, user account. Identical as "Delete my account",
|
101
107
|
# but for Facebook Connect (which "un-installs" the app/site for the current user).
|
102
108
|
#
|
109
|
+
# References:
|
110
|
+
#
|
111
|
+
# * http://wiki.developers.facebook.com/index.php/Auth.revokeAuthorization
|
112
|
+
#
|
103
113
|
def facebook_disconnect_link(options = {})
|
104
114
|
raise "facebook_disconnect_link: Not implemented yet."
|
115
|
+
# TODO:
|
116
|
+
# options.reverse_merge!(
|
117
|
+
# :label => ::I18n.t(:facebook_logout, :scope => [:devise, :sessions]),
|
118
|
+
# )
|
119
|
+
# content_tag(:div, :class => 'fb_connect_disconnect_link') do
|
120
|
+
# link_to_function(options[:label], 'devise.facebook_connectable.disconnect_with_callback();')
|
121
|
+
# end
|
105
122
|
end
|
106
123
|
|
107
124
|
protected
|
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.
|
4
|
+
version: 0.1.5
|
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: 2009-12-
|
12
|
+
date: 2009-12-11 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|