bixby-auth 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 58232e00fb92f8ace02f941943e67a6cb8e64508
4
+ data.tar.gz: 18a1d58a81c8ff2a4aa9baf6148db4d78ee2c11a
5
+ SHA512:
6
+ metadata.gz: f329d1953f45daa94c406cec32ba73c80040e7c69103bf63fa272529072300208626d2d139be476d204eae2980578e1c7aef39dd4701c5ce7b0ed96cde205510
7
+ data.tar.gz: b63a762438d45f82872599510ce4013403e0946bcf2326a2d2ea0d4c8d548f3f71507c7bf67ec14138ab795f53df746f97bf03e2b5b3d621b78e3a6704fb22fc
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,28 @@
1
+ source "https://rubygems.org"
2
+
3
+ group :development do
4
+ gem "rake", "~> 10.3"
5
+ gem "pry", "~> 0.10"
6
+ gem "yard", "~> 0.7"
7
+ gem "bundler", "~> 1.0"
8
+ gem "jeweler", "~> 2.0.1", :github => "chetan/jeweler", :branch => "bixby"
9
+
10
+ gem "bixby-common", "~> 0.4"
11
+
12
+
13
+ gem "micron", :github => "chetan/micron"
14
+ gem "test_guard", :github => "chetan/test_guard"
15
+ gem 'rb-inotify', :require => false
16
+ gem 'rb-fsevent', :require => false
17
+ gem 'rb-fchange', :require => false
18
+
19
+ gem "oj"
20
+ gem "rspec"
21
+ gem "amatch"
22
+ gem "rails"
23
+ gem "activeresource"
24
+ gem "rest-client", "~> 1.6.0"
25
+ gem "curb", "~> 0.8.1"
26
+ gem "httpi"
27
+
28
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,245 @@
1
+ GIT
2
+ remote: git://github.com/chetan/jeweler.git
3
+ revision: b90381a3958daae7f3ce3d8c4d710fe39e72443b
4
+ branch: bixby
5
+ specs:
6
+ jeweler (2.0.1)
7
+ builder
8
+ bundler (>= 1.0)
9
+ git (>= 1.2.5)
10
+ github_api
11
+ highline (>= 1.6.15)
12
+ nokogiri (>= 1.5.10)
13
+ rake
14
+
15
+ GIT
16
+ remote: git://github.com/chetan/micron.git
17
+ revision: 0c1e9c0b9d9e052805f43485fe3454cbd25913c5
18
+ specs:
19
+ micron (0.5.1)
20
+ ansi
21
+ easycov
22
+ hitimes
23
+
24
+ GIT
25
+ remote: git://github.com/chetan/test_guard.git
26
+ revision: 178e47e2e57dc83060d6cabc18f206916b9d02f2
27
+ specs:
28
+ test_guard (0.2.1)
29
+ awesome_print
30
+ easycov
31
+ growl
32
+ listen
33
+ simplecov
34
+ simplecov-console
35
+
36
+ GEM
37
+ remote: https://rubygems.org/
38
+ specs:
39
+ actionmailer (4.1.8)
40
+ actionpack (= 4.1.8)
41
+ actionview (= 4.1.8)
42
+ mail (~> 2.5, >= 2.5.4)
43
+ actionpack (4.1.8)
44
+ actionview (= 4.1.8)
45
+ activesupport (= 4.1.8)
46
+ rack (~> 1.5.2)
47
+ rack-test (~> 0.6.2)
48
+ actionview (4.1.8)
49
+ activesupport (= 4.1.8)
50
+ builder (~> 3.1)
51
+ erubis (~> 2.7.0)
52
+ activemodel (4.1.8)
53
+ activesupport (= 4.1.8)
54
+ builder (~> 3.1)
55
+ activerecord (4.1.8)
56
+ activemodel (= 4.1.8)
57
+ activesupport (= 4.1.8)
58
+ arel (~> 5.0.0)
59
+ activeresource (4.0.0)
60
+ activemodel (~> 4.0)
61
+ activesupport (~> 4.0)
62
+ rails-observers (~> 0.1.1)
63
+ activesupport (4.1.8)
64
+ i18n (~> 0.6, >= 0.6.9)
65
+ json (~> 1.7, >= 1.7.7)
66
+ minitest (~> 5.1)
67
+ thread_safe (~> 0.1)
68
+ tzinfo (~> 1.1)
69
+ addressable (2.3.6)
70
+ amatch (0.2.11)
71
+ tins (~> 0.3)
72
+ ansi (1.4.3)
73
+ api-auth (1.0.3)
74
+ arel (5.0.1.20140414130214)
75
+ awesome_print (1.2.0)
76
+ bixby-common (0.4.13)
77
+ api-auth (~> 1.0)
78
+ faye-websocket (~> 0.7)
79
+ httpi (~> 2.1)
80
+ logging (~> 1.8)
81
+ multi_json (~> 1.8)
82
+ semver2 (~> 3.3)
83
+ builder (3.2.2)
84
+ celluloid (0.16.0)
85
+ timers (~> 4.0.0)
86
+ coderay (1.1.0)
87
+ colorize (0.7.3)
88
+ curb (0.8.6)
89
+ descendants_tracker (0.0.4)
90
+ thread_safe (~> 0.3, >= 0.3.1)
91
+ diff-lcs (1.2.5)
92
+ docile (1.1.5)
93
+ easycov (0.4.0)
94
+ multi_json
95
+ simplecov
96
+ simplecov-console
97
+ simplecov-html
98
+ erubis (2.7.0)
99
+ eventmachine (1.0.3)
100
+ faraday (0.9.0)
101
+ multipart-post (>= 1.2, < 3)
102
+ faye-websocket (0.7.4)
103
+ eventmachine (>= 0.12.0)
104
+ websocket-driver (>= 0.3.1)
105
+ ffi (1.9.6)
106
+ git (1.2.8)
107
+ github_api (0.12.2)
108
+ addressable (~> 2.3)
109
+ descendants_tracker (~> 0.0.4)
110
+ faraday (~> 0.8, < 0.10)
111
+ hashie (>= 3.3)
112
+ multi_json (>= 1.7.5, < 2.0)
113
+ nokogiri (~> 1.6.3)
114
+ oauth2
115
+ growl (1.0.3)
116
+ hashie (3.3.1)
117
+ highline (1.6.21)
118
+ hike (1.2.3)
119
+ hirb (0.7.2)
120
+ hitimes (1.2.2)
121
+ httpi (2.2.7)
122
+ rack
123
+ i18n (0.6.11)
124
+ json (1.8.1)
125
+ jwt (1.0.0)
126
+ listen (2.8.0)
127
+ celluloid (>= 0.15.2)
128
+ rb-fsevent (>= 0.9.3)
129
+ rb-inotify (>= 0.9)
130
+ little-plugger (1.1.3)
131
+ logging (1.8.2)
132
+ little-plugger (>= 1.1.3)
133
+ multi_json (>= 1.8.4)
134
+ mail (2.6.3)
135
+ mime-types (>= 1.16, < 3)
136
+ method_source (0.8.2)
137
+ mime-types (2.4.3)
138
+ mini_portile (0.6.1)
139
+ minitest (5.4.3)
140
+ multi_json (1.10.1)
141
+ multi_xml (0.5.5)
142
+ multipart-post (2.0.0)
143
+ nokogiri (1.6.4.1)
144
+ mini_portile (~> 0.6.0)
145
+ oauth2 (1.0.0)
146
+ faraday (>= 0.8, < 0.10)
147
+ jwt (~> 1.0)
148
+ multi_json (~> 1.3)
149
+ multi_xml (~> 0.5)
150
+ rack (~> 1.2)
151
+ oj (2.10.2)
152
+ pry (0.10.1)
153
+ coderay (~> 1.1.0)
154
+ method_source (~> 0.8.1)
155
+ slop (~> 3.4)
156
+ rack (1.5.2)
157
+ rack-test (0.6.2)
158
+ rack (>= 1.0)
159
+ rails (4.1.8)
160
+ actionmailer (= 4.1.8)
161
+ actionpack (= 4.1.8)
162
+ actionview (= 4.1.8)
163
+ activemodel (= 4.1.8)
164
+ activerecord (= 4.1.8)
165
+ activesupport (= 4.1.8)
166
+ bundler (>= 1.3.0, < 2.0)
167
+ railties (= 4.1.8)
168
+ sprockets-rails (~> 2.0)
169
+ rails-observers (0.1.2)
170
+ activemodel (~> 4.0)
171
+ railties (4.1.8)
172
+ actionpack (= 4.1.8)
173
+ activesupport (= 4.1.8)
174
+ rake (>= 0.8.7)
175
+ thor (>= 0.18.1, < 2.0)
176
+ rake (10.3.2)
177
+ rb-fchange (0.0.6)
178
+ ffi
179
+ rb-fsevent (0.9.4)
180
+ rb-inotify (0.9.5)
181
+ ffi (>= 0.5.0)
182
+ rest-client (1.6.7)
183
+ mime-types (>= 1.16)
184
+ rspec (2.14.1)
185
+ rspec-core (~> 2.14.0)
186
+ rspec-expectations (~> 2.14.0)
187
+ rspec-mocks (~> 2.14.0)
188
+ rspec-core (2.14.5)
189
+ rspec-expectations (2.14.2)
190
+ diff-lcs (>= 1.1.3, < 2.0)
191
+ rspec-mocks (2.14.3)
192
+ semver2 (3.4.0)
193
+ simplecov (0.9.1)
194
+ docile (~> 1.1.0)
195
+ multi_json (~> 1.0)
196
+ simplecov-html (~> 0.8.0)
197
+ simplecov-console (0.2.0)
198
+ colorize
199
+ hirb
200
+ simplecov
201
+ simplecov-html (0.8.0)
202
+ slop (3.6.0)
203
+ sprockets (2.12.3)
204
+ hike (~> 1.2)
205
+ multi_json (~> 1.0)
206
+ rack (~> 1.0)
207
+ tilt (~> 1.1, != 1.3.0)
208
+ sprockets-rails (2.2.0)
209
+ actionpack (>= 3.0)
210
+ activesupport (>= 3.0)
211
+ sprockets (>= 2.8, < 4.0)
212
+ thor (0.19.1)
213
+ thread_safe (0.3.4)
214
+ tilt (1.4.1)
215
+ timers (4.0.1)
216
+ hitimes
217
+ tins (0.12.0)
218
+ tzinfo (1.2.2)
219
+ thread_safe (~> 0.1)
220
+ websocket-driver (0.3.4)
221
+ yard (0.8.7.6)
222
+
223
+ PLATFORMS
224
+ ruby
225
+
226
+ DEPENDENCIES
227
+ activeresource
228
+ amatch
229
+ bixby-common (~> 0.4)
230
+ bundler (~> 1.0)
231
+ curb (~> 0.8.1)
232
+ httpi
233
+ jeweler (~> 2.0.1)!
234
+ micron!
235
+ oj
236
+ pry (~> 0.10)
237
+ rails
238
+ rake (~> 10.3)
239
+ rb-fchange
240
+ rb-fsevent
241
+ rb-inotify
242
+ rest-client (~> 1.6.0)
243
+ rspec
244
+ test_guard!
245
+ yard (~> 0.7)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Chetan Sarva
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,19 @@
1
+ = bixby-auth
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to bixby-auth
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2014 Chetan Sarva. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "bixby-auth"
18
+ gem.homepage = "http://github.com/chetan/bixby-auth"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Bixby API Auth library}
21
+ gem.description = %Q{Bixby API Auth library for both clients and servers}
22
+ gem.email = "chetan@pixelcop.net"
23
+ gem.authors = ["Chetan Sarva"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ # require 'rake/testtask'
29
+ # Rake::TestTask.new(:test) do |test|
30
+ # test.libs << 'lib' << 'test'
31
+ # test.pattern = 'test/**/test_*.rb'
32
+ # test.verbose = true
33
+ # end
34
+
35
+ desc "Code coverage detail"
36
+ task :simplecov do
37
+ ENV['COVERAGE'] = "true"
38
+ Rake::Task['test'].execute
39
+ end
40
+
41
+ task :default => :test
42
+
43
+ require 'yard'
44
+ YARD::Rake::YardocTask.new
45
+
46
+
47
+ require 'rspec/core'
48
+ require 'rspec/core/rake_task'
49
+
50
+ RSpec::Core::RakeTask.new(:spec) do |spec|
51
+ spec.pattern = FileList['spec/**/*_spec.rb']
52
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,129 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: bixby-auth 0.1.0 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "bixby-auth"
9
+ s.version = "0.1.0"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
13
+ s.authors = ["Chetan Sarva"]
14
+ s.date = "2014-11-20"
15
+ s.description = "Bixby API Auth library for both clients and servers"
16
+ s.email = "chetan@pixelcop.net"
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.md"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.md",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "bixby-auth.gemspec",
30
+ "lib/api-auth.rb",
31
+ "lib/api_auth.rb",
32
+ "lib/api_auth/base.rb",
33
+ "lib/api_auth/errors.rb",
34
+ "lib/api_auth/headers.rb",
35
+ "lib/api_auth/helpers.rb",
36
+ "lib/api_auth/railtie.rb",
37
+ "lib/api_auth/request_drivers.rb",
38
+ "lib/api_auth/request_drivers/action_controller.rb",
39
+ "lib/api_auth/request_drivers/action_dispatch.rb",
40
+ "lib/api_auth/request_drivers/bixby_request.rb",
41
+ "lib/api_auth/request_drivers/curb.rb",
42
+ "lib/api_auth/request_drivers/httpi.rb",
43
+ "lib/api_auth/request_drivers/net_http.rb",
44
+ "lib/api_auth/request_drivers/rack.rb",
45
+ "lib/api_auth/request_drivers/rest_client.rb",
46
+ "lib/bixby-auth.rb",
47
+ "spec/api_auth_spec.rb",
48
+ "spec/application_helper.rb",
49
+ "spec/fixtures/upload.png",
50
+ "spec/headers_spec.rb",
51
+ "spec/helpers_spec.rb",
52
+ "spec/railtie_spec.rb",
53
+ "spec/spec_helper.rb",
54
+ "spec/test_helper.rb",
55
+ "test/helper.rb",
56
+ "test/test_bixby-auth.rb"
57
+ ]
58
+ s.homepage = "http://github.com/chetan/bixby-auth"
59
+ s.licenses = ["MIT"]
60
+ s.rubygems_version = "2.4.2"
61
+ s.summary = "Bixby API Auth library"
62
+
63
+ if s.respond_to? :specification_version then
64
+ s.specification_version = 4
65
+
66
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
67
+ s.add_development_dependency(%q<rake>, ["~> 10.3"])
68
+ s.add_development_dependency(%q<pry>, ["~> 0.10"])
69
+ s.add_development_dependency(%q<yard>, ["~> 0.7"])
70
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
71
+ s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
72
+ s.add_development_dependency(%q<bixby-common>, ["~> 0.4"])
73
+ s.add_development_dependency(%q<micron>, [">= 0"])
74
+ s.add_development_dependency(%q<test_guard>, [">= 0"])
75
+ s.add_development_dependency(%q<rb-inotify>, [">= 0"])
76
+ s.add_development_dependency(%q<rb-fsevent>, [">= 0"])
77
+ s.add_development_dependency(%q<rb-fchange>, [">= 0"])
78
+ s.add_development_dependency(%q<oj>, [">= 0"])
79
+ s.add_development_dependency(%q<rspec>, [">= 0"])
80
+ s.add_development_dependency(%q<amatch>, [">= 0"])
81
+ s.add_development_dependency(%q<rails>, [">= 0"])
82
+ s.add_development_dependency(%q<activeresource>, [">= 0"])
83
+ s.add_development_dependency(%q<rest-client>, ["~> 1.6.0"])
84
+ s.add_development_dependency(%q<curb>, ["~> 0.8.1"])
85
+ s.add_development_dependency(%q<httpi>, [">= 0"])
86
+ else
87
+ s.add_dependency(%q<rake>, ["~> 10.3"])
88
+ s.add_dependency(%q<pry>, ["~> 0.10"])
89
+ s.add_dependency(%q<yard>, ["~> 0.7"])
90
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
91
+ s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
92
+ s.add_dependency(%q<bixby-common>, ["~> 0.4"])
93
+ s.add_dependency(%q<micron>, [">= 0"])
94
+ s.add_dependency(%q<test_guard>, [">= 0"])
95
+ s.add_dependency(%q<rb-inotify>, [">= 0"])
96
+ s.add_dependency(%q<rb-fsevent>, [">= 0"])
97
+ s.add_dependency(%q<rb-fchange>, [">= 0"])
98
+ s.add_dependency(%q<oj>, [">= 0"])
99
+ s.add_dependency(%q<rspec>, [">= 0"])
100
+ s.add_dependency(%q<amatch>, [">= 0"])
101
+ s.add_dependency(%q<rails>, [">= 0"])
102
+ s.add_dependency(%q<activeresource>, [">= 0"])
103
+ s.add_dependency(%q<rest-client>, ["~> 1.6.0"])
104
+ s.add_dependency(%q<curb>, ["~> 0.8.1"])
105
+ s.add_dependency(%q<httpi>, [">= 0"])
106
+ end
107
+ else
108
+ s.add_dependency(%q<rake>, ["~> 10.3"])
109
+ s.add_dependency(%q<pry>, ["~> 0.10"])
110
+ s.add_dependency(%q<yard>, ["~> 0.7"])
111
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
112
+ s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
113
+ s.add_dependency(%q<bixby-common>, ["~> 0.4"])
114
+ s.add_dependency(%q<micron>, [">= 0"])
115
+ s.add_dependency(%q<test_guard>, [">= 0"])
116
+ s.add_dependency(%q<rb-inotify>, [">= 0"])
117
+ s.add_dependency(%q<rb-fsevent>, [">= 0"])
118
+ s.add_dependency(%q<rb-fchange>, [">= 0"])
119
+ s.add_dependency(%q<oj>, [">= 0"])
120
+ s.add_dependency(%q<rspec>, [">= 0"])
121
+ s.add_dependency(%q<amatch>, [">= 0"])
122
+ s.add_dependency(%q<rails>, [">= 0"])
123
+ s.add_dependency(%q<activeresource>, [">= 0"])
124
+ s.add_dependency(%q<rest-client>, ["~> 1.6.0"])
125
+ s.add_dependency(%q<curb>, ["~> 0.8.1"])
126
+ s.add_dependency(%q<httpi>, [">= 0"])
127
+ end
128
+ end
129
+
data/lib/api-auth.rb ADDED
@@ -0,0 +1,2 @@
1
+ # So you can require "api-auth" instead of "api_auth"
2
+ require "api_auth"
@@ -0,0 +1,105 @@
1
+ # encoding: UTF-8
2
+ # api-auth is a Ruby gem designed to be used both in your client and server
3
+ # HTTP-based applications. It implements the same authentication methods (HMAC)
4
+ # used by Amazon Web Services.
5
+
6
+ # The gem will sign your requests on the client side and authenticate that
7
+ # signature on the server side. If your server resources are implemented as a
8
+ # Rails ActiveResource, it will integrate with that. It will even generate the
9
+ # secret keys necessary for your clients to sign their requests.
10
+ module ApiAuth
11
+
12
+ class << self
13
+
14
+ include Helpers
15
+
16
+ # Signs an HTTP request using the client's access id and secret key.
17
+ # Returns the HTTP request object with the modified headers.
18
+ #
19
+ # request: The request can be a Net::HTTP, ActionDispatch::Request,
20
+ # Curb (Curl::Easy) or a RestClient object.
21
+ #
22
+ # access_id: The public unique identifier for the client
23
+ #
24
+ # secret_key: assigned secret key that is known to both parties
25
+ def sign!(request, access_id, secret_key)
26
+ headers = Headers.new(request)
27
+ headers.calculate_md5
28
+ headers.set_date
29
+ headers.sign_header auth_header(request, access_id, secret_key)
30
+ end
31
+
32
+ # Determines if the request is authentic given the request and the client's
33
+ # secret key. Returns true if the request is authentic and false otherwise.
34
+ def authentic?(request, secret_key)
35
+ return false if secret_key.nil?
36
+
37
+ return !md5_mismatch?(request) && signatures_match?(request, secret_key) && !request_too_old?(request)
38
+ end
39
+
40
+ # Returns the access id from the request's authorization header
41
+ def access_id(request)
42
+ headers = Headers.new(request)
43
+ if match_data = parse_auth_header(headers.authorization_header)
44
+ return match_data[1]
45
+ end
46
+
47
+ nil
48
+ end
49
+
50
+ # Generates a Base64 encoded, randomized secret key
51
+ #
52
+ # Store this key along with the access key that will be used for
53
+ # authenticating the client
54
+ def generate_secret_key
55
+ random_bytes = OpenSSL::Random.random_bytes(512)
56
+ b64_encode(Digest::SHA2.new(512).digest(random_bytes))
57
+ end
58
+
59
+ private
60
+
61
+ def request_too_old?(request)
62
+ headers = Headers.new(request)
63
+ # 900 seconds is 15 minutes
64
+ begin
65
+ if Time.parse(headers.timestamp).utc < (Time.now.utc - 900) then
66
+ raise RequestTooOld, "request is more than 900 seconds old"
67
+ end
68
+ return false
69
+ rescue ArgumentError
70
+ return true
71
+ end
72
+ end
73
+
74
+ def md5_mismatch?(request)
75
+ headers = Headers.new(request)
76
+ headers.md5_mismatch?
77
+ end
78
+
79
+ def signatures_match?(request, secret_key)
80
+ headers = Headers.new(request)
81
+ if match_data = parse_auth_header(headers.authorization_header)
82
+ hmac = match_data[2]
83
+ return hmac == hmac_signature(request, secret_key)
84
+ end
85
+ false
86
+ end
87
+
88
+ def hmac_signature(request, secret_key)
89
+ headers = Headers.new(request)
90
+ canonical_string = headers.canonical_string
91
+ digest = OpenSSL::Digest.new('sha1')
92
+ b64_encode(OpenSSL::HMAC.digest(digest, secret_key, canonical_string))
93
+ end
94
+
95
+ def auth_header(request, access_id, secret_key)
96
+ "APIAuth #{access_id}:#{hmac_signature(request, secret_key)}"
97
+ end
98
+
99
+ def parse_auth_header(auth_header)
100
+ Regexp.new("APIAuth ([^:]+):(.+)$").match(auth_header)
101
+ end
102
+
103
+ end # class methods
104
+
105
+ end # ApiAuth
@@ -0,0 +1,12 @@
1
+ module ApiAuth
2
+
3
+ # :nodoc:
4
+ class ApiAuthError < StandardError; end
5
+
6
+ # Raised when the request date is too far in the past (more than 15 minutes old)
7
+ class RequestTooOld < ApiAuthError; end
8
+
9
+ # Raised when the HTTP request object passed is not supported
10
+ class UnknownHTTPRequest < ApiAuthError; end
11
+
12
+ end