mini_fb 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +7 -7
- data/lib/mini_fb.rb +32 -25
- metadata +26 -4
data/README.markdown
CHANGED
@@ -24,7 +24,7 @@ Installation
|
|
24
24
|
Facebook Graph API
|
25
25
|
==================
|
26
26
|
|
27
|
-
For an overview of what this is all about, see http://developers.facebook.com/docs/api
|
27
|
+
For an overview of what this is all about, see <http://developers.facebook.com/docs/api>.
|
28
28
|
|
29
29
|
Authentication
|
30
30
|
--------------
|
@@ -57,7 +57,8 @@ It's very simple:
|
|
57
57
|
@response_hash = MiniFB.get(@access_token, @id, :type=>@type)
|
58
58
|
# @response_hash is a hash, but also allows object like syntax for instance, the following is true:
|
59
59
|
@response_hash["user"] == @response_hash.user
|
60
|
-
|
60
|
+
|
61
|
+
See <http://developers.facebook.com/docs/api> for the available types.
|
61
62
|
|
62
63
|
Posting Data to Facebook
|
63
64
|
------------------------
|
@@ -161,12 +162,11 @@ Then add the following script to the page where you put the login button so it l
|
|
161
162
|
Define an fb_connect method in your login/sessions controller like so:
|
162
163
|
|
163
164
|
def fb_connect
|
164
|
-
@
|
165
|
-
@
|
166
|
-
puts "
|
167
|
-
puts "session=#{@fb_session}"
|
165
|
+
@fb_info = MiniFB.parse_cookie_information(FB_APP_ID, cookies) # some users may have to use their API rather than the app. ID.
|
166
|
+
puts "uid=#{@fb_info['uid']}"
|
167
|
+
puts "session=#{@fb_info['session_key']}"
|
168
168
|
|
169
|
-
if MiniFB.
|
169
|
+
if MiniFB.verify_cookie_signature(FB_APP_ID, FB_SECRET, cookies)
|
170
170
|
# And here you would create the user if it doesn't already exist, then redirect them to wherever you want.
|
171
171
|
else
|
172
172
|
# The cookies may have been modified as the signature does not match
|
data/lib/mini_fb.rb
CHANGED
@@ -255,35 +255,37 @@ module MiniFB
|
|
255
255
|
end
|
256
256
|
return false
|
257
257
|
end
|
258
|
+
|
259
|
+
# Parses cookies in order to extract the facebook cookie and parse it into a useable hash
|
260
|
+
#
|
261
|
+
# options:
|
262
|
+
# * app_id - the connect applications app_id (some users may find they have to use their facebook API key)
|
263
|
+
# * secret - the connect application secret
|
264
|
+
# * cookies - the cookies given by facebook - it is ok to just pass all of the cookies, the method will do the filtering for you.
|
265
|
+
def MiniFB.parse_cookie_information(app_id, cookies)
|
266
|
+
return nil if cookies["fbs_#{app_id}"].nil?
|
267
|
+
Hash[*cookies["fbs_#{app_id}"].split('&').map{|v| v.gsub('"', '').split('=', 2) }.flatten]
|
268
|
+
end
|
258
269
|
|
259
270
|
# Validates that the cookies sent by the user are those that were set by facebook. Since your
|
260
271
|
# secret is only known by you and facebook it is used to sign all of the cookies set.
|
261
272
|
#
|
262
273
|
# options:
|
263
|
-
# *
|
274
|
+
# * app_id - the connect applications app_id (some users may find they have to use their facebook API key)
|
264
275
|
# * secret - the connect application secret
|
265
276
|
# * cookies - the cookies given by facebook - it is ok to just pass all of the cookies, the method will do the filtering for you.
|
277
|
+
def MiniFB.verify_cookie_signature(app_id, secret, cookies)
|
278
|
+
fb_keys = MiniFB.parse_cookie_information(app_id, cookies)
|
279
|
+
return false if fb_keys.nil?
|
280
|
+
|
281
|
+
signature = fb_keys.delete('sig')
|
282
|
+
return signature == Digest::MD5.hexdigest(fb_keys.map{|k,v| "#{k}=#{v}"}.sort.join + secret)
|
283
|
+
end
|
284
|
+
|
285
|
+
# <b>DEPRECATED:</b> Please use <tt>verify_cookie_signature</tt> instead.
|
266
286
|
def MiniFB.verify_connect_signature(api_key, secret, cookies)
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
unsigned = Hash.new
|
271
|
-
signed = Hash.new
|
272
|
-
|
273
|
-
cookies.each do |k, v|
|
274
|
-
if k =~ /^#{api_key}_(.*)/ then
|
275
|
-
signed[$1] = v
|
276
|
-
else
|
277
|
-
unsigned[k] = v
|
278
|
-
end
|
279
|
-
end
|
280
|
-
|
281
|
-
arg_string = String.new
|
282
|
-
signed.sort.each {|kv| arg_string << kv[0] << "=" << kv[1] }
|
283
|
-
if Digest::MD5.hexdigest(arg_string + secret) == signature
|
284
|
-
return true
|
285
|
-
end
|
286
|
-
return false
|
287
|
+
warn "DEPRECATION WARNING: 'verify_connect_signature' has been renamed to 'verify_cookie_signature' as Facebook no longer calls this 'connect'"
|
288
|
+
MiniFB.verify_cookie_signature(api_key, secret, cookies)
|
287
289
|
end
|
288
290
|
|
289
291
|
# Returns the login/add app url for your application.
|
@@ -308,7 +310,9 @@ module MiniFB
|
|
308
310
|
oauth_url = "#{graph_base}oauth/authorize"
|
309
311
|
oauth_url << "?client_id=#{app_id}"
|
310
312
|
oauth_url << "&redirect_uri=#{URI.escape(redirect_uri)}"
|
311
|
-
oauth_url << "&scope=#{options[:scope]}" if options[:scope]
|
313
|
+
# oauth_url << "&scope=#{options[:scope]}" if options[:scope]
|
314
|
+
oauth_url << ("&" + options.each.map { |k,v| "%s=%s" % [k, v] }.join('&')) unless options.empty?
|
315
|
+
oauth_url
|
312
316
|
end
|
313
317
|
|
314
318
|
# returns a hash with one value being 'access_token', the other being 'expires'
|
@@ -347,6 +351,9 @@ module MiniFB
|
|
347
351
|
if options[:method] == :post
|
348
352
|
resp = RestClient.post url, options[:params]
|
349
353
|
else
|
354
|
+
if options[:params] && options[:params].size > 0
|
355
|
+
url += '?' + options[:params].each.map {|k,v| "%s=%s" % [k,v]}.join('&')
|
356
|
+
end
|
350
357
|
resp = RestClient.get url
|
351
358
|
end
|
352
359
|
|
@@ -404,9 +411,9 @@ module MiniFB
|
|
404
411
|
# Uses new Oauth 2 authentication against old Facebook REST API
|
405
412
|
def self.rest(access_token, api_method, options={})
|
406
413
|
url = "https://api.facebook.com/method/#{api_method}"
|
407
|
-
options[:
|
408
|
-
options[:format] = "json"
|
409
|
-
method = (options[:method]) ? options[:method]: :get
|
414
|
+
options[:access_token] = access_token
|
415
|
+
options[:format] = "json"
|
416
|
+
method = (options[:method]) ? options[:method] : :get
|
410
417
|
options.delete(:method) if options[:method]
|
411
418
|
return fetch(url, :params => options, :method => method)
|
412
419
|
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mini_fb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 31
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 1
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
version: 1.0.
|
9
|
+
- 4
|
10
|
+
version: 1.0.4
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Travis Reeder
|
@@ -15,21 +16,37 @@ autorequire:
|
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date: 2010-
|
19
|
+
date: 2010-06-04 00:00:00 -07:00
|
19
20
|
default_executable:
|
20
21
|
dependencies:
|
21
22
|
- !ruby/object:Gem::Dependency
|
22
23
|
name: rest-client
|
23
24
|
prerelease: false
|
24
25
|
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
25
27
|
requirements:
|
26
28
|
- - ">="
|
27
29
|
- !ruby/object:Gem::Version
|
30
|
+
hash: 3
|
28
31
|
segments:
|
29
32
|
- 0
|
30
33
|
version: "0"
|
31
34
|
type: :runtime
|
32
35
|
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: hashie
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
version: "0"
|
48
|
+
type: :runtime
|
49
|
+
version_requirements: *id002
|
33
50
|
description: Tiny facebook library
|
34
51
|
email: travis@appoxy.com
|
35
52
|
executables: []
|
@@ -41,6 +58,7 @@ extra_rdoc_files:
|
|
41
58
|
files:
|
42
59
|
- lib/mini_fb.rb
|
43
60
|
- README.markdown
|
61
|
+
- test/test_mini_fb.rb
|
44
62
|
has_rdoc: true
|
45
63
|
homepage: http://github.com/appoxy/mini_fb
|
46
64
|
licenses: []
|
@@ -51,23 +69,27 @@ rdoc_options:
|
|
51
69
|
require_paths:
|
52
70
|
- lib
|
53
71
|
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
54
73
|
requirements:
|
55
74
|
- - ">="
|
56
75
|
- !ruby/object:Gem::Version
|
76
|
+
hash: 3
|
57
77
|
segments:
|
58
78
|
- 0
|
59
79
|
version: "0"
|
60
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
61
82
|
requirements:
|
62
83
|
- - ">="
|
63
84
|
- !ruby/object:Gem::Version
|
85
|
+
hash: 3
|
64
86
|
segments:
|
65
87
|
- 0
|
66
88
|
version: "0"
|
67
89
|
requirements: []
|
68
90
|
|
69
91
|
rubyforge_project:
|
70
|
-
rubygems_version: 1.3.
|
92
|
+
rubygems_version: 1.3.7
|
71
93
|
signing_key:
|
72
94
|
specification_version: 3
|
73
95
|
summary: Tiny facebook library
|