rfacebook 0.8.8 → 0.8.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -30,9 +30,7 @@
30
30
  require "rfacebook_on_rails/view_extensions"
31
31
  require "rfacebook_on_rails/controller_extensions"
32
32
  require "rfacebook_on_rails/model_extensions"
33
-
34
- require "digest/md5"
35
- require "cgi"
33
+ require "rfacebook_on_rails/session_extensions"
36
34
 
37
35
  module RFacebook
38
36
  module Rails
@@ -94,7 +92,7 @@ end
94
92
  FACEBOOK["canvas_path"] = ensureLeadingAndTrailingSlashesForPath(FACEBOOK["canvas_path"])
95
93
  FACEBOOK["callback_path"] = ensureLeadingAndTrailingSlashesForPath(FACEBOOK["callback_path"])
96
94
 
97
- # inject methods
95
+ # inject methods to Rails MVC classes
98
96
  ActionView::Base.send(:include, RFacebook::Rails::ViewExtensions)
99
97
  ActionView::Base.send(:include, RFacebook::Rails::Plugin::ViewExtensions)
100
98
 
@@ -104,99 +102,22 @@ ActionController::Base.send(:include, RFacebook::Rails::Plugin::ControllerExtens
104
102
  ActiveRecord::Base.send(:include, RFacebook::Rails::ModelExtensions)
105
103
  ActiveRecord::Base.send(:include, RFacebook::Rails::Plugin::ModelExtensions)
106
104
 
107
-
108
- class CGI::Session
109
-
110
- alias :initialize__ALIASED :initialize
111
- alias :new_session__ALIASED :new_session
112
-
113
- def using_facebook_session_id?
114
- return @using_fb_session_id
115
- end
116
-
117
- def force_to_be_new!
118
- @force_to_be_new = true
119
- end
120
-
121
- def new_session
122
- if @force_to_be_new
123
- return true
124
- else
125
- return new_session__ALIASED
126
- end
127
- end
128
-
129
- def initialize(request, options = {})
130
-
131
- # check the environment to find a Facebook sig_session_key (credit: Blake Carlson and David Troy)
132
- fbsessionId = nil
133
- ["RAW_POST_DATA", "QUERY_STRING", "HTTP_REFERER"].each do |tableSource|
134
- if request.env_table[tableSource]
135
- fbsessionId = CGI::parse(request.env_table[tableSource]).fetch('fb_sig_session_key'){[]}.first
136
- RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: checked #{tableSource} for Facebook session id and got [#{fbsessionId}]"
137
- end
138
- break if fbsessionId
139
- end
140
-
141
- # we only want to change the session_id if we got one from the fb_sig
142
- if fbsessionId
143
- options['session_id'] = Digest::MD5.hexdigest(fbsessionId)
144
- @using_facebook_session_id = true
145
- RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: using MD5 of Facebook session id [#{options['session_id']}] for the Rails session id}"
146
- end
147
-
148
- # now call the default Rails session initialization
149
- initialize__ALIASED(request, options)
150
- end
151
- end
152
-
153
- # NOTE: the following extensions allow ActiveRecord and PStore to use the Facebook session id for sessions
154
- # Their implementation warrants another look. Ideally, we'd like to solve this further up the chain
155
- # so that sessions will work no matter what store you have
156
- # ...maybe we could just override CGI::Session#session_id? what are the consequences?
157
-
158
- # TODO: support other session stores (like MemCached, etc.)
159
-
160
- # force ActiveRecordStore to use the Facebook session id (credit: Blake Carlson)
161
- class CGI
162
- class Session
163
- class ActiveRecordStore
105
+ # inject methods to patch Rails session containers
106
+ # TODO: document this as API so that everyone knows how to patch their own custom session container
107
+ module RFacebook::Rails::Toolbox
108
+ def self.patch_session_store_class(sessionStoreKlass)
109
+ sessionStoreKlass.send(:include, RFacebook::Rails::SessionStoreExtensions)
110
+ sessionStoreKlass.class_eval'
164
111
  alias :initialize__ALIASED :initialize
165
- def initialize(session, options = nil)
166
- initialize__ALIASED(session, options)
167
- session_id = session.session_id
168
- unless @session = ActiveRecord::Base.silence { @@session_class.find_by_session_id(session_id) }
169
- # FIXME: technically this might be a security problem, since an external browser can grab any unused session id they want
170
- @session = @@session_class.new(:session_id => session_id, :data => {})
171
- end
172
- end
173
- end
112
+ alias :initialize :initialize__RFACEBOOK
113
+ '
174
114
  end
175
115
  end
176
116
 
177
- # force PStore to use the Facebook session id
178
- class CGI
179
- class Session
180
- class PStore
181
- alias :initialize__ALIASED :initialize
182
- def initialize(session, options = nil)
183
- begin
184
- RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: inside PStore, with session_id: #{session.session_id}, new_session = #{session.new_session ? 'yes' : 'no'}"
185
- initialize__ALIASED(session, options)
186
- rescue Exception => e
187
- begin
188
- RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: failed to init PStore session, trying to make a new session"
189
- # FIXME: technically this might be a security problem, since an external browser can grab any unused session id they want
190
- if session.session_id
191
- session.force_to_be_new!
192
- end
193
- initialize__ALIASED(session, options)
194
- rescue Exception => e
195
- RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: failed to create a new PStore session falling back to default Rails behavior"
196
- raise e
197
- end
198
- end
199
- end
200
- end
201
- end
202
- end
117
+ # patch as many session stores as possible
118
+ RFacebook::Rails::Toolbox::patch_session_store_class(CGI::Session::PStore)
119
+ RFacebook::Rails::Toolbox::patch_session_store_class(CGI::Session::ActiveRecordStore)
120
+ RFacebook::Rails::Toolbox::patch_session_store_class(CGI::Session::DRbStore)
121
+ RFacebook::Rails::Toolbox::patch_session_store_class(CGI::Session::FileStore)
122
+ RFacebook::Rails::Toolbox::patch_session_store_class(CGI::Session::MemoryStore)
123
+ RFacebook::Rails::Toolbox::patch_session_store_class(CGI::Session::MemCacheStore)
@@ -0,0 +1,101 @@
1
+ # Copyright (c) 2007, Matt Pizzimenti (www.livelearncode.com)
2
+ # All rights reserved.
3
+ #
4
+ # Redistribution and use in source and binary forms, with or without modification,
5
+ # are permitted provided that the following conditions are met:
6
+ #
7
+ # Redistributions of source code must retain the above copyright notice,
8
+ # this list of conditions and the following disclaimer.
9
+ #
10
+ # Redistributions in binary form must reproduce the above copyright notice,
11
+ # this list of conditions and the following disclaimer in the documentation
12
+ # and/or other materials provided with the distribution.
13
+ #
14
+ # Neither the name of the original author nor the names of contributors
15
+ # may be used to endorse or promote products derived from this software
16
+ # without specific prior written permission.
17
+ #
18
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+ #
29
+
30
+ require "digest/md5"
31
+ require "cgi"
32
+
33
+ # patch up the CGI session module to use Facebook session keys when cookies aren't available
34
+ class CGI::Session
35
+
36
+ alias :initialize__ALIASED :initialize
37
+ alias :new_session__ALIASED :new_session
38
+
39
+ def using_facebook_session_id?
40
+ return @using_fb_session_id
41
+ end
42
+
43
+ def force_to_be_new!
44
+ @force_to_be_new = true
45
+ end
46
+
47
+ def new_session
48
+ if @force_to_be_new
49
+ return true
50
+ else
51
+ return new_session__ALIASED
52
+ end
53
+ end
54
+
55
+ def initialize(request, options = {})
56
+
57
+ # check the environment to find a Facebook sig_session_key (credit: Blake Carlson and David Troy)
58
+ fbsessionId = nil
59
+ ["RAW_POST_DATA", "QUERY_STRING", "HTTP_REFERER"].each do |tableSource|
60
+ if request.env_table[tableSource]
61
+ fbsessionId = CGI::parse(request.env_table[tableSource]).fetch('fb_sig_session_key'){[]}.first
62
+ RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: checked #{tableSource} for Facebook session id and got [#{fbsessionId}]"
63
+ end
64
+ break if fbsessionId
65
+ end
66
+
67
+ # we only want to change the session_id if we got one from the fb_sig
68
+ if fbsessionId
69
+ options['session_id'] = Digest::MD5.hexdigest(fbsessionId)
70
+ @using_facebook_session_id = true
71
+ RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: using MD5 of Facebook session id [#{options['session_id']}] for the Rails session id}"
72
+ end
73
+
74
+ # now call the default Rails session initialization
75
+ initialize__ALIASED(request, options)
76
+ end
77
+ end
78
+
79
+ # Module: SessionStoreExtensions
80
+ #
81
+ # Special initialize method that forces any session store to use the Facebook session
82
+ module RFacebook::Rails::SessionStoreExtensions
83
+ def initialize__RFACEBOOK(session, options, *extraParams)
84
+ begin
85
+ RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: inside #{self.class.to_s}, with session_id: #{session.session_id}, new_session = #{session.new_session ? 'yes' : 'no'}"
86
+ initialize__ALIASED(session, options, *extraParams)
87
+ rescue Exception => e
88
+ begin
89
+ RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: failed to init #{self.class.to_s} session, trying to make a new session"
90
+ # FIXME: technically this might be a security problem, since an external browser can grab any unused session id they want
91
+ if session.session_id
92
+ session.force_to_be_new!
93
+ end
94
+ initialize__ALIASED(session, options, *extraParams)
95
+ rescue Exception => e
96
+ RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: failed to create a new #{self.class.to_s} session falling back to default Rails behavior"
97
+ raise e
98
+ end
99
+ end
100
+ end
101
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.1
3
3
  specification_version: 1
4
4
  name: rfacebook
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.8.8
7
- date: 2007-08-17 00:00:00 -05:00
6
+ version: 0.8.9
7
+ date: 2007-08-18 00:00:00 -05:00
8
8
  summary: A Ruby interface to the Facebook API v1.0+ (F8 and beyond). Works with RFacebook on Rails plugin (see rfacebook.rubyforge.org).
9
9
  require_paths:
10
10
  - lib
@@ -38,6 +38,7 @@ files:
38
38
  - lib/rfacebook_on_rails/controller_extensions.rb
39
39
  - lib/rfacebook_on_rails/model_extensions.rb
40
40
  - lib/rfacebook_on_rails/plugin
41
+ - lib/rfacebook_on_rails/session_extensions.rb
41
42
  - lib/rfacebook_on_rails/status_manager.rb
42
43
  - lib/rfacebook_on_rails/templates
43
44
  - lib/rfacebook_on_rails/view_extensions.rb