facebook_session 0.0.3 → 0.0.4

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