doesfacebook 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +20 -0
- data/README.rdoc +85 -0
- data/app/helpers/does_facebook_helper.rb +47 -0
- data/config/doesfacebook.yml.example +25 -0
- data/lib/doesfacebook.rb +49 -0
- data/lib/doesfacebook/config.rb +24 -0
- data/lib/doesfacebook/controls.rb +24 -0
- data/lib/doesfacebook/filters.rb +56 -0
- data/lib/doesfacebook/session.rb +9 -0
- metadata +86 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
Copyright (C) 2011 by Awexome Labs, LLC
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
6
|
+
in the Software without restriction, including without limitation the rights
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
9
|
+
furnished to do so, subject to the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be included in
|
12
|
+
all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
= DoesFacebook
|
2
|
+
|
3
|
+
The Awexome Labs rails plugin for handling Facebook application credentials and authentication.
|
4
|
+
Also provides helpers and convenience methods for canvas applications.
|
5
|
+
|
6
|
+
You may also be interested in accessing content on the Facebook Open Graph. For that, consider
|
7
|
+
this gem's brother from the same mother, DoesOpenGraph
|
8
|
+
|
9
|
+
|
10
|
+
== Installation
|
11
|
+
|
12
|
+
To install the gem, do the usual:
|
13
|
+
|
14
|
+
gem install doesfacebook
|
15
|
+
|
16
|
+
If you plan on using DoesFacebook in a project with a Gemfile:
|
17
|
+
|
18
|
+
gem "doesfacebook", ">=0.3.2"
|
19
|
+
|
20
|
+
You can live on the edge, too, if you like:
|
21
|
+
|
22
|
+
gem "doesfacebook", ">=0.3.2", :git=>"git://github.com/awexome/doesfacebook.git"
|
23
|
+
|
24
|
+
|
25
|
+
== Configuration
|
26
|
+
|
27
|
+
You configure DoesFacebook in much the same way you'll configure other Facebook integration
|
28
|
+
helper plugins. Add a "doesfacebook.yml" file to you config/ directory with the a config for
|
29
|
+
each environment in the following format:
|
30
|
+
|
31
|
+
development:
|
32
|
+
app_id: 1234567890
|
33
|
+
api_key: 1234567890abcdefghijklmnopqrsttuv
|
34
|
+
secret_key: 1234567890abcdefghijklmnopqrsttuv
|
35
|
+
canvas_name: your_canvas_name
|
36
|
+
callback_url: http://your.dev.server.com/and/path
|
37
|
+
|
38
|
+
These parameters relate to settings in the Facebook Developers application configuration panel,
|
39
|
+
and should be easy to copy and paste in as you need for each application.
|
40
|
+
|
41
|
+
|
42
|
+
== Usage
|
43
|
+
|
44
|
+
To parse requests, add the following declaration to your controller:
|
45
|
+
|
46
|
+
does_facebook
|
47
|
+
|
48
|
+
Now, with each incoming request, DoesFacebook will parse the signed_request_parameter against your
|
49
|
+
application's keys, as described at http://developers.facebook.com/docs/authentication/signed_request
|
50
|
+
|
51
|
+
This allows your application to verify requests from Facebook, properly handle Facebook POSTs via
|
52
|
+
canvas and within page tabs.
|
53
|
+
|
54
|
+
You also get helpers for your views that will make many aspects of developing on the Facebook platform
|
55
|
+
easier:
|
56
|
+
|
57
|
+
app_id
|
58
|
+
=> The current application's id, parsed from doesfacebook.yml
|
59
|
+
|
60
|
+
app_callback_url
|
61
|
+
=> The current application's callback URL, parsed from doesfacebook.yml
|
62
|
+
|
63
|
+
app_canvas_name
|
64
|
+
=> The current application's canvas shortname, parsed from doesfacebook.yml
|
65
|
+
|
66
|
+
app_canvas_url
|
67
|
+
=> The full URL to the application canvas (e.g., http://apps.facebook.com/your_canvas_name)
|
68
|
+
|
69
|
+
url_for_canvas(url_opts={})
|
70
|
+
=> Like the standard url_for, but ensures the endpoint is in the Facebook canvas
|
71
|
+
|
72
|
+
link_to_canvas(text, url_opts={}, html_opts={})
|
73
|
+
=> Use as you would the regular link_to helper; generates links to the canvas and properly
|
74
|
+
targets the link to "_top"
|
75
|
+
|
76
|
+
Other helpers and useful shortcuts being added regularly.
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
== Copyright
|
83
|
+
|
84
|
+
Copyright 2011 Awexome Labs, LLC http://awexomelabs.com
|
85
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# AWEXOME LABS
|
2
|
+
# DoesFacebook
|
3
|
+
#
|
4
|
+
# DoesFacebookHelper - add helpers to
|
5
|
+
|
6
|
+
module DoesFacebookHelper
|
7
|
+
|
8
|
+
# Return the current application id to the view
|
9
|
+
def app_id
|
10
|
+
controller.send(:facebook_config)[:app_id]
|
11
|
+
end
|
12
|
+
|
13
|
+
# Return the current app callback URL
|
14
|
+
def app_callback_url
|
15
|
+
controller.send(:facebook_config)[:callback_url]
|
16
|
+
end
|
17
|
+
|
18
|
+
# Return the current app canvas name:
|
19
|
+
def app_canvas_name
|
20
|
+
controller.send(:facebook_config)[:canvas_name]
|
21
|
+
end
|
22
|
+
|
23
|
+
# Return the full canvas URL:
|
24
|
+
def app_canvas_url
|
25
|
+
"http://apps.facebook.com/#{controller.send(:facebook_config)[:canvas_name]}"
|
26
|
+
end
|
27
|
+
|
28
|
+
# Generate a URL that points within the Facebook canvas
|
29
|
+
def url_for_canvas(url_opts={})
|
30
|
+
canvas_name = controller.send(:facebook_config)["canvas_name"]
|
31
|
+
canvas_root = File.join("http://apps.facebook.com", canvas_name)
|
32
|
+
if url_opts.is_a?(Hash)
|
33
|
+
return File.join(canvas_root, url_for(url_opts))
|
34
|
+
elsif url_opts.include?("://")
|
35
|
+
return url_opts
|
36
|
+
else
|
37
|
+
return File.join(canvas_root, url_opts)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Generate a link that stays within the Facebook canvas
|
42
|
+
def link_to_canvas(text, url_opts={}, html_opts={})
|
43
|
+
url = url_for_canvas(url_opts)
|
44
|
+
content_tag("a", text, html_opts.merge(:rel=>"canvas", :href=>url, :target=>"_top"), false)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# AWEXOME LABS
|
2
|
+
# Beyond12
|
3
|
+
#
|
4
|
+
# Example Facebook Configuration File
|
5
|
+
|
6
|
+
development:
|
7
|
+
app_id: 1234567890
|
8
|
+
api_key: 1234567890abcdefghijklmnopqrsttuv
|
9
|
+
secret_key: 1234567890abcdefghijklmnopqrsttuv
|
10
|
+
canvas_name: your_canvas_name
|
11
|
+
callback_url: http://your.dev.server.com/and/path
|
12
|
+
|
13
|
+
staging:
|
14
|
+
app_id: 1234567890
|
15
|
+
api_key: 1234567890abcdefghijklmnopqrsttuv
|
16
|
+
secret_key: 1234567890abcdefghijklmnopqrsttuv
|
17
|
+
canvas_name: your_canvas_name
|
18
|
+
callback_url: http://your.dev.server.com/and/path
|
19
|
+
|
20
|
+
production:
|
21
|
+
app_id: 1234567890
|
22
|
+
api_key: 1234567890abcdefghijklmnopqrsttuv
|
23
|
+
secret_key: 1234567890abcdefghijklmnopqrsttuv
|
24
|
+
canvas_name: your_canvas_name
|
25
|
+
callback_url: http://your.dev.server.com/and/path
|
data/lib/doesfacebook.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# AWEXOME LABS
|
2
|
+
# DoesFacebook
|
3
|
+
|
4
|
+
require 'doesfacebook'
|
5
|
+
require 'rails'
|
6
|
+
require 'action_controller'
|
7
|
+
|
8
|
+
require 'doesfacebook/config'
|
9
|
+
require 'doesfacebook/filters'
|
10
|
+
require 'doesfacebook/controls'
|
11
|
+
require 'doesfacebook/session'
|
12
|
+
|
13
|
+
module DoesFacebook
|
14
|
+
|
15
|
+
# Create a Rails Engine
|
16
|
+
class Engine < Rails::Engine
|
17
|
+
# engine_name :doesfacebook
|
18
|
+
end
|
19
|
+
|
20
|
+
# Return the current working version of DoFacebook from VERSION file:
|
21
|
+
def self.version
|
22
|
+
@@version ||= File.open(File.join(File.dirname(__FILE__), "..", "VERSION"), "r").read
|
23
|
+
end
|
24
|
+
|
25
|
+
end # DoesFacebook
|
26
|
+
|
27
|
+
|
28
|
+
module ActionController
|
29
|
+
class Base
|
30
|
+
|
31
|
+
# Call this method within your controller to parse configuration and enabled
|
32
|
+
# session validation and parsing
|
33
|
+
def self.does_facebook
|
34
|
+
self.instance_eval do
|
35
|
+
include DoesFacebook::Config
|
36
|
+
include DoesFacebook::Controls
|
37
|
+
include DoesFacebook::Filters
|
38
|
+
prepend_before_filter :parse_signed_request
|
39
|
+
prepend_before_filter :validate_signed_request
|
40
|
+
helper :does_facebook
|
41
|
+
|
42
|
+
protected
|
43
|
+
attr_reader :fbparams
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end # ActionController
|
49
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# AWEXOME LABS
|
2
|
+
# DoesFacebook Config
|
3
|
+
|
4
|
+
module DoesFacebook
|
5
|
+
module Config
|
6
|
+
|
7
|
+
protected
|
8
|
+
|
9
|
+
# Access the Facebook-specific configuration for the given environment:
|
10
|
+
def facebook_config
|
11
|
+
@@facebook_config ||= HashWithIndifferentAccess.new(all_facebook_config[Rails.env])
|
12
|
+
end
|
13
|
+
|
14
|
+
# Load configuration from YAML file for all environments:
|
15
|
+
def all_facebook_config
|
16
|
+
config_file = File.join(Rails.root, "config", "doesfacebook.yml")
|
17
|
+
if File.exist?(config_file)
|
18
|
+
return @@all_facebook_config ||= YAML.load(File.open( config_file ))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end # DoesFacebook
|
24
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# AWEXOME LABS
|
2
|
+
# DoesFacebook
|
3
|
+
#
|
4
|
+
# Controls - convenience methods for injection into controllers
|
5
|
+
|
6
|
+
module DoesFacebook
|
7
|
+
module Controls
|
8
|
+
|
9
|
+
# Exception Classes:
|
10
|
+
class MalformedUrlOptions < Exception; end
|
11
|
+
|
12
|
+
|
13
|
+
protected
|
14
|
+
|
15
|
+
# Mechanism for redirecting within the Facebook canvas:
|
16
|
+
def redirect_to_canvas(opts={})
|
17
|
+
raise MalformedUrlOptions.new("Options passed to `redirect_to_canvas` must be a URL options Hash") unless opts.is_a?(Hash)
|
18
|
+
dest = File.join("http://apps.facebook.com/", facebook_config[:canvas_name], url_for(opts.merge(:only_path=>true)))
|
19
|
+
logger.info "Canvas Redirect to #{opts.inspect}=>#{dest}"
|
20
|
+
redirect_to dest
|
21
|
+
end
|
22
|
+
|
23
|
+
end # Controls
|
24
|
+
end # DoesFacebook
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# AWEXOME LABS
|
2
|
+
# DoesFacebook
|
3
|
+
#
|
4
|
+
# Filters - before and after filters for controller that process Facebook behavior
|
5
|
+
|
6
|
+
module DoesFacebook
|
7
|
+
module Filters
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
# Ensures, using configuration options, that the request was signed by Facebook
|
12
|
+
def validate_signed_request
|
13
|
+
if request_parameter = request.params["signed_request"]
|
14
|
+
if app_secret = facebook_config["secret_key"]
|
15
|
+
encoded_signature, encoded_data = request_parameter.split(".")
|
16
|
+
decoded_signature = base64_url_decode(encoded_signature)
|
17
|
+
digested = OpenSSL::HMAC.digest("sha256", app_secret, encoded_data)
|
18
|
+
valid = (digested == decoded_signature)
|
19
|
+
if valid
|
20
|
+
logger.info "DoFacebook: Signed Request Valid."
|
21
|
+
else
|
22
|
+
logger.info "DoFacebook: Invalid Signed Request. Ensure request from Facebook."
|
23
|
+
raise "DoFacebook: Invalid Signed Request. Ensure request from Facebook."
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
# If present, parses data from the signed request and inserts it into the fbparams
|
31
|
+
# object for use during requests
|
32
|
+
def parse_signed_request
|
33
|
+
if request_parameter = request.params["signed_request"]
|
34
|
+
encoded_signature, encoded_data = request_parameter.split(".")
|
35
|
+
decoded_signature = base64_url_decode(encoded_signature)
|
36
|
+
decoded_data = base64_url_decode(encoded_data)
|
37
|
+
@fbparams = HashWithIndifferentAccess.new(JSON.parse(decoded_data).merge({
|
38
|
+
"signature"=>encoded_signature,
|
39
|
+
"data"=>encoded_data
|
40
|
+
}))
|
41
|
+
logger.info " Facebook Parameters: #{fbparams.inspect}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
# Base64 URL Decode method
|
50
|
+
# see http://developers.facebook.com/docs/authentication/canvas
|
51
|
+
def base64_url_decode(str)
|
52
|
+
"#{str}==".tr("-_", "+/").unpack("m")[0]
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end # DoesFacebook
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: doesfacebook
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.3.3
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- mccolin
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-02-12 00:00:00 -05:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: bundler
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.0.0
|
24
|
+
type: :development
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: jeweler
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.5.1
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *id002
|
38
|
+
description: Paper-thin Facebook validation and signed request parsing Rails plugin
|
39
|
+
email: info@awexomelabs.com
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files:
|
45
|
+
- LICENSE
|
46
|
+
- README.rdoc
|
47
|
+
files:
|
48
|
+
- app/helpers/does_facebook_helper.rb
|
49
|
+
- config/doesfacebook.yml.example
|
50
|
+
- lib/doesfacebook.rb
|
51
|
+
- lib/doesfacebook/config.rb
|
52
|
+
- lib/doesfacebook/controls.rb
|
53
|
+
- lib/doesfacebook/filters.rb
|
54
|
+
- lib/doesfacebook/session.rb
|
55
|
+
- LICENSE
|
56
|
+
- README.rdoc
|
57
|
+
has_rdoc: true
|
58
|
+
homepage: http://awexomelabs.com/
|
59
|
+
licenses: []
|
60
|
+
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: "0"
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.5.2
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Paper-thin Facebook validation and signed request parsing Rails plugin
|
85
|
+
test_files: []
|
86
|
+
|