restful_api_authentication 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YzhiYTFiNWY3ODVjMTAyMWU3YWMyZWFjZTI2MzI3MThkZDRjMTQxMQ==
5
+ data.tar.gz: !binary |-
6
+ YmZmZTM0NDhlMzZmZDgzMTFjMGQ1MTdlZDMyMTNjYTVlNjExNTA2OA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MDZiNWUwNWMwNmU4ZDRkNzJjODlmYmJhNjhiZTc4MjdiNzBhZjBjYzBkZTU3
10
+ ZWIxYjAyOWFhOWZmZTNkNDEyYjY2YTdjYzVjOGIzYmI4Njg0ZWI2MDhjM2Ex
11
+ NGI3NmYzNjlkM2ZmOGZlZDc2YTE2ZmMxMGI2ODkyNjY3NzE2MjI=
12
+ data.tar.gz: !binary |-
13
+ ZjUzZDhkZWRkMmIyODU5ZDdhNTFlZWMwZmJhZmVlN2IyMzUwZGQxNTdkMTA1
14
+ YTVkODEzMTVjNjc0Y2NlNDIyODgyNThkYTkwOWQ1YjgwMDEyOWJlNmU0Nzdk
15
+ MmRkMGMyMTI0MTdjYzAwOWRmMTZhZWY3MjM2MDJiNDU3OTZhOGQ=
@@ -1,5 +1,8 @@
1
1
  # Change History / Release Notes
2
2
 
3
+ ## Version 0.3.0
4
+ * Added an is_disabled flag to the RestClient model. This allows clients to be disabled without deleting them from the database, so their credentials remain if you ever want to enable them in the future.
5
+
3
6
  ## Version 0.2.2
4
7
  * Closed Issue #5 - Improperly formatted timestamps result in an uncaught exception
5
8
 
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 David Kiger
1
+ Copyright (c) 2012-2013 David Kiger
2
2
 
3
3
  MIT License
4
4
 
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
19
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
20
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
21
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -6,6 +6,7 @@ class CreateRestClient < ActiveRecord::Migration
6
6
  t.string :api_key
7
7
  t.string :secret
8
8
  t.boolean :is_master
9
+ t.boolean :disabled
9
10
  t.timestamps
10
11
  end
11
12
  end
@@ -30,6 +30,7 @@ class RestClient < ActiveRecord::Base
30
30
  self.gen_api_key if self.api_key.nil? || self.api_key == ""
31
31
  self.gen_secret if self.secret.nil? || self.secret == ""
32
32
  self.is_master = false if self.is_master.nil?
33
+ self.is_disabled = false if self.is_disabled.nil?
33
34
  return true
34
35
  end
35
36
 
@@ -1,4 +1,5 @@
1
1
  defaults: &DEFAULTS
2
+ disabled_message: "This client is currently disabled and cannot make calls to this API."
2
3
  request_window: 10 # request window in minutes - between 5 and 10 is usually best; must be at least 2
3
4
  verbose_errors: false # if false, error response will always be "not authorized", otherwise it will be more descriptive of why authentication failed
4
5
  header_names: # names of HTTP headers that must be sent on all requests requiring authentication
@@ -24,7 +24,7 @@
24
24
  module RestfulApiAuthentication
25
25
  class Checker
26
26
  # Class attributes which are set when the Rails application is initialized: locally cached version of configuration settings stored in YML file.
27
- cattr_accessor :header_timestamp, :header_signature, :header_api_key, :time_window, :verbose_errors
27
+ cattr_accessor :header_timestamp, :header_signature, :header_api_key, :time_window, :verbose_errors, :disabled_message
28
28
  attr_accessor :http_headers, :request_uri, :errors
29
29
 
30
30
  def initialize(http_headers, request_uri)
@@ -35,11 +35,15 @@ module RestfulApiAuthentication
35
35
 
36
36
  # Checks if the current request passes authorization
37
37
  def authorized?(options = {})
38
- raise "Configuration values not found. Please run rails g restful_api_authentication:install to generate a config file." if @@header_timestamp.nil? || @@header_signature.nil? || @@header_api_key.nil? || @@time_window.nil?
38
+ raise "Configuration values not found. Please run rails g restful_api_authentication:install to generate a config file." if @@header_timestamp.nil? || @@header_signature.nil? || @@header_api_key.nil? || @@time_window.nil? || @@disabled_message.nil?
39
39
  return_val = false
40
40
  if headers_have_values?
41
41
  if in_time_window?
42
42
  if test_hash.downcase == @http_headers[@@header_signature].downcase
43
+ if is_disabled?
44
+ @errors << @@disabled_message
45
+ return false
46
+ end
43
47
  if options[:require_master] == true
44
48
  if is_master?
