wechat-validator 0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2eb8f8ca2d42d8cde005149dd05c7d4ee67b9083
4
+ data.tar.gz: 32681763ef68e00239747c16c083e755ecb288ba
5
+ SHA512:
6
+ metadata.gz: 65de9d152cd21a28ce08c0ea2c11f0d08f9bb2d5fbc7bd7932c1fc6c6f28ba0c51965ec807141dfd836b83778a76833743e51260312b59d2a6de4e75ae554504
7
+ data.tar.gz: 324f69a6cee1f88ca6c01152bdc118fc40e112c531fce36f97b8b1b4ee8fd1b32d4d9cdb620a42e36edddea170b72faf5ec5a6ea8b7041390d60cdeb7391fd03
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2016 Topbit Du
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ # Wechat Validator 微信服务器验证器引擎
2
+
3
+ The Wechat Server Validator Engine is an engine which handles the Wechat server validation requests.
4
+ 微信服务器验证引擎是一个处理微信服务器验证请求的引擎。
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Validator'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+ load 'rails/tasks/statistics.rake'
20
+
21
+
22
+
23
+ Bundler::GemHelper.install_tasks
24
+
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,2 @@
1
+ class Wechat::Validator::ApplicationController < ActionController::Base
2
+ end
@@ -0,0 +1,53 @@
1
+ module Wechat
2
+ module Validator
3
+ module Concerns
4
+
5
+ module SignatureChecker
6
+
7
+ extend ActiveSupport::Concern
8
+
9
+ self.included do |includer|
10
+
11
+ def check_signature(token)
12
+
13
+ if token.blank?
14
+ Rails.logger.warn 'Token is required to validate URL by Wechat.'
15
+ render status: :forbidden, text: ''
16
+ return
17
+ end
18
+
19
+ timestamp = params[:timestamp]
20
+ nonce = params[:nonce]
21
+ signature = params[:signature]
22
+ echo = params[:echostr]
23
+
24
+ return unless check_parameter 'timestamp', timestamp
25
+ return unless check_parameter 'nonce', nonce
26
+ return unless check_parameter 'signature', signature
27
+ return unless check_parameter 'echo', echo
28
+
29
+ actual_signature = ::Wechat::Validation.sign nonce, timestamp, token
30
+ Rails.logger.warn "Actual signature is #{actual_signature}, which #{signature==actual_signature ? 'equals' : 'does not equal'} to the given signature #{signature}."
31
+ render text: (signature==actual_signature ? echo : '')
32
+
33
+ end
34
+
35
+ def check_parameter(name, value)
36
+ if value.blank?
37
+ Rails.logger.warn "The #{name} parameter is blank. Failed to validate URL by Wechat."
38
+ render status: :bad_request, text: ''
39
+ end
40
+ value.present?
41
+ end
42
+
43
+ end
44
+
45
+ module ClassMethods
46
+ # def method_name do end
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,12 @@
1
+ class Wechat::Validator::ServerValidationsController < ::Wechat::Validator::ApplicationController
2
+
3
+ include ::Wechat::Validator::Concerns::SignatureChecker
4
+
5
+ def index
6
+
7
+ token = Rails.application.secrets.wechat_validation_token
8
+ check_signature token
9
+
10
+ end
11
+
12
+ end
@@ -0,0 +1,2 @@
1
+ module Wechat::Validator::ApplicationHelper
2
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Validator</title>
5
+ <%= stylesheet_link_tag "validator/application", media: "all" %>
6
+ <%= javascript_include_tag "validator/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,9 @@
1
+ Wechat::Validator::Engine.routes.draw do
2
+
3
+ #scope module: 'wechat/validator' do
4
+ # resources :server_validations, only: :index
5
+ #end
6
+
7
+ resources :server_validations, only: :index
8
+
9
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :validator do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,6 @@
1
+ require 'wechat/validator/engine'
2
+
3
+ module Wechat
4
+ module Validator
5
+ end
6
+ end
@@ -0,0 +1,21 @@
1
+ module Wechat
2
+ module Validator
3
+
4
+ class Engine < ::Rails::Engine
5
+
6
+ config.autoload_paths += %W(
7
+ #{config.root}/lib
8
+ #{config.root}/app/controllers/wechat/validator/concerns
9
+ )
10
+
11
+ config.eager_load_paths += %W(
12
+ #{config.root}/lib
13
+ #{config.root}/app/controllers/wechat/validator/concerns
14
+ )
15
+
16
+ isolate_namespace Wechat::Validator
17
+
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ module Wechat
2
+ module Validator
3
+ VERSION = '0.1'.freeze
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wechat-validator
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Topbit Du
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: wechat-validation
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.1'
41
+ description: The Wechat Validator engine handles the Wechat server validation requests.
42
+ email:
43
+ - topbit.du@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - MIT-LICENSE
49
+ - README.md
50
+ - Rakefile
51
+ - app/assets/javascripts/wechat/validator/application.js
52
+ - app/assets/stylesheets/wechat/validator/application.css
53
+ - app/controllers/wechat/validator/application_controller.rb
54
+ - app/controllers/wechat/validator/concerns/signature_checker.rb
55
+ - app/controllers/wechat/validator/server_validations_controller.rb
56
+ - app/helpers/wechat/validator/application_helper.rb
57
+ - app/views/layouts/wechat/validator/application.html.erb
58
+ - config/routes.rb
59
+ - lib/tasks/validator_tasks.rake
60
+ - lib/wechat/validator.rb
61
+ - lib/wechat/validator/engine.rb
62
+ - lib/wechat/validator/version.rb
63
+ homepage: https://github.com/topbitdu/wechat-validator
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.4.5.1
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: The Wechat Validator engine includes a concern and a controller to handle
87
+ the Wechat server validation request.
88
+ test_files: []