thorsson_facebooker2 0.0.17 → 0.0.18
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/facebooker2/rails/controller.rb +25 -8
- metadata +2 -2
@@ -121,7 +121,7 @@ module Facebooker2
|
|
121
121
|
def fb_signed_request_json(encoded)
|
122
122
|
chars_to_add = 4-(encoded.size % 4)
|
123
123
|
encoded += ("=" * chars_to_add)
|
124
|
-
|
124
|
+
base64_url_decode(encoded)
|
125
125
|
end
|
126
126
|
|
127
127
|
def facebook_params
|
@@ -211,14 +211,10 @@ module Facebooker2
|
|
211
211
|
end
|
212
212
|
|
213
213
|
### Oauth2
|
214
|
-
def oauth2_current_facebook_user
|
215
|
-
oauth2_fetch_client_and_user
|
216
|
-
@_current_facebook_user
|
217
|
-
end
|
218
214
|
|
219
215
|
def oauth2_fetch_client_and_user
|
220
216
|
return if @_fb_user_fetched
|
221
|
-
|
217
|
+
oauth2_fetch_client_and_user_from_session || oauth2_fetch_client_and_user_from_cookie
|
222
218
|
@_fb_user_fetched = true
|
223
219
|
end
|
224
220
|
|
@@ -227,12 +223,33 @@ module Facebooker2
|
|
227
223
|
sig,payload = fb_cookie.split('.')
|
228
224
|
return unless fb_signed_request_sig_valid?(sig, payload)
|
229
225
|
data = JSON.parse(base64_url_decode(payload))
|
230
|
-
authenticator = Mogli::Authenticator.new(Facebooker2.app_id, Facebooker2.secret,
|
226
|
+
authenticator = Mogli::Authenticator.new(Facebooker2.app_id, Facebooker2.secret, '')
|
231
227
|
client = Mogli::Client.create_from_code_and_authenticator(data["code"], authenticator)
|
232
228
|
user = Mogli::User.new(:id=>data["user_id"])
|
229
|
+
oauth2_store_client_and_user_in_session(client,user)
|
233
230
|
fb_sign_in_user_and_client(user, client)
|
234
231
|
end
|
235
232
|
|
233
|
+
def oauth2_store_client_and_user_in_session(client, user)
|
234
|
+
session[:facebooker2_access_token] = client.access_token
|
235
|
+
session[:facebooker2_expiration] = client.expiration
|
236
|
+
session[:facebooker2_user_id] = user.id
|
237
|
+
end
|
238
|
+
|
239
|
+
def oauth2_fetch_client_and_user_from_session
|
240
|
+
if session[:facebooker2_access_token]
|
241
|
+
client = Mogli::Client.new(session[:facebooker2_access_token],session[:facebooker2_expiration])
|
242
|
+
user = Mogli::User.new(:id=>session[:facebooker2_user_id])
|
243
|
+
fb_sign_in_user_and_client(user, client)
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
def fb_logout!
|
248
|
+
session[:facebooker2_access_token]=nil
|
249
|
+
session[:facebooker2_expiration]=nil
|
250
|
+
session[:facebooker2_user_id]=nil
|
251
|
+
end
|
252
|
+
|
236
253
|
|
237
254
|
def base64_url_decode(encoded)
|
238
255
|
chars_to_add = 4-(encoded.size % 4)
|
@@ -242,4 +259,4 @@ module Facebooker2
|
|
242
259
|
|
243
260
|
end
|
244
261
|
end
|
245
|
-
end
|
262
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thorsson_facebooker2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.18
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-02-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mogli
|