fbauth 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.mdown +13 -1
- data/app/controllers/facebook_auth_functions.rb +80 -0
- data/app/helpers/fbauth_helper.rb +17 -0
- data/app/views/fbauth/_init.html.haml +7 -0
- data/app/views/fbauth/_login.html.haml +17 -0
- data/lib/fbauth.rb +11 -0
- metadata +6 -2
data/README.mdown
CHANGED
@@ -1,3 +1,15 @@
|
|
1
1
|
FBAuth
|
2
|
-
|
2
|
+
======
|
3
|
+
|
4
|
+
This gem provides authentication and basic Facebook functions for your Rails application.
|
5
|
+
|
6
|
+
The Authentication Challenge
|
7
|
+
----------------------------
|
8
|
+
|
9
|
+
Facebook is an evolving platform, over the past couple years we've seen a lot of change in how it authenticates users of
|
10
|
+
third-party applications.
|
11
|
+
|
12
|
+
And as of this writing, authentication with the Javascript SDK remains broken due to the reliance on cross-domain
|
13
|
+
cookies, which are simply not supported in mobile Safari, by default on Safari for Windows, and reportedly on the
|
14
|
+
Android Webkit based browser.
|
3
15
|
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module FacebookAuthFunctions
|
2
|
+
|
3
|
+
def setup_facebook_auth
|
4
|
+
@facebook_auth ||= facebook_auth
|
5
|
+
end
|
6
|
+
|
7
|
+
def require_facebook_auth
|
8
|
+
setup_facebook_auth
|
9
|
+
if @facebook_auth.nil?
|
10
|
+
redirect_to build_auth_url
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def build_auth_url
|
17
|
+
"#{request.protocol}#{request.host_with_port}#{FacebookConfig['auth_path']}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def facebook_auth
|
21
|
+
# If we have valid auth in session, use it
|
22
|
+
data = parse_session
|
23
|
+
auth = validate_and_save(data) unless data.nil?
|
24
|
+
return auth unless auth.nil?
|
25
|
+
# Clear session variable if its data was bad
|
26
|
+
session[:fbauth] = nil
|
27
|
+
|
28
|
+
# If no valid session auth, try the cookie from the JS SDK
|
29
|
+
data = parse_cookie
|
30
|
+
auth = validate_and_save(data) unless data.nil?
|
31
|
+
return auth unless auth.nil?
|
32
|
+
|
33
|
+
# If no valid session or cookie auth, last chance try the URL
|
34
|
+
data = parse_parms
|
35
|
+
auth = validate_and_save(data) unless data.nil?
|
36
|
+
return auth
|
37
|
+
end
|
38
|
+
|
39
|
+
def validate_and_save data
|
40
|
+
auth = FacebookAuth.create(data)
|
41
|
+
if auth.validate
|
42
|
+
session[:fbauth] = auth.session_data
|
43
|
+
return auth
|
44
|
+
else
|
45
|
+
return nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def parse_session
|
50
|
+
unless session[:fbauth].nil?
|
51
|
+
begin
|
52
|
+
parms = JSON.parse(session[:fbauth])
|
53
|
+
rescue => e
|
54
|
+
session[:fbauth] = nil
|
55
|
+
end
|
56
|
+
end
|
57
|
+
parms
|
58
|
+
end
|
59
|
+
|
60
|
+
def parse_parms
|
61
|
+
unless params[:session].nil?
|
62
|
+
logger.warn "###### URL parms found - #{params[:session].inspect}"
|
63
|
+
parms = JSON.parse(params[:session])
|
64
|
+
end
|
65
|
+
parms
|
66
|
+
end
|
67
|
+
|
68
|
+
def parse_cookie
|
69
|
+
cookie = cookies["fbs_#{FacebookConfig['app_id']}"]
|
70
|
+
unless cookie.nil?
|
71
|
+
parms = {}
|
72
|
+
cookie.split("&").each do |pair|
|
73
|
+
key, value = pair.split("=")
|
74
|
+
parms[key] = value
|
75
|
+
end
|
76
|
+
end
|
77
|
+
parms
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module FbauthHelper
|
2
|
+
def fbauth_login_javascript options={}
|
3
|
+
login_el = options[:login] || 'login'
|
4
|
+
add_el = options[:add] || 'add'
|
5
|
+
ready_el = options[:ready] || 'ready'
|
6
|
+
|
7
|
+
render :partial => '/fbauth/login.html.haml', :locals => { :login_el => login_el, :add_el => add_el, :ready_el => ready_el }
|
8
|
+
end
|
9
|
+
|
10
|
+
def fbauth_init_javascript options={}
|
11
|
+
render :partial => '/fbauth/init.html.haml', :locals => options
|
12
|
+
end
|
13
|
+
|
14
|
+
def fbauth
|
15
|
+
@facebook_auth
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
:javascript
|
2
|
+
$(document).ready(function() {
|
3
|
+
$('#{login_el}').hide();
|
4
|
+
$('#{add_el}').hide();
|
5
|
+
$('#{ready_el}').hide();
|
6
|
+
});
|
7
|
+
FB.getLoginStatus(function(response) {
|
8
|
+
if (response.status == 'connected') {
|
9
|
+
$('#{ready_el}').show();
|
10
|
+
window.top.location.href = '#{FacebookConfig.app_url}';
|
11
|
+
} else if (response.status == 'unknown') {
|
12
|
+
$('#{login_el}').show();
|
13
|
+
} else if (response.status == 'notConnected') {
|
14
|
+
$('#{add_el}').show();
|
15
|
+
}
|
16
|
+
});
|
17
|
+
|
data/lib/fbauth.rb
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
%w{ controllers helpers }.each do |dir|
|
2
|
+
path = File.join(File.dirname(__FILE__), '..', 'app', dir) + "/"
|
3
|
+
$LOAD_PATH << path
|
4
|
+
|
5
|
+
Dir.new(path).entries.each do |file|
|
6
|
+
if file =~ /\.rb$/
|
7
|
+
require file
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
1
12
|
require 'facebook_auth.rb'
|
2
13
|
require 'facebook_config.rb'
|
3
14
|
require 'facebook_graph.rb'
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 9
|
8
|
-
-
|
9
|
-
version: 0.9.
|
8
|
+
- 3
|
9
|
+
version: 0.9.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Three Wise Men Inc.
|
@@ -31,6 +31,10 @@ files:
|
|
31
31
|
- lib/facebook_config.rb
|
32
32
|
- lib/facebook_graph.rb
|
33
33
|
- lib/fbauth.rb
|
34
|
+
- app/controllers/facebook_auth_functions.rb
|
35
|
+
- app/helpers/fbauth_helper.rb
|
36
|
+
- app/views/fbauth/_init.html.haml
|
37
|
+
- app/views/fbauth/_login.html.haml
|
34
38
|
- rails/init.rb
|
35
39
|
- README.mdown
|
36
40
|
has_rdoc: true
|