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 +8 -0
- data/Rakefile +11 -0
- data/lib/facebook-signed-request.rb +1 -1
- data/lib/facebook-signed-request/signed_request.rb +6 -4
- data/lib/facebook-signed-request/version.rb +1 -1
- metadata +2 -2
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
@@ -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::
|
13
|
-
signature =
|
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
|
99
|
-
computed_signature
|
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. " \
|
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.
|
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-
|
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
|