facebook-signed-request 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -4,6 +4,12 @@ Usage
4
4
 
5
5
  ```ruby
6
6
  require 'facebook-signed-request'
7
+
8
+ # The secret can be set globally
9
+ Facebook::SignedRequest.secret = "dkhsdfhjsd123d2ed3q1wd222qd2"
10
+ request = Facebook::SignedRequest.new( params[:signed_request] )
11
+
12
+ # or as an optional parameter for individual calls
7
13
  request = Facebook::SignedRequest.new( params[:signed_request], secret )
8
14
 
9
15
  request.valid?
@@ -38,3 +44,5 @@ Usage
38
44
  # => g_eE3hoQDPKFusHcc_Tj7k2xxo3mCKsOEXKMViq0pAY=.eyJmb28iOiJiYXIifQ==
39
45
 
40
46
  ```
47
+
48
+ Run the tests with ```rake test:units```
data/Rakefile CHANGED
@@ -1 +1,12 @@
1
1
  require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ namespace :test do
5
+ Rake::TestTask.new(:units) do |t|
6
+ t.libs << "test"
7
+ t.test_files = FileList['test/*_test.rb']
8
+
9
+ t.verbose = true
10
+ end
11
+ end
12
+
@@ -1,7 +1,7 @@
1
1
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'facebook-signed-request'))
2
2
 
3
3
  require "facebook-signed-request/version"
4
- require 'digest'
4
+ require 'openssl'
5
5
  require 'base64'
6
6
  require 'json'
7
7
  require 'signed_request'
@@ -9,8 +9,8 @@ module Facebook
9
9
  def encode_and_sign options
10
10
  encoded_data = Base64.strict_encode64( options.to_json )
11
11
 
12
- digestor = Digest::HMAC.new( @secret, Digest::SHA256 )
13
- signature = digestor.digest( encoded_data )
12
+ digestor = OpenSSL::Digest::Digest.new('sha256')
13
+ signature = OpenSSL::HMAC.digest( digestor, @secret, encoded_data )
14
14
  encoded_signature = Base64.strict_encode64( signature )
15
15
  encoded_signature = encoded_signature.gsub('+','_').gsub('/', '_')
16
16
 
@@ -95,8 +95,10 @@ module Facebook
95
95
  end
96
96
 
97
97
  def validate_signature
98
- digestor = Digest::HMAC.new( @secret, Digest::SHA256 )
99
- computed_signature = digestor.digest( @encoded_data )
98
+ digestor = OpenSSL::Digest::Digest.new('sha256')
99
+ computed_signature = OpenSSL::HMAC.digest(
100
+ digestor, @secret, @encoded_data
101
+ )
100
102
 
101
103
  if @signature != computed_signature
102
104
  message = "Signatures do not match. " \
@@ -1,5 +1,5 @@
1
1
  module Facebook
2
2
  class SignedRequest
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facebook-signed-request
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-06-26 00:00:00.000000000 +02:00
12
+ date: 2011-06-27 00:00:00.000000000 +02:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
  description: Parses and validates Facebook signed requests