cadinsor 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +109 -0
  4. data/README.rdoc +3 -0
  5. data/Rakefile +34 -0
  6. data/app/controllers/cadinsor/api_keys_controller.rb +29 -0
  7. data/app/controllers/cadinsor/application_controller.rb +4 -0
  8. data/app/helpers/cadinsor/api_keys_helper.rb +4 -0
  9. data/app/helpers/cadinsor/application_helper.rb +4 -0
  10. data/app/models/cadinsor/api_key.rb +19 -0
  11. data/app/models/cadinsor/client_app.rb +13 -0
  12. data/app/views/cadinsor/api_keys/create.rabl +3 -0
  13. data/app/views/cadinsor/api_keys/show.rabl +10 -0
  14. data/app/views/cadinsor/application/cadinsor_error_response.rabl +3 -0
  15. data/app/views/layouts/cadinsor/application.html.erb +14 -0
  16. data/config/initializers/rabl_config.rb +4 -0
  17. data/config/routes.rb +4 -0
  18. data/db/migrate/20140111160304_create_cadinsor_client_apps.rb +9 -0
  19. data/db/migrate/20140111160653_create_cadinsor_api_keys.rb +10 -0
  20. data/lib/cadinsor.rb +6 -0
  21. data/lib/cadinsor/engine.rb +10 -0
  22. data/lib/cadinsor/extensions.rb +61 -0
  23. data/lib/cadinsor/extensions/request_error.rb +6 -0
  24. data/lib/cadinsor/version.rb +3 -0
  25. data/lib/generators/cadinsor/install/USAGE +7 -0
  26. data/lib/generators/cadinsor/install/install_generator.rb +30 -0
  27. data/lib/generators/cadinsor/install/templates/cadinsor_initializer.erb +29 -0
  28. data/lib/tasks/api_key.rake +27 -0
  29. data/lib/tasks/cadinsor_tasks.rake +4 -0
  30. data/lib/tasks/client_app.rake +85 -0
  31. data/test/cadinsor_test.rb +7 -0
  32. data/test/controllers/cadinsor/api_keys_controller_test.rb +9 -0
  33. data/test/dummy/Gemfile.lock +25 -0
  34. data/test/dummy/README.rdoc +28 -0
  35. data/test/dummy/Rakefile +6 -0
  36. data/test/dummy/app/assets/javascripts/application.js +13 -0
  37. data/test/dummy/app/assets/javascripts/cadinsor_tests.js +2 -0
  38. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  39. data/test/dummy/app/assets/stylesheets/cadinsor_tests.css +4 -0
  40. data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
  41. data/test/dummy/app/controllers/application_controller.rb +5 -0
  42. data/test/dummy/app/controllers/cadinsor_tests_controller.rb +26 -0
  43. data/test/dummy/app/helpers/application_helper.rb +2 -0
  44. data/test/dummy/app/helpers/cadinsor_tests_helper.rb +2 -0
  45. data/test/dummy/app/views/cadinsor_tests/do_not_check.rabl +3 -0
  46. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  47. data/test/dummy/bin/bundle +3 -0
  48. data/test/dummy/bin/rails +4 -0
  49. data/test/dummy/bin/rake +4 -0
  50. data/test/dummy/config.ru +4 -0
  51. data/test/dummy/config/application.rb +23 -0
  52. data/test/dummy/config/boot.rb +5 -0
  53. data/test/dummy/config/database.yml +25 -0
  54. data/test/dummy/config/environment.rb +5 -0
  55. data/test/dummy/config/environments/development.rb +29 -0
  56. data/test/dummy/config/environments/production.rb +80 -0
  57. data/test/dummy/config/environments/test.rb +36 -0
  58. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  59. data/test/dummy/config/initializers/cadinsor.rb +29 -0
  60. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  61. data/test/dummy/config/initializers/inflections.rb +16 -0
  62. data/test/dummy/config/initializers/mime_types.rb +5 -0
  63. data/test/dummy/config/initializers/secret_token.rb +12 -0
  64. data/test/dummy/config/initializers/session_store.rb +3 -0
  65. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  66. data/test/dummy/config/locales/en.yml +23 -0
  67. data/test/dummy/config/routes.rb +4 -0
  68. data/test/dummy/db/development.sqlite3 +0 -0
  69. data/test/dummy/db/migrate/20140115125610_create_cadinsor_client_apps.cadinsor.rb +11 -0
  70. data/test/dummy/db/migrate/20140115125611_create_cadinsor_api_keys.cadinsor.rb +11 -0
  71. data/test/dummy/db/schema.rb +33 -0
  72. data/test/dummy/db/test.sqlite3 +0 -0
  73. data/test/dummy/log/development.log +2737 -0
  74. data/test/dummy/public/404.html +58 -0
  75. data/test/dummy/public/422.html +58 -0
  76. data/test/dummy/public/500.html +57 -0
  77. data/test/dummy/public/favicon.ico +0 -0
  78. data/test/dummy/test/controllers/cadinsor_tests_controller_test.rb +9 -0
  79. data/test/dummy/test/helpers/cadinsor_tests_helper_test.rb +4 -0
  80. data/test/fixtures/cadinsor/api_keys.yml +11 -0
  81. data/test/fixtures/cadinsor/client_apps.yml +11 -0
  82. data/test/helpers/cadinsor/api_keys_helper_test.rb +6 -0
  83. data/test/integration/navigation_test.rb +10 -0
  84. data/test/models/cadinsor/api_key_test.rb +9 -0
  85. data/test/models/cadinsor/client_app_test.rb +9 -0
  86. data/test/test_helper.rb +15 -0
  87. metadata +228 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f272eb0fca093ecb854ed3e0095fbaa11601be92