45
49
  return_val = true
@@ -66,6 +70,14 @@ module RestfulApiAuthentication
66
70
 
67
71
  private
68
72
 
73
+ # determines if a RestClient is disabled or not
74
+ def is_disabled?
75
+ client = RestClient.where(:api_key => @http_headers[@@header_api_key]).first
76
+ return true if client.nil?
77
+ return false if client.is_disabled.nil?
78
+ client.is_disabled
79
+ end
80
+
69
81
  # determines if a RestClient has master privileges or not
70
82
  def is_master?
71
83
  client = RestClient.where(:api_key => @http_headers[@@header_api_key]).first
@@ -29,9 +29,11 @@ module RestfulApiAuthentication
29
29
  RestfulApiAuthentication::Checker.header_signature = 'x-signature'
30
30
  RestfulApiAuthentication::Checker.header_api_key = 'x-api-key'
31
31
  RestfulApiAuthentication::Checker.verbose_errors = false
32
+ RestfulApiAuthentication::Checker.disabled_message = 'This client is disabled and cannot make calls to this API.'
32
33
  if File.exists? Rails.root.join('config', 'restful_api_authentication.yml')
33
34
  begin
34
35
  config_data = YAML::load_file(Rails.root.join('config', 'restful_api_authentication.yml'))[Rails.env]
36
+ RestfulApiAuthentication::Checker.disabled_message = config_data['disabled_message'] unless config_data['disabled_message'].nil?
35
37
  RestfulApiAuthentication::Checker.time_window = config_data['request_window'].to_i unless config_data['request_window'].nil?
36
38
  RestfulApiAuthentication::Checker.header_timestamp = config_data['header_names']['timestamp'] unless config_data['header_names'].nil? or config_data['header_names']['timestamp'].nil?
37
39
  RestfulApiAuthentication::Checker.header_signature = config_data['header_names']['signature'] unless config_data['header_names'].nil? or config_data['header_names']['signature'].nil?
@@ -22,5 +22,5 @@
22
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
 
24
24
  module RestfulApiAuthentication
25
- VERSION = "0.2.3"
25
+ VERSION = "0.3.0"
26
26
  end
metadata CHANGED
@@ -1,49 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restful_api_authentication
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
5
- prerelease:
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Dave Kiger
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-13 00:00:00.000000000 Z
11
+ date: 2013-11-14 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rails
16
- requirement: &70257440207460 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: 3.2.0
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *70257440207460
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 3.2.0
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: uuid
27
- requirement: &70257440206640 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
31
  - - ! '>='
31
32
  - !ruby/object:Gem::Version
32
33
  version: 2.3.5
33
34
  type: :runtime
34
35
  prerelease: false
35
- version_requirements: *70257440206640
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 2.3.5
36
41
  - !ruby/object:Gem::Dependency
37
42
  name: chronic
38
- requirement: &70257440205960 !ruby/object:Gem::Requirement
39
- none: false
43
+ requirement: !ruby/object:Gem::Requirement
40
44
  requirements:
41
45
  - - ! '>='
42
46
  - !ruby/object:Gem::Version
43
47
  version: 0.6.7
44
48
  type: :runtime
45
49
  prerelease: false
46
- version_requirements: *70257440205960
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.6.7
47
55
  description: A gem which implements a standard api_key / secret authentication system
48
56
  for your Ruby on Rails RESTful web services.
49
57
  email:
@@ -68,30 +76,28 @@ files:
68
76
  - restful_api_authentication.gemspec
69
77
  homepage: http://davejkiger.github.com/restful_api_authentication/
70
78
  licenses: []
79
+ metadata: {}
71
80
  post_install_message:
72
81
  rdoc_options: []
73
82
  require_paths:
74
83
  - lib
75
84
  required_ruby_version: !ruby/object:Gem::Requirement
76
- none: false
77
85
  requirements:
78
86
  - - ! '>='
79
87
  - !ruby/object:Gem::Version
80
88
  version: '0'
81
89
  required_rubygems_version: !ruby/object:Gem::Requirement
82
- none: false
83
90
  requirements:
84
91
  - - ! '>='
85
92
  - !ruby/object:Gem::Version
86
93
  version: '0'
87
94
  requirements: []
88
95
  rubyforge_project:
89
- rubygems_version: 1.8.17
96
+ rubygems_version: 2.1.10
90
97
  signing_key:
91
- specification_version: 3
98
+ specification_version: 4
92
99
  summary: With most RESTful Web API's, it is important to know which app is using your
93
100
  resources and that only the apps you allow access those resources. This gem allows
94
101
  you to easily add this layer of authentication to any Rails RESTful resource you
95
102
  want, and it even includes protection against various forms of attack.
96
103
  test_files: []
97
- has_rdoc: