facebook_registration 0.0.1

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/CHANGELOG.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ === 1.0 / 2011-02-01
2
+
3
+ * Initial Release.
data/README.rdoc ADDED
@@ -0,0 +1,48 @@
1
+ = Author
2
+ Veerasundaravel Thirugnanasundaram <veerasundaravel@gmail.com>
3
+
4
+ http://veerasundaravel.wordpress.com/2011/01/27/facebook-registration-plugin-in-rails/
5
+
6
+ = Synopsis
7
+ facebook_registration is a ruby library for displaying new Facebook Registration form and to parse to signed_request.
8
+ [http://developers.facebook.com/docs/plugins/registration]
9
+
10
+
11
+ === Installation
12
+ sudo gem install facebook_registration
13
+
14
+
15
+ === Using Gem in Rails
16
+ Once you installed the gem, you will need to configure your Facebook app in config/facebooker.yml.
17
+
18
+ You can copy facebooker.yml file which one is already available in this Root directory.
19
+
20
+
21
+ === Initializing Registration Form
22
+
23
+ <%= init_fb_registration %>
24
+
25
+
26
+ === Displaying Facebook Registration Form
27
+
28
+ <%= fb_registration_form("fields" =>"name,email,password", "redirect-uri"=>"http://localhost:3000/fb_registration", "width" =>830) %>
29
+
30
+ or
31
+
32
+ <%= fb_registration_form("fields" =>"[{'name':'name'}, {'name':'email'}, {'name':'password'}, {'name':'username','description':'Username','type':'text'}, {'name':'like', 'description':'You like this Website', 'type':'checkbox', 'default':'checked'}]", "fb_only"=>false, "redirect-uri"=>"http://localhost:3000/fb_registration", "width" =>830) %>
33
+
34
+ For more form field specifications refer this url:
35
+ http://developers.facebook.com/docs/plugins/registration#named_fields
36
+ http://developers.facebook.com/docs/plugins/registration#custom_fields
37
+
38
+
39
+ === Accessing profile informations
40
+ After displaying the form, you can register their details and they will be redirected to the url which one you have specified as redirect-uri.
41
+
42
+ So in our case, you can parse the Facebook profile informations in the action fb_registration as follows:
43
+
44
+ FacebookRegistration::SignedRequest.parse(params["signed_request"])
45
+
46
+ it will return the output as follows:
47
+
48
+ {"expires"=>1295964000, "registration_metadata"=>{"fields"=>"[{'name':'name'}, {'name':'location'}, {'name':'email'}]"}, "algorithm"=>"HMAC-SHA256", "registration"=>{"name"=>"Veera Sundaravel", "location"=>{"name"=>"Chennai, Tamil Nadu", "id"=>000000000}, "email"=>"veeraa2003@gmail.com"}, "user_id"=>"111111111", "oauth_token"=>"1212121212|2.9vzjKsatvaser_dStgereokRhg__.360220.1295964000-daff1|rsfsfasdfasdfasd", "user"=>{"country"=>"us", "locale"=>"en_US"}, "issued_at"=>1295956965}
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{facebook_registration}
5
+ s.version = "0.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Veerasundaravel Thirugnanasundaram"]
9
+ s.date = %q{2011-02-01}
10
+ s.description = %q{facebook_registration is a ruby library for displaying new Facebook Registration form and to parse to signed_request[http://developers.facebook.com/docs/plugins/registration].}
11
+ s.email = ["veerasundaravel@gmail.com"]
12
+ s.extra_rdoc_files = ["CHANGELOG.rdoc", "README.rdoc", ]
13
+ s.files = ["CHANGELOG.rdoc", "README.rdoc", "facebook_registration.gemspec", "facebooker.yml", "lib/facebook_registration.rb", "lib/helpers/helpers.rb", "lib/rails/signed_request.rb"]
14
+ s.homepage = %q{http://veerasundaravel.wordpress.com/2011/01/27/facebook-registration-plugin-in-rails/}
15
+ s.rdoc_options = ["--main", "README.rdoc"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{facebook_registration}
18
+ s.rubygems_version = %q{1.3.5}
19
+ s.summary = %q{facebook_registration is a ruby library for displaying new Facebook Registration form and to parse to signed_request[http://developers.facebook.com/docs/plugins/registration]. by Veerasundaravel Thirugnanasundaram}
20
+ s.test_files = []
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 1
25
+ s.add_runtime_dependency(%q<yajl-ruby>, [">= 0.7.6"])
26
+ else
27
+ s.add_dependency(%q<yajl-ruby>, [">= 0.7.6"])
28
+ end
29
+ end
data/facebooker.yml ADDED
@@ -0,0 +1,14 @@
1
+ development:
2
+ app_id:
3
+ api_key:
4
+ secret_key:
5
+
6
+ production:
7
+ app_id:
8
+ api_key:
9
+ secret_key:
10
+
11
+ test:
12
+ app_id:
13
+ api_key:
14
+ secret_key:
@@ -0,0 +1,32 @@
1
+ module FacebookRegistration
2
+ @facebook_configuration = {}
3
+ @raw_facebook_configuration = {}
4
+ @current_adapter = nil
5
+ @set_asset_host_to_callback_url = true
6
+ @path_prefix = nil
7
+ @use_curl = false
8
+
9
+ class << self
10
+
11
+ def load_configuration(facebook_yaml_file)
12
+ return false unless File.exist?(facebook_yaml_file)
13
+ @raw_facebook_configuration = YAML.load(ERB.new(File.read(facebook_yaml_file)).result)
14
+ if defined? RAILS_ENV
15
+ @raw_facebook_configuration = @raw_facebook_configuration[RAILS_ENV]
16
+ end
17
+ @raw_facebook_configuration
18
+ end
19
+
20
+ def facebook_config
21
+ @facebook_configuration
22
+ end
23
+ end
24
+ end
25
+
26
+ facebook_config = "#{RAILS_ROOT}/config/facebooker.yml"
27
+ FACEBOOK_CONFIG = FacebookRegistration.load_configuration(facebook_config)
28
+
29
+ if defined? Rails
30
+ require 'helpers/helpers'
31
+ require 'rails/signed_request'
32
+ end
@@ -0,0 +1,29 @@
1
+ module FacebookRegistration
2
+ def self.included(base)
3
+ base.send :include, InstanceMethods
4
+ end
5
+
6
+
7
+ module InstanceMethods
8
+ DefaultValues = {"fields" =>"name,email,password", "redirect-uri"=>"http://localhost:3000/fb_registration", "fb_only" => false, "width" => "100%", "height" => nil, "onvalidate" =>nil}
9
+
10
+ def init_fb_registration
11
+ raise "Must set Application ID for initializing" unless defined?(FACEBOOK_CONFIG) && FACEBOOK_CONFIG["app_id"]
12
+ "<script src=\"http://connect.facebook.net/en_US/all.js#appId=#{FACEBOOK_CONFIG["app_id"]}&xfbml=1\"></script> \n <script src=\"http://code.jquery.com/jquery-1.4.4.min.js\"></script>"
13
+ end
14
+
15
+ def fb_registration_form(options={})
16
+ options = DefaultValues.merge(options).delete_if { |key, value| value.nil? }
17
+ str = "<fb:registration"
18
+ options.each_pair do |key, value|
19
+ str += " #{key} = \"#{value}\""
20
+ end
21
+ str += "> </fb:registration>"
22
+ end
23
+ end
24
+
25
+
26
+ end
27
+
28
+ ActionView::Base.send(:include, FacebookRegistration) if defined?(ActionView::Base)
29
+
@@ -0,0 +1,43 @@
1
+ require 'rubygems'
2
+ require 'openssl'
3
+ require 'base64'
4
+ require 'yajl'
5
+
6
+ module FacebookRegistration
7
+ class SignedRequest
8
+ def self.parse(params)
9
+ if params.is_a?(Hash)
10
+ signed_request = params.delete('signed_request')
11
+ else
12
+ signed_request = params
13
+ end
14
+
15
+ unless signed_request
16
+ raise "Missing signed_request param"
17
+ end
18
+
19
+ signature, signed_params = signed_request.split('.')
20
+
21
+ unless signed_request_is_valid?(FACEBOOK_CONFIG['secret_key'], signature, signed_params)
22
+ raise "Invalid signature"
23
+ end
24
+
25
+ signed_params = Yajl::Parser.new.parse(base64_url_decode(signed_params))
26
+
27
+ return signed_params
28
+ end
29
+
30
+ private
31
+
32
+ def self.signed_request_is_valid?(secret, signature, params)
33
+ signature = base64_url_decode(signature)
34
+ expected_signature = OpenSSL::HMAC.digest('SHA256', secret, params.tr("-_", "+/"))
35
+ return signature == expected_signature
36
+ end
37
+
38
+ def self.base64_url_decode(str)
39
+ str = str + "=" * (6 - str.size % 6) unless str.size % 6 == 0
40
+ return Base64.decode64(str.tr("-_", "+/"))
41
+ end
42
+ end
43
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: facebook_registration
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Veerasundaravel Thirugnanasundaram
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2011-02-01 00:00:00 +05:30
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: yajl-ruby
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.7.6
24
+ version:
25
+ description: facebook_registration is a ruby library for displaying new Facebook Registration form and to parse to signed_request[http://developers.facebook.com/docs/plugins/registration].
26
+ email:
27
+ - veerasundaravel@gmail.com
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - CHANGELOG.rdoc
34
+ - README.rdoc
35
+ files:
36
+ - CHANGELOG.rdoc
37
+ - README.rdoc
38
+ - facebook_registration.gemspec
39
+ - facebooker.yml
40
+ - lib/facebook_registration.rb
41
+ - lib/helpers/helpers.rb
42
+ - lib/rails/signed_request.rb
43
+ has_rdoc: true
44
+ homepage: http://veerasundaravel.wordpress.com/2011/01/27/facebook-registration-plugin-in-rails/
45
+ licenses: []
46
+
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --main
50
+ - README.rdoc
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ requirements: []
66
+
67
+ rubyforge_project: facebook_registration
68
+ rubygems_version: 1.3.5
69
+ signing_key:
70
+ specification_version: 1
71
+ summary: facebook_registration is a ruby library for displaying new Facebook Registration form and to parse to signed_request[http://developers.facebook.com/docs/plugins/registration]. by Veerasundaravel Thirugnanasundaram
72
+ test_files: []
73
+