facebook_session 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ module FacebookSession
2
+ module Helper
3
+
4
+ def facebook_session
5
+ return @facebook_session if @facebook_session
6
+ raise 'FacebookSession not configured!' unless FacebookSession.config?
7
+ if facebook_cookie = cookies["fbsr_#{FacebookSession.application_id}"]
8
+ @facebook_session = FacebookSession::Session.parse_cookie(facebook_cookie)
9
+ end
10
+ end
11
+
12
+ def facebook_session?
13
+ self.facebook_session ? true : false
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,38 @@
1
+ module FacebookSession
2
+ class Session
3
+ attr_accessor :user_id, :oauth_token, :algorithm, :issued_at
4
+
5
+ class << self
6
+ def base64_url_decode(string)
7
+ encoded_string = string.gsub('-','+').gsub('_','/')
8
+ encoded_string += '=' while (encoded_string.length % 4 != 0)
9
+ Base64.decode64(encoded_string)
10
+ end
11
+
12
+ def parse_cookie(cookie)
13
+ encoded_sig, payload = cookie.split('.')
14
+ sig = base64_url_decode(encoded_sig)
15
+ session_data = JSON.parse(base64_url_decode(payload))
16
+ session_data.symbolize_keys!
17
+
18
+ expected_sig = OpenSSL::HMAC.digest(
19
+ OpenSSL::Digest::Digest.new('sha256'),
20
+ FacebookSession.application_secret,
21
+ payload
22
+ )
23
+
24
+ if sig == expected_sig
25
+ self.new(session_data)
26
+ else
27
+ nil
28
+ end
29
+ end
30
+ end
31
+
32
+ def initialize(session_data={})
33
+ session_data.each do |key, value|
34
+ self.send("#{key.to_s}=".to_sym, value) if self.respond_to?("#{key.to_s}=".to_sym)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module FacebookSession
2
+ VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,33 @@
1
+ require File.join(File.dirname(__FILE__), 'facebook_session/helper')
2
+ require File.join(File.dirname(__FILE__), 'facebook_session/session')
3
+
4
+ module FacebookSession
5
+ class << self
6
+
7
+ def config
8
+ @@config ||= {}
9
+ end
10
+
11
+ def config?
12
+ self.config[:application_id] && self.config[:application_secret] ? true : false
13
+ end
14
+
15
+ def configure(options={})
16
+ options.each do |key, val|
17
+ self.config[key.to_sym] = val
18
+ end
19
+ self.config
20
+ end
21
+
22
+ def application_id
23
+ self.config[:application_id]
24
+ end
25
+
26
+ def application_secret
27
+ self.config[:application_secret]
28
+ end
29
+ end
30
+ end
31
+
32
+ ActionView::Base.send :include, FacebookSession::Helper
33
+ ActionController::Base.send :include, FacebookSession::Helper
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: facebook_session
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 3
10
+ version: 0.0.3
11
+ platform: ruby
12
+ authors:
13
+ - "Inge J\xC3\xB8rgensen"
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-05-02 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: Rails plugin for simple Facebook session authentication
22
+ email: inge@manualdesign.no
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - lib/facebook_session.rb
31
+ - lib/facebook_session/helper.rb
32
+ - lib/facebook_session/session.rb
33
+ - lib/facebook_session/version.rb
34
+ homepage: https://github.com/manualdesign/simple_session
35
+ licenses: []
36
+
37
+ post_install_message:
38
+ rdoc_options: []
39
+
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ hash: 3
48
+ segments:
49
+ - 0
50
+ version: "0"
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ requirements: []
61
+
62
+ rubyforge_project:
63
+ rubygems_version: 1.8.17
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Rails plugin for simple Facebook session authentication
67
+ test_files: []
68
+