facebook_dialog 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/Readme.md CHANGED
@@ -23,7 +23,7 @@ This is available for Rails >= 3.0 and Ruby >= 1.9.2
23
23
 
24
24
  #at the bottom of your page
25
25
 
26
- <%= facebook_js %>
26
+ <%= fb_js %>
27
27
  <%= javascript_tag do %>
28
28
  <%= fb_init_js %>
29
29
  $("#share_on_facebook").click(function(e){
@@ -32,3 +32,36 @@ This is available for Rails >= 3.0 and Ruby >= 1.9.2
32
32
  <%- end -%>
33
33
  ```
34
34
 
35
+ Use with OmniAuth
36
+ ==
37
+
38
+ We've created a convenience mechanism for you to use FacebookDialog with [omniauth-facebook](https://github.com/mkdynamic/omniauth-facebook).
39
+
40
+ ```ruby
41
+ <%= link_to "Sign In w/ Facebook", FacebookDialog::OmniAuth.dialog.url %>
42
+ ```
43
+
44
+ *NOTE*: omniauth-facebook must be loaded prior to facebook_dialog for this to work.
45
+
46
+ *NOTE*: You must set OmniAuth.config.full_host or a redirect_uri in each invocation for this to work properly. In order to obtain the data we need without coupling to request context, we do some neat/hacky things with Rack.
47
+
48
+ In an initializer like config/initializers/omniauth.rb:
49
+
50
+ ```ruby
51
+ OmniAuth.full_host = "http://example.com"
52
+ ```
53
+
54
+ Alternatively, we provide you
55
+
56
+ ```ruby
57
+ <%= link_to "Sign In With Facebook", FacebookDialog::OmniAuth.dialog({
58
+ display: "popup",
59
+ redirect_uri: fb_callback_url
60
+ }).url%>
61
+ ```
62
+
63
+ fb_callback_url is a convenience method provided by facebook_dialog
64
+
65
+ Without one of these approaches, your OAuth dialog will not work!
66
+
67
+ Per Facebook's documentation "The OAuth Dialog should not be called directly from the JavaScript SDK. Rather, use FB.login for this purpose." Thus, this helper should only be used for server side implementations to start.
@@ -24,5 +24,6 @@ Gem::Specification.new do |gem|
24
24
  gem.add_development_dependency "rspec"
25
25
  gem.add_development_dependency "guard-rspec"
26
26
  gem.add_development_dependency "mocha"
27
+ gem.add_development_dependency "omniauth-facebook"
27
28
  end
28
29
 
@@ -6,6 +6,10 @@ module FacebookDialog
6
6
  super
7
7
  @options[:client_id] = @options.delete(:app_id)
8
8
  end
9
+
10
+ def scope
11
+ @options[:scope]
12
+ end
9
13
  end
10
14
  end
11
15
 
@@ -0,0 +1,33 @@
1
+ module FacebookDialog
2
+ module OmniAuth
3
+ def self.dialog(additional_options = {})
4
+ options = authorize_params.merge(additional_options)
5
+ options[:redirect_uri] ||= hacked_app.callback_url
6
+ FacebookDialog::Oauth.new(options.merge(authorize_params))
7
+ end
8
+
9
+ protected
10
+ def self.authorize_params
11
+ hacked_app.authorize_params.merge(hacked_app.client.auth_code.authorize_params)
12
+ end
13
+
14
+ def self.hacked_app
15
+ @hacked_app ||= OmniAuthHack.new(MockRack.new)
16
+ end
17
+
18
+ class MockRack
19
+ def call(env)
20
+ [200, {}, []]
21
+ end
22
+ end
23
+
24
+ class OmniAuthHack < ::OmniAuth::Strategies::Facebook
25
+ option :name, "facebook"
26
+ protected
27
+ def request
28
+ @env = Rack::MockRequest.env_for("", {"rack.session" => {}})
29
+ super
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,11 @@
1
+ module FacebookDialog
2
+ module OmniAuthHelper
3
+ #this is a convenience method we add to decouple dialogs from controller/request context
4
+ def fb_callback_url
5
+ uri = URI.parse(request.url.gsub(/\?.*$/,''))
6
+ uri.path = "/auth/facebook/callback"
7
+ uri.query = nil
8
+ uri.to_s
9
+ end
10
+ end
11
+ end
@@ -4,6 +4,10 @@ module FacebookDialog
4
4
  class Railtie < Rails::Railtie
5
5
  ActiveSupport.on_load(:action_controller) do
6
6
  helper FacebookDialog::ScriptHelper
7
+ if FacebookDialog.omniauth_enabled?
8
+ require "facebook_dialog/omni_auth_helper"
9
+ helper FacebookDialog::OmniAuthHelper
10
+ end
7
11
  end
8
12
  end
9
13
  end
@@ -1,16 +1,17 @@
1
1
  module FacebookDialog
2
2
  module ScriptHelper
3
- def facebook_js
3
+ def fb_js
4
4
  content_tag(:div, "", id: "fb-root") +
5
5
  javascript_include_tag('http://connect.facebook.net/en_US/all.js')
6
6
  end
7
7
 
8
- def fb_init_js
9
- "FB.init({
10
- appId: '#{FacebookDialog.api_key}',
8
+ def fb_init_js(options = {})
9
+ default_options = {
10
+ appId: FacebookDialog.api_key,
11
11
  status: true,
12
12
  cookies: true
13
- });".html_safe
13
+ }
14
+ "FB.init(#{options.merge(default_options).to_json.html_safe});".html_safe
14
15
  end
15
16
  end
16
17
  end
@@ -1,4 +1,4 @@
1
1
  module FacebookDialog
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
4
4
 
@@ -32,10 +32,15 @@ module FacebookDialog
32
32
  ]
33
33
  end
34
34
 
35
+ def self.omniauth_enabled?
36
+ defined?(::OmniAuth) && defined?(::OmniAuth::Strategies::Facebook)
37
+ end
38
+
35
39
 
36
40
  class ResourceNameNotDefined < Exception; end;
37
41
  class InvalidDisplay < Exception; end;
38
42
  end
39
43
 
44
+ require "facebook_dialog/omni_auth" if FacebookDialog.omniauth_enabled?
40
45
  require "facebook_dialog/railtie" if defined?(Rails)
41
46
 
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe FacebookDialog::OmniAuth do
4
+ before do
5
+ FacebookDialog.api_key = "blah"
6
+ end
7
+
8
+ subject { FacebookDialog::OmniAuth.dialog }
9
+
10
+ its(:url) { should include "client_id=#{Rack::Utils.escape(FacebookDialog.api_key)}" }
11
+ its(:url) { should match(/redirect_uri=[^\&]/) }
12
+ end
13
+
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'rspec'
2
+ require 'omniauth-facebook'
2
3
  require 'facebook_dialog'
3
4
  require 'mocha'
4
5
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facebook_dialog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-20 00:00:00.000000000Z
12
+ date: 2011-12-29 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
16
- requirement: &2156417100 !ruby/object:Gem::Requirement
16
+ requirement: &2151909900 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2156417100
24
+ version_requirements: *2151909900
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activemodel
27
- requirement: &2156416260 !ruby/object:Gem::Requirement
27
+ requirement: &2151908580 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2156416260
35
+ version_requirements: *2151908580
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: activesupport
38
- requirement: &2156415640 !ruby/object:Gem::Requirement
38
+ requirement: &2151907580 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2156415640
46
+ version_requirements: *2151907580
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: configatron
49
- requirement: &2156414700 !ruby/object:Gem::Requirement
49
+ requirement: &2151905200 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *2156414700
57
+ version_requirements: *2151905200
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rake
60
- requirement: &2156414160 !ruby/object:Gem::Requirement
60
+ requirement: &2151903900 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *2156414160
68
+ version_requirements: *2151903900
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
- requirement: &2156413280 !ruby/object:Gem::Requirement
71
+ requirement: &2151902860 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2156413280
79
+ version_requirements: *2151902860
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: guard-rspec
82
- requirement: &2156412560 !ruby/object:Gem::Requirement
82
+ requirement: &2151901720 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *2156412560
90
+ version_requirements: *2151901720
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: mocha
93
- requirement: &2156411920 !ruby/object:Gem::Requirement
93
+ requirement: &2151897040 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,7 +98,18 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *2156411920
101
+ version_requirements: *2151897040
102
+ - !ruby/object:Gem::Dependency
103
+ name: omniauth-facebook
104
+ requirement: &2151896280 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: *2151896280
102
113
  description: A utility for building progressively enhanced Facebook dialogs
103
114
  email:
104
115
  - dpickett@enlightsolutions.com
@@ -119,6 +130,8 @@ files:
119
130
  - lib/facebook_dialog/dialog.rb
120
131
  - lib/facebook_dialog/feed.rb
121
132
  - lib/facebook_dialog/oauth.rb
133
+ - lib/facebook_dialog/omni_auth.rb
134
+ - lib/facebook_dialog/omni_auth_helper.rb
122
135
  - lib/facebook_dialog/option_serialization.rb
123
136
  - lib/facebook_dialog/railtie.rb
124
137
  - lib/facebook_dialog/script_helper.rb
@@ -128,6 +141,7 @@ files:
128
141
  - spec/facebook_dialog/dialog_spec.rb
129
142
  - spec/facebook_dialog/feed_spec.rb
130
143
  - spec/facebook_dialog/oauth_spec.rb
144
+ - spec/facebook_dialog/omni_auth_spec.rb
131
145
  - spec/facebook_dialog/option_serialization_spec.rb
132
146
  - spec/facebook_dialog/validators/display_spec.rb
133
147
  - spec/spec_helper.rb
@@ -145,7 +159,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
145
159
  version: '0'
146
160
  segments:
147
161
  - 0
148
- hash: -1035554407844364285
162
+ hash: -145623593344422603
149
163
  required_rubygems_version: !ruby/object:Gem::Requirement
150
164
  none: false
151
165
  requirements:
@@ -154,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
168
  version: '0'
155
169
  segments:
156
170
  - 0
157
- hash: -1035554407844364285
171
+ hash: -145623593344422603
158
172
  requirements: []
159
173
  rubyforge_project:
160
174
  rubygems_version: 1.8.6
@@ -165,6 +179,7 @@ test_files:
165
179
  - spec/facebook_dialog/dialog_spec.rb
166
180
  - spec/facebook_dialog/feed_spec.rb
167
181
  - spec/facebook_dialog/oauth_spec.rb
182
+ - spec/facebook_dialog/omni_auth_spec.rb
168
183
  - spec/facebook_dialog/option_serialization_spec.rb
169
184
  - spec/facebook_dialog/validators/display_spec.rb
170
185
  - spec/spec_helper.rb