simple_api_auth 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/simple_api_auth/simple_api_auth.rb +12 -11
- data/simple_api_auth.gemspec +1 -1
- metadata +60 -74
data/Gemfile.lock
CHANGED
@@ -1,35 +1,36 @@
|
|
1
1
|
module SimpleApiAuth
|
2
|
-
|
2
|
+
|
3
3
|
class Middleware
|
4
|
-
|
4
|
+
|
5
5
|
@@api_path_matcher = /^\/api\//
|
6
6
|
@@unauthorized_response = [401, {"Content-Type" => "text/plain"}, ['{ "message": "Unauthenticated." }']]
|
7
|
-
|
7
|
+
|
8
8
|
def self.api_key=(key)
|
9
9
|
@@api_key = key
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def initialize(app)
|
13
13
|
@app = app
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def call(env)
|
17
17
|
path = env['PATH_INFO']
|
18
18
|
if path =~ @@api_path_matcher
|
19
|
-
api_key = env["HTTP_AUTHORIZATION"] || Rack::Request.new(env).params['api_key']
|
19
|
+
api_key = env["HTTP_AUTHORIZATION"] || Rack::Request.new(env).params['api_key']
|
20
20
|
unless api_key == @@api_key
|
21
|
+
env['rack.errors'].write "throw 401 from SimpleApiAuth. got api_key: #{api_key.inspect} \n"
|
21
22
|
return @@unauthorized_response
|
22
23
|
end
|
23
24
|
end
|
24
|
-
|
25
|
+
|
25
26
|
@app.call(env)
|
26
27
|
end
|
27
|
-
|
28
|
+
|
28
29
|
end
|
29
|
-
|
30
|
+
|
30
31
|
def self.generate(length = 40)
|
31
32
|
require "digest/sha1"
|
32
33
|
Digest::SHA1.hexdigest(Time.now.to_s + rand(99999999).to_s)[0..length-1]
|
33
34
|
end
|
34
|
-
|
35
|
-
end
|
35
|
+
|
36
|
+
end
|
data/simple_api_auth.gemspec
CHANGED
metadata
CHANGED
@@ -1,76 +1,71 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_api_auth
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 4
|
10
|
-
version: 0.0.4
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Wen-Tien Chang
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-04-20 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: rack
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
33
22
|
type: :runtime
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: rspec
|
37
23
|
prerelease: false
|
38
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
25
|
none: false
|
40
|
-
requirements:
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
41
35
|
- - ~>
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
segments:
|
45
|
-
- 2
|
46
|
-
- 5
|
47
|
-
version: "2.5"
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '2.5'
|
48
38
|
type: :development
|
49
|
-
version_requirements: *id002
|
50
|
-
- !ruby/object:Gem::Dependency
|
51
|
-
name: json
|
52
39
|
prerelease: false
|
53
|
-
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
41
|
none: false
|
55
|
-
requirements:
|
56
|
-
- -
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '2.5'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: json
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
62
54
|
type: :development
|
63
|
-
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
64
62
|
description: A Rack middleware and Railtie(for Rails3) for API key authentication.
|
65
|
-
email:
|
63
|
+
email:
|
66
64
|
- ihower@gmail.com
|
67
65
|
executables: []
|
68
|
-
|
69
66
|
extensions: []
|
70
|
-
|
71
67
|
extra_rdoc_files: []
|
72
|
-
|
73
|
-
files:
|
68
|
+
files:
|
74
69
|
- .gitignore
|
75
70
|
- Gemfile
|
76
71
|
- Gemfile.lock
|
@@ -82,40 +77,31 @@ files:
|
|
82
77
|
- simple_api_auth.gemspec
|
83
78
|
- spec/lib/simple_api_auth_spec.rb
|
84
79
|
- spec/spec_helper.rb
|
85
|
-
has_rdoc: true
|
86
80
|
homepage: https://github.com/ihower/simple_api_auth
|
87
81
|
licenses: []
|
88
|
-
|
89
82
|
post_install_message:
|
90
83
|
rdoc_options: []
|
91
|
-
|
92
|
-
require_paths:
|
84
|
+
require_paths:
|
93
85
|
- lib
|
94
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
87
|
none: false
|
96
|
-
requirements:
|
97
|
-
- -
|
98
|
-
- !ruby/object:Gem::Version
|
99
|
-
|
100
|
-
|
101
|
-
- 0
|
102
|
-
version: "0"
|
103
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
93
|
none: false
|
105
|
-
requirements:
|
106
|
-
- -
|
107
|
-
- !ruby/object:Gem::Version
|
108
|
-
|
109
|
-
segments:
|
110
|
-
- 0
|
111
|
-
version: "0"
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
112
98
|
requirements: []
|
113
|
-
|
114
99
|
rubyforge_project:
|
115
|
-
rubygems_version: 1.
|
100
|
+
rubygems_version: 1.8.19
|
116
101
|
signing_key:
|
117
102
|
specification_version: 3
|
118
103
|
summary: Simple API Key Authentication
|
119
|
-
test_files:
|
104
|
+
test_files:
|
120
105
|
- spec/lib/simple_api_auth_spec.rb
|
121
106
|
- spec/spec_helper.rb
|
107
|
+
has_rdoc:
|