wechat-validator 0.2 → 0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5109b3bbb8a3e6360b6111134b4cb85d606c6682
|
4
|
+
data.tar.gz: ec6a546d8312f57b5ac0f5ef1b6c00b3d590614d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e46448d4eb99540ceae67e5174fbdc0932d7d6ce9409f143ff5982190aa3435b070442280baab4b33b95ba852c777bfbc2c67586dfe241784aace40887b40a2
|
7
|
+
data.tar.gz: 6cbbb88bdafbc9aec64b8e73f642e3f93277200a7f1a16dbe866f8e8b2eed1253abb39be15bc4efc5b6cdb6d397c306bdef50e2822ef4dd825c081acaf140bcf
|
@@ -46,6 +46,9 @@ module Wechat
|
|
46
46
|
value.present?
|
47
47
|
end
|
48
48
|
|
49
|
+
deprecate check_signature: :'Wechat::Validator::Concerns::SignatureValidator.validate_signature', deprecator: ActiveSupport::Deprecation.new('1.0', 'wechat-validator')
|
50
|
+
deprecate check_parameter: :'Wechat::Validator::Concerns::SignatureValidator.validate_parameter', deprecator: ActiveSupport::Deprecation.new('1.0', 'wechat-validator')
|
51
|
+
|
49
52
|
end
|
50
53
|
|
51
54
|
module ClassMethods
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Wechat::Validator::Concerns::SignatureValidator
|
2
|
+
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
self.included do |includer|
|
6
|
+
|
7
|
+
def validate_signature(token)
|
8
|
+
|
9
|
+
if token.blank?
|
10
|
+
Rails.logger.warn 'Token is required to validate URL by Wechat.'
|
11
|
+
render status: :forbidden, text: 'The token parameter is required.'
|
12
|
+
return
|
13
|
+
end
|
14
|
+
|
15
|
+
timestamp = params[:timestamp]
|
16
|
+
nonce = params[:nonce]
|
17
|
+
signature = params[:signature]
|
18
|
+
echo = params[:echostr]
|
19
|
+
|
20
|
+
return unless validate_parameter 'timestamp', timestamp
|
21
|
+
return unless validate_parameter 'nonce', nonce
|
22
|
+
return unless validate_parameter 'signature', signature
|
23
|
+
return unless validate_parameter 'echo', echo
|
24
|
+
|
25
|
+
actual_signature = ::Wechat::Validation::Signature.create nonce, timestamp, token # ::Wechat::Validation.sign nonce, timestamp, token
|
26
|
+
signature_matched = signature==actual_signature
|
27
|
+
Rails.logger.warn "Actual signature is #{actual_signature}, which #{signature_matched ? 'equals' : 'does not equal'} to the given signature #{signature}."
|
28
|
+
|
29
|
+
if signature_matched
|
30
|
+
render text: echo
|
31
|
+
else
|
32
|
+
render status: :forbidden, text: "The signature parameter '#{signature}' and the generated parameter '#{actual_signature}' is not matched."
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
def validate_parameter(name, value)
|
38
|
+
if value.blank?
|
39
|
+
Rails.logger.warn "The #{name} parameter is blank. Failed to validate URL by Wechat."
|
40
|
+
render status: :bad_request, text: "The #{name} parameter is required."
|
41
|
+
end
|
42
|
+
value.present?
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
module ClassMethods
|
48
|
+
# def method_name do end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wechat-validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.3'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Topbit Du
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -53,6 +53,7 @@ files:
|
|
53
53
|
- app/assets/stylesheets/wechat/validator/application.css
|
54
54
|
- app/controllers/wechat/validator/application_controller.rb
|
55
55
|
- app/controllers/wechat/validator/concerns/signature_checker.rb
|
56
|
+
- app/controllers/wechat/validator/concerns/signature_validator.rb
|
56
57
|
- app/controllers/wechat/validator/server_validations_controller.rb
|
57
58
|
- app/helpers/wechat/validator/application_helper.rb
|
58
59
|
- app/views/layouts/wechat/validator/application.html.erb
|