4
+ data.tar.gz: e527755a81a9c143c407a9c9cba4f61054b4659f
5
+ SHA512:
6
+ metadata.gz: 61236189e79b581f1c004912d393bdf6579325566ef404319bd1a150a8e54e884f35beb56f12ec24a6a70dc45ed6f017af889d4bc24e80d4323ee7405cbd4d42
7
+ data.tar.gz: ec34b71995bfb135ca902e7dedb52af17fd605fdd7ee969b7d5b62966e15e92ece962b5a2e5fbe9a2099e3f84f6dee91773eaf74f8a1eb007e41c552408b95df
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 Ramkumar V.
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,109 @@
1
+ Cadinsor 0.1.0
2
+ ===
3
+ ## What is Cadinsor?
4
+ Cadinsor provides OAuth like authentication to validate requests from your client apps to your backend Rails application. It can be easily mounted onto any application as it is a Rails engine. Currently supports both JSON and XML formats.
5
+
6
+ ## Setup Instructions
7
+ Add the cadinsor gem your gem file and then run the install generator. The installer will ask you would like to mount the engine.
8
+
9
+
10
+ gem "cadinsor"
11
+ $ rails g cadinsor:install
12
+ $ rake db:migrate
13
+
14
+ ## So how does it work?
15
+ Every request that is authenticated through Cadinsor must possess among it's parameters:
16
+
17
+ 1. A valid server issued key
18
+
19
+ 2. A valid app id
20
+
21
+ 3. A proper request signature
22
+
23
+ ### Key Components
24
+ * **An APP ID/ Secret**: Each client application has a unique APP ID and an "APP Secret" string. The app id is sent as part of every request from the client app. The app secret is not sent with the request, and is instead used to build the request signature (explained below).
25
+ Cadinsor has very helpful rake tasks for you to manager your apps. Please be warned that the client_app tasks are interactive and cannot be run in a background job. You may run the following rake tasks:
26
+
27
+ rake cadinsor:client_app:create # Add a new client app
28
+ rake cadinsor:client_app:delete # Delete App
29
+ rake cadinsor:client_app:edit_secret # Edit App Secret
30
+ rake cadinsor:client_app:list # List all client apps with their secrets
31
+
32
+ * **A Server Issued Key/ Key Fetch API**: In order to keep each request from the app independent, a server issued unique key string is sent along with request. A key is obtained by making a call the Key Fetch API. It is a public API and requires no parameters except an optional app id. The key has a time bound expiry (default = 5mins, specified in the initializer) and is invalidated after each request to the backend application.
33
+
34
+ + Assuming your engine is mounted at /cadinsor, you may get a new key by visiting <root_url>/cadinsor/api_keys/create.json
35
+ + Assuming your engine is mounted at /cadinsor, you may view the status of your key by visiting <root_url>/cadinsor/api_keys/show.json?key=<key value here\>
36
+
37
+ You can clear expired keys from the db in the background or foreground by using rake tasks:
38
+
39
+ rake cadinsor:api_key:clean_background # Remove all expired keys from the db without any confirmation, for background tasks like cron jobs only
40
+ rake cadinsor:api_key:clean_manual # Interactive task to remove expired keys from the db, please use clean_background if you want to run this in a non-interactive mode
41
+
42
+
43
+ ### Building the request signature at the client side
44
+ All the request parameters are sorted in alphabetical order and a request string is obtained by concatenating the corresponding values of these parameters. To this string, the app secret and an SHA2 (256 bit) hash is computed of this string. This signature is also sent with every request to the server.
45
+ Ex: Consider a simple login request with the following parameters:
46
+
47
+ 1. user_name: lewstherin
48
+ 2. password: thedragon
49
+ 3. key: N1ilN8qZmOXodohO-9IRvpxZmVDY_Zg8P7r9JoDpFs4
50
+ 4. app_id: 2
51
+
52
+ In alphabetical order, these parameters become app_id, key, password and user_name. Assuming the app secret is "CaraianCaldazar!", our request string becomes "2N1ilN8qZmOXodohO-9IRvpxZmVDY_Zg8P7r9JoDpFs4thedragonlewstherinCaraianCaldazar!". Now the SHA2 hash of this string is "ab71fc84351c4cdfd23c31ea2ce4133b38cd3c21cfee48d3d15501e726c16734" and this is sent along with the request as the parameter signature.
53
+ At the server end, Cadinsor will rebuild this signature and check if it matches with the input signature. If it does, it means the client has sent a valid app secret and thus the request is from a trusted source.
54
+
55
+ In case you have nested hashes, flatten them by appending the outer hash key as a prefix, and then sort the keys to build a signature.
56
+ Ex: If your input params is as follows, cadinsor computes the signature of the flattened hash shown below.
57
+
58
+ params = {:key=>"aslkaslkas", :signature=>"askjaskdskjdasklfj2103", :user=>{:id=>1, :email=>"a@b.com"}, :post=>{:title=>"rails_layout", :author=>"lewstherin", :comments=>{:author=>"Lews Therin", :date=>"14012014", :desc=>"This is a dummy comment"}}}
59
+
60
+ flattened_hash = {"key"=>"aslkaslkas", "signature"=>"askjaskdskjdasklfj2103", "user_id"=>1, "user_email"=>"a@b.com", "post_title"=>"rails_layout", "post_author"=>"lewstherin", "post_comments_author"=>"Lews Therin", "post_comments_date"=>"14012014", "post_comments_desc"=>"This is a dummy comment"}
61
+
62
+ ### Validating your requests at the controller side
63
+
64
+ You can validate your requests by the either placing a call to the **check_request_with_cadinsor** method in the before_filter method of your controller or by making an explicit call within your method. Take a look at the following code snippet (same code as in the test/dummy application):
65
+
66
+ class CadinsorTestsController < ApplicationController
67
+
68
+ before_filter :check_request_with_cadinsor, except: [:inside_method_check, :do_not_check]
69
+
70
+ def default_check
71
+ respond_to do |format|
72
+ format.json {render :action => 'do_not_check', :format => 'json'}
73
+ format.xml {render :action => 'do_not_check', :format => 'xml'}
74
+ end
75
+ end
76
+
77
+ def inside_method_check
78
+ check_request_with_cadinsor
79
+ respond_to do |format|
80
+ format.json {render :action => 'do_not_check', :format => 'json'}
81
+ format.xml {render :action => 'do_not_check', :format => 'xml'}
82
+ end
83
+ end
84
+
85
+ def do_not_check
86
+ respond_to do |format|
87
+ format.json {render :action => 'do_not_check', :format => 'json'}
88
+ format.xml {render :action => 'do_not_check', :format => 'xml'}
89
+ end
90
+ end
91
+ end
92
+
93
+ ### Options while calling the *check_request_with_cadinsor_method*
94
+
95
+ 1. If you do not want the cadinsor to check the params hash, but would like to check some other hash, you can do that by calling the method as follows:
96
+
97
+ check_request_with_cadinsor(target_params: params[user])
98
+
99
+ 2. You can disable key checking altogether by:
100
+
101
+ check_request_with_cadinsor(ignore_api_key_check: true)
102
+
103
+ ## Action Items
104
+
105
+ 1. Add tests
106
+ 2. Improve this documentation
107
+
108
+ ## License
109
+ [MIT License](http://opensource.org/licenses/MIT)
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = Cadinsor
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,34 @@
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 = 'Cadinsor'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1,29 @@
1
+ require_dependency "cadinsor/application_controller"
2
+
3
+ module Cadinsor
4
+ class ApiKeysController < ApplicationController
5
+
6
+ def create
7
+ @key = ApiKey.new
8
+ @key.client_app_id = params[Cadinsor::Engine.config.api_key_param_name].to_i if params[Cadinsor::Engine.config.api_key_param_name]
9
+ @key.generate_key!
10
+ if @key.save
11
+ respond_to do |format|
12
+ format.json {redirect_to :action => 'show', :format => 'json', :key => @key.key}
13
+ format.xml {redirect_to :action => 'show', :format => 'xml', :key => @key.key}
14
+ end
15
+ else
16
+ respond_to do |format|
17
+ format.json
18
+ format.xml
19
+ end
20
+ end
21
+ end
22
+
23
+ def show
24
+ if params[:key]
25
+ @key = ApiKey.find_by_key(params[:key])
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,4 @@
1
+ module Cadinsor
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Cadinsor
2
+ module ApiKeysHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Cadinsor
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,19 @@
1
+ module Cadinsor
2
+ class ApiKey < ActiveRecord::Base
3
+ belongs_to :client_app
4
+ validates_presence_of :key
5
+
6
+ def generate_key!
7
+ self.key = SecureRandom.urlsafe_base64(32)
8
+ generate_key! if Cadinsor::ApiKey.find_by_key(self.key)
9
+ # Return object for chaining requests
10
+ self
11
+ end
12
+
13
+ def expired?
14
+ return true if self.created_at < Cadinsor::Engine.config.key_expiry_time_in_mins.to_i.minutes.ago
15
+ false
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ module Cadinsor
2
+ class ClientApp < ActiveRecord::Base
3
+ validates_presence_of :name,:secret
4
+ validates_uniqueness_of :name, :secret
5
+
6
+ def generate_secret!
7
+ self.secret = SecureRandom.urlsafe_base64(32)
8
+ generate_secret! if ClientApp.find_by_secret(self.secret)
9
+ self
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ object @key
2
+ node(:status) {"Error."}
3
+ node(:errors) {|key| key.errors.full_messages}
@@ -0,0 +1,10 @@
1
+ object @key
2
+ if !@key
3
+ node(:status) {"Error."}
4
+ node(:errors) {"No valid key found with id: " + params[:id].to_s}
5
+ else
6
+ node(:status) {"Success."}
7
+ attribute :key
8
+ attribute :created_at
9
+ node(:expired) {|key| key.expired?}
10
+ end
@@ -0,0 +1,3 @@
1
+ object :false
2
+ node(:status) {"Error."}
3
+ node(:errors) {@cadinsor_error_message}
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Cadinsor</title>
5
+ <%= stylesheet_link_tag "cadinsor/application", media: "all" %>
6
+ <%= javascript_include_tag "cadinsor/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,4 @@
1
+ require 'rabl'
2
+ Rabl.configure do |config|
3
+ config.include_json_root = false
4
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,4 @@
1
+ Cadinsor::Engine.routes.draw do
2
+ get 'api_keys/create', :responds => [:json, :xml]
3
+ get 'api_keys/show', :responds => [:json, :xml]
4
+ end
@@ -0,0 +1,9 @@
1
+ class CreateCadinsorClientApps < ActiveRecord::Migration
2
+ def change
3
+ create_table :cadinsor_client_apps do |t|
4
+ t.string :name
5
+ t.string :secret
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ class CreateCadinsorApiKeys < ActiveRecord::Migration
2
+ def change
3
+ create_table :cadinsor_api_keys do |t|
4
+ t.string :key
5
+ t.integer :client_app_id
6
+ t.timestamps
7
+ end
8
+ add_index :cadinsor_api_keys, :key
9
+ end
10
+ end
data/lib/cadinsor.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "cadinsor/engine"
2
+ require "cadinsor/extensions"
3
+ require "cadinsor/extensions/request_error"
4
+
5
+ module Cadinsor
6
+ end
@@ -0,0 +1,10 @@
1
+ module Cadinsor
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Cadinsor
4
+ # Set key expiry time in minutes
5
+ self.config.key_expiry_time_in_mins = 5
6
+ self.config.client_app_id_param_name = :client_app_id
7
+ self.config.api_key_param_name = :api_key
8
+ self.config.request_signature_param_name = :signature
9
+ end
10
+ end
@@ -0,0 +1,61 @@
1
+ module Cadinsor
2
+ module Extensions
3
+
4
+ def check_request_with_cadinsor(options = {})
5
+ options[:target_params] ? target_params = options[:target_params] : target_params = params
6
+ target_params = cadinsor_flatten_params(target_params)
7
+ api_key = target_params[Cadinsor::Engine.config.api_key_param_name.to_s]
8
+ signature = target_params[Cadinsor::Engine.config.request_signature_param_name.to_s]
9
+ client_app_id = target_params[Cadinsor::Engine.config.client_app_id_param_name.to_s]
10
+ cadinsor_validate_key(api_key) if options[:ignore_api_key_check] != true
11
+ cadinsor_validate_app(client_app_id)
12
+ cadinsor_validate_signature(target_params, signature, Cadinsor::Engine.config.client_app_id_param_name.to_s, Cadinsor::Engine.config.request_signature_param_name.to_s)
13
+ end
14
+
15
+ def cadinsor_flatten_params(parameter_hash, key_prefix = "")
16
+ flattened_hash = {}
17
+ parameter_hash.keys.each do |key|
18
+ if parameter_hash[key].is_a? Hash
19
+ key_prefix == "" ? flatten_prefix = key.to_s : flatten_prefix = key_prefix + "_" + key.to_s
20
+ flattened_hash.merge! cadinsor_flatten_params(parameter_hash[key], flatten_prefix)
21
+ else
22
+ key_prefix == "" ? flattened_hash.merge!({key.to_s => parameter_hash[key]}) : flattened_hash.merge!({(key_prefix.to_s + "_" + key.to_s) => parameter_hash[key]})
23
+ end
24
+ end
25
+ flattened_hash
26
+ end
27
+
28
+ def cadinsor_validate_key(api_key)
29
+ raise Cadinsor::Extensions::RequestError.new "Invalid Request. Key not present in request." if api_key.to_s == ""
30
+ key = Cadinsor::ApiKey.find_by_key(api_key)
31
+ raise Cadinsor::Extensions::RequestError.new "Invalid Request. Key is not valid." if !key
32
+ raise Cadinsor::Extensions::RequestError.new "Invalid Request. Key has expired. Please use a new key." if key.expired?
33
+ end
34
+
35
+ def cadinsor_rescue(message)
36
+ @cadinsor_error_message = message
37
+ respond_to do |format|
38
+ format.json {render "cadinsor/application/cadinsor_error_response", format: 'json'}
39
+ format.xml {render "/cadinsor/application/cadinsor_error_response", format: 'xml'}
40
+ end
41
+ end
42
+
43
+ def cadinsor_validate_app(app_id)
44
+ raise Cadinsor::Extensions::RequestError.new "Invalid Request. Client App id is not present in request." if app_id.to_s == ""
45
+ app = Cadinsor::ClientApp.find_by_id(app_id)
46
+ raise Cadinsor::Extensions::RequestError.new "Invalid Request. Client App is not valid." if !app
47
+ end
48
+
49
+ def cadinsor_validate_signature(params, signature, app_id_param_name, signature_param_name)
50
+ raise Cadinsor::Extensions::RequestError.new "Invalid Request. Request signature is not present." if signature.to_s == ""
51
+ req_string = ""
52
+ params.keys.sort.each do |key|
53
+ req_string = req_string + params[key] unless [signature_param_name.to_s, "controller", "action", "format"].include? key.to_s
54
+ end
55
+ req_string = req_string + Cadinsor::ClientApp.find_by_id(params[app_id_param_name.to_s]).secret
56
+ request_hash = Digest::SHA2.hexdigest(req_string)
57
+ raise Cadinsor::Extensions::RequestError.new "Invalid Request. Request Signature is not valid." if signature != request_hash
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,6 @@
1
+ module Cadinsor
2
+ module Extensions
3
+ class RequestError < StandardError
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module Cadinsor
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,7 @@
1
+ Description:
2
+ This generator will create an initializer called cadinsor.rb in config/initializers, which is necessary for running the Cadinsor gem.
3
+ Please visit the github page: http://github.com/lewstherin/cadinsor for more details on the various configuration options etc.
4
+
5
+ Do not forget to run rake db:migrate after running this initializer.
6
+
7
+