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: 52c70d489e2f730f37e5156c281389eefdd482b3
4
- data.tar.gz: 07faf1150db584263433821e3e2165cd310027dd
3
+ metadata.gz: 5109b3bbb8a3e6360b6111134b4cb85d606c6682
4
+ data.tar.gz: ec6a546d8312f57b5ac0f5ef1b6c00b3d590614d
5
5
  SHA512:
6
- metadata.gz: e9c4b0d7f70157b86b2b5b368d9127078cc61446e5573f3ab78c5d79f69ce82e2528fba2465ebafce166f643fa2098a0fc03f062439744018e1b878091f1efaf
7
- data.tar.gz: 61208f0bca87d65209c8a68f5b42e1536d3c9ae2f846db89f4040a3fa2f360a064b2bf73fce9b789404e43d0266a1d1805e805505058cce9baf0c4c7b3226512
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
@@ -1,5 +1,5 @@
1
1
  module Wechat
2
2
  module Validator
3
- VERSION = '0.2'.freeze
3
+ VERSION = '0.3'.freeze
4
4
  end
5
5
  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.2'
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-02-29 00:00:00.000000000 Z
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