wepay-signer 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/{signer.rb → wepay-signer.rb} +18 -42
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dee087f2859195456da1b0ed41de40beefa30ab7
|
4
|
+
data.tar.gz: ec8a0ebdb7918e3d14af18d9591199070c09f154
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9089628d9b8642359f8c3a1d071a91298e4c9df22fe1b2b38c8b9288022fba00301b35e7920bf522c046bd021fc032c962da4a6ec4d31544aa9fc208cca7be0e
|
7
|
+
data.tar.gz: 877c49f80dc7360751985e814c634ad656822bf1cef7953444529a6ac87bb1ccebe7c951ceba0746f93fe7558330b1cf718a42617af9d379b7a2dcf2c412b8b9
|
@@ -29,6 +29,11 @@ module WePay
|
|
29
29
|
##
|
30
30
|
class Signer
|
31
31
|
|
32
|
+
attr_reader :self_key
|
33
|
+
attr_reader :client_id
|
34
|
+
attr_reader :client_secret
|
35
|
+
attr_reader :hash_algo
|
36
|
+
|
32
37
|
##
|
33
38
|
# Constructs a new instance of this class.
|
34
39
|
#
|
@@ -42,43 +47,16 @@ module WePay
|
|
42
47
|
# @option options [String] hash_algo (sha512) The hash algorithm to use for signing.
|
43
48
|
##
|
44
49
|
def initialize(client_id, client_secret, options = {})
|
45
|
-
@client_id = client_id
|
46
|
-
@client_secret = client_secret
|
50
|
+
@client_id = client_id.to_s
|
51
|
+
@client_secret = client_secret.to_s
|
47
52
|
|
48
53
|
options = {
|
49
54
|
:self_key => 'WePay',
|
50
55
|
:hash_algo => 'sha512',
|
51
|
-
}.merge(options)
|
56
|
+
}.merge(options)
|
52
57
|
|
53
|
-
@self_key = options[:self_key]
|
54
|
-
@hash_algo = options[:hash_algo]
|
55
|
-
end
|
56
|
-
|
57
|
-
##
|
58
|
-
# Gets the self key that was set in the constructor.
|
59
|
-
#
|
60
|
-
# @return [String] The self key.
|
61
|
-
##
|
62
|
-
def get_self_key
|
63
|
-
@self_key
|
64
|
-
end
|
65
|
-
|
66
|
-
##
|
67
|
-
# Gets the client key that was set in the constructor.
|
68
|
-
#
|
69
|
-
# @return [String] The client key.
|
70
|
-
##
|
71
|
-
def get_client_id
|
72
|
-
@client_id
|
73
|
-
end
|
74
|
-
|
75
|
-
##
|
76
|
-
# Gets the client secret that was set in the constructor.
|
77
|
-
#
|
78
|
-
# @return [String] The client secret.
|
79
|
-
##
|
80
|
-
def get_client_secret
|
81
|
-
@client_secret
|
58
|
+
@self_key = options[:self_key].to_s
|
59
|
+
@hash_algo = options[:hash_algo].to_s
|
82
60
|
end
|
83
61
|
|
84
62
|
##
|
@@ -100,9 +78,7 @@ module WePay
|
|
100
78
|
context = create_context(payload)
|
101
79
|
s2s = create_string_to_sign(scope, context)
|
102
80
|
signing_key = get_signing_salt
|
103
|
-
|
104
|
-
|
105
|
-
return signature
|
81
|
+
OpenSSL::HMAC.hexdigest(@hash_algo, signing_key, s2s)
|
106
82
|
end
|
107
83
|
|
108
84
|
##
|
@@ -118,13 +94,13 @@ module WePay
|
|
118
94
|
signed_token = sign(payload)
|
119
95
|
payload[:client_id] = @client_id
|
120
96
|
payload[:stoken] = signed_token
|
121
|
-
qsa =
|
97
|
+
qsa = []
|
122
98
|
|
123
99
|
payload.keys.sort.each do | key |
|
124
100
|
qsa.push sprintf("%s=%s", key, payload[key])
|
125
101
|
end
|
126
102
|
|
127
|
-
|
103
|
+
qsa.join("&")
|
128
104
|
end
|
129
105
|
|
130
106
|
private
|
@@ -139,7 +115,7 @@ private
|
|
139
115
|
def create_string_to_sign(scope, context)
|
140
116
|
scope_hash = OpenSSL::Digest.new(@hash_algo, scope)
|
141
117
|
context_hash = OpenSSL::Digest.new(@hash_algo, context)
|
142
|
-
|
118
|
+
sprintf "SIGNER-HMAC-%s\n%s\n%s\n%s\n%s", @hash_algo.upcase, @self_key, @client_id, scope_hash, context_hash
|
143
119
|
end
|
144
120
|
|
145
121
|
##
|
@@ -161,8 +137,8 @@ private
|
|
161
137
|
|
162
138
|
canonical_payload.sort!
|
163
139
|
|
164
|
-
signed_headers_string = payload.keys.sort_by {|s| s.to_s}.join(";")
|
165
|
-
|
140
|
+
signed_headers_string = payload.keys.sort_by {|s| s.to_s }.join(";")
|
141
|
+
canonical_payload.join("") + "\n" + signed_headers_string
|
166
142
|
end
|
167
143
|
|
168
144
|
##
|
@@ -173,7 +149,7 @@ private
|
|
173
149
|
def get_signing_salt
|
174
150
|
self_key_sign = OpenSSL::HMAC.digest(@hash_algo, @client_secret, @self_key)
|
175
151
|
client_id_sign = OpenSSL::HMAC.digest(@hash_algo, self_key_sign, @client_id)
|
176
|
-
|
152
|
+
OpenSSL::HMAC.digest(@hash_algo, client_id_sign, 'signer')
|
177
153
|
end
|
178
154
|
|
179
155
|
##
|
@@ -182,7 +158,7 @@ private
|
|
182
158
|
# @return [String] The string which represents the scope in which the signature is valid.
|
183
159
|
##
|
184
160
|
def create_scope
|
185
|
-
|
161
|
+
sprintf "%s/%s/signer", @self_key, @client_id
|
186
162
|
end
|
187
163
|
|
188
164
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wepay-signer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- WePay
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A Modern Ruby SDK for signing WePay requests.
|
14
14
|
email: api@wepay.com
|
@@ -16,7 +16,7 @@ executables: []
|
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
|
-
- lib/signer.rb
|
19
|
+
- lib/wepay-signer.rb
|
20
20
|
homepage: https://github.com/wepay/signer-ruby
|
21
21
|
licenses:
|
22
22
|
- Apache-2.0
|