moguera-authentication 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +1 -6
- data/README.md +20 -39
- data/lib/faraday/moguera_authentication.rb +41 -0
- data/lib/moguera/authentication/version.rb +1 -1
- data/lib/rack/moguera_authentication.rb +6 -6
- data/sample/Gemfile +5 -0
- data/sample/client-faraday.rb +23 -0
- data/sample/client.rb +9 -10
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c9ccff400b781421408c21d83821a8ca3c3e672
|
4
|
+
data.tar.gz: 88e99e22e2dfb9239577910591da4e4840aabeca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ed915f53a94c7cb4a51c08cc8f562b7adc027269e84147797aaf16663fcb0aab46e9faf465a4a0abf99c0e8978b9838234458e09ef32f6dd1c242323e006586
|
7
|
+
data.tar.gz: 6a837da2a49a40e2c613e704df27bb414801e27d4749af350f849d279ced8622fe7474fe76e3833c3c467b972f416d8eada832875ffce50cb3f02d303f816707
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
@@ -5,15 +5,10 @@ gemspec
|
|
5
5
|
|
6
6
|
group :test do
|
7
7
|
gem 'timecop'
|
8
|
-
gem 'pry'
|
8
|
+
gem 'pry', '< 0.10.0'
|
9
9
|
gem 'pry-byebug'
|
10
10
|
gem 'simplecov'
|
11
11
|
gem 'simplecov-rcov'
|
12
12
|
gem 'coveralls'
|
13
13
|
gem 'rack-test'
|
14
14
|
end
|
15
|
-
|
16
|
-
group :development do
|
17
|
-
gem 'rest-client'
|
18
|
-
gem 'sinatra'
|
19
|
-
end
|
data/README.md
CHANGED
@@ -125,46 +125,27 @@ end
|
|
125
125
|
|
126
126
|
### Cilent
|
127
127
|
|
128
|
-
example
|
128
|
+
example client-faraday.rb
|
129
129
|
|
130
130
|
```ruby
|
131
|
-
require '
|
132
|
-
require 'rest-client'
|
133
|
-
require 'time'
|
134
|
-
require 'json'
|
135
|
-
require 'uri'
|
131
|
+
require 'faraday/moguera_authentication'
|
136
132
|
|
137
133
|
url = ARGV[0]
|
138
|
-
abort "Usage: ruby #{__FILE__} http://localhost:
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
secret_access_key: 'secret',
|
148
|
-
request_path: request_path,
|
149
|
-
request_method: 'POST',
|
150
|
-
content_type: content_type,
|
151
|
-
http_date: http_date
|
152
|
-
}
|
153
|
-
|
154
|
-
request = Moguera::Authentication::Request.new(params)
|
155
|
-
|
156
|
-
headers = {
|
157
|
-
Authorization: request.token,
|
158
|
-
content_type: content_type,
|
159
|
-
Date: http_date
|
160
|
-
}
|
161
|
-
|
162
|
-
begin
|
163
|
-
res = RestClient.post(url, {key:'value'}.to_json, headers)
|
164
|
-
puts res.body
|
165
|
-
rescue => e
|
166
|
-
puts e.message
|
134
|
+
abort "Usage: ruby #{__FILE__} http://localhost:9292/login/hello" unless url
|
135
|
+
|
136
|
+
access_key = 'user01'
|
137
|
+
secret_access_key = 'secret'
|
138
|
+
|
139
|
+
conn = Faraday.new do |faraday|
|
140
|
+
faraday.use Faraday::MogueraAuthentication, access_key, secret_access_key
|
141
|
+
faraday.response :logger
|
142
|
+
faraday.adapter Faraday.default_adapter
|
167
143
|
end
|
144
|
+
|
145
|
+
payload = '{ "key" : "value" }'
|
146
|
+
response = conn.post(url, payload, 'Content-Type' => 'application/json')
|
147
|
+
|
148
|
+
puts response.body
|
168
149
|
```
|
169
150
|
|
170
151
|
### Quick Run
|
@@ -178,10 +159,10 @@ $ rackup sample/config.ru
|
|
178
159
|
client
|
179
160
|
|
180
161
|
```
|
181
|
-
$ sample/client.rb http://localhost:9292/hello
|
162
|
+
$ sample/client-faraday.rb http://localhost:9292/hello
|
182
163
|
Hello World!
|
183
164
|
|
184
|
-
$ sample/client.rb http://localhost:9292/login/hello
|
165
|
+
$ sample/client-faraday.rb http://localhost:9292/login/hello
|
185
166
|
Hello user01!
|
186
167
|
```
|
187
168
|
|
@@ -195,6 +176,6 @@ Hello user01!
|
|
195
176
|
|
196
177
|
## Copyright
|
197
178
|
|
198
|
-
Copyright (c)
|
179
|
+
Copyright (c) 2015 hiro-su.
|
199
180
|
|
200
|
-
MIT License
|
181
|
+
MIT License
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'moguera/authentication'
|
3
|
+
require 'time'
|
4
|
+
|
5
|
+
module Faraday
|
6
|
+
class MogueraAuthentication < Faraday::Middleware
|
7
|
+
def initialize(app, access_key, secret_access_key)
|
8
|
+
super(app) # @app = app
|
9
|
+
@access_key = access_key
|
10
|
+
@secret_access_key = secret_access_key
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
params = build_parameter(env)
|
15
|
+
request = Moguera::Authentication::Request.new(params)
|
16
|
+
headers = {
|
17
|
+
'Authorization' => request.token,
|
18
|
+
'Content-Type' => params[:content_type],
|
19
|
+
'Date' => params[:http_date]
|
20
|
+
}
|
21
|
+
env.request_headers.merge!(headers)
|
22
|
+
@app.call(env)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def build_parameter(env)
|
28
|
+
path = env.url.path
|
29
|
+
method = "#{env.method}".upcase
|
30
|
+
headers = env.request_headers
|
31
|
+
{
|
32
|
+
access_key: @access_key,
|
33
|
+
secret_access_key: @secret_access_key,
|
34
|
+
request_path: path,
|
35
|
+
request_method: method,
|
36
|
+
content_type: headers['Content-Type'],
|
37
|
+
http_date: headers['Date'] || Time.now.httpdate
|
38
|
+
}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -19,9 +19,9 @@ module Rack
|
|
19
19
|
def call(env)
|
20
20
|
begin
|
21
21
|
request_token = Moguera::Authentication.new(env['HTTP_AUTHORIZATION'])
|
22
|
-
auth = request_token.authenticate! do |
|
23
|
-
|
24
|
-
params = build_parameter(
|
22
|
+
auth = request_token.authenticate! do |access_key|
|
23
|
+
secret_access_key = @secret_block.call(access_key)
|
24
|
+
params = build_parameter(access_key, secret_access_key, env)
|
25
25
|
|
26
26
|
Moguera::Authentication::Request.new(params)
|
27
27
|
end
|
@@ -36,10 +36,10 @@ module Rack
|
|
36
36
|
|
37
37
|
private
|
38
38
|
|
39
|
-
def build_parameter(
|
39
|
+
def build_parameter(access_key, secret_access_key, env)
|
40
40
|
{
|
41
|
-
access_key:
|
42
|
-
secret_access_key:
|
41
|
+
access_key: access_key,
|
42
|
+
secret_access_key: secret_access_key,
|
43
43
|
request_path: env['REQUEST_PATH'],
|
44
44
|
request_method: env['REQUEST_METHOD'],
|
45
45
|
content_type: env['CONTENT_TYPE'],
|
data/sample/Gemfile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
4
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), %w(.. lib)))
|
5
|
+
|
6
|
+
require 'faraday/moguera_authentication'
|
7
|
+
|
8
|
+
url = ARGV[0]
|
9
|
+
abort "Usage: ruby #{__FILE__} http://localhost:9292/login/hello" unless url
|
10
|
+
|
11
|
+
access_key = 'user01'
|
12
|
+
secret_access_key = 'secret'
|
13
|
+
|
14
|
+
conn = Faraday.new do |faraday|
|
15
|
+
faraday.use Faraday::MogueraAuthentication, access_key, secret_access_key
|
16
|
+
faraday.response :logger
|
17
|
+
faraday.adapter Faraday.default_adapter
|
18
|
+
end
|
19
|
+
|
20
|
+
payload = '{ "key" : "value" }'
|
21
|
+
response = conn.post(url, payload, 'Content-Type' => 'application/json')
|
22
|
+
|
23
|
+
puts response.body
|
data/sample/client.rb
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
4
4
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), %w(.. lib)))
|
5
5
|
|
6
6
|
require 'moguera/authentication'
|
7
|
-
require '
|
7
|
+
require 'httpclient'
|
8
8
|
require 'time'
|
9
9
|
require 'json'
|
10
10
|
require 'uri'
|
@@ -12,6 +12,9 @@ require 'uri'
|
|
12
12
|
url = ARGV[0]
|
13
13
|
abort "Usage: ruby #{__FILE__} http://localhost:4567/login" unless url
|
14
14
|
|
15
|
+
http_client = HTTPClient.new
|
16
|
+
http_client.debug_dev = STDERR
|
17
|
+
|
15
18
|
request_path = URI.parse(url).path
|
16
19
|
request_path = '/' if request_path.empty?
|
17
20
|
http_date = Time.now.httpdate
|
@@ -29,14 +32,10 @@ params = {
|
|
29
32
|
request = Moguera::Authentication::Request.new(params)
|
30
33
|
|
31
34
|
headers = {
|
32
|
-
Authorization
|
33
|
-
|
34
|
-
Date
|
35
|
+
'Authorization' => request.token,
|
36
|
+
'Content-Type' => content_type,
|
37
|
+
'Date' => http_date
|
35
38
|
}
|
36
39
|
|
37
|
-
|
38
|
-
|
39
|
-
puts res.body
|
40
|
-
rescue => e
|
41
|
-
puts e.response
|
42
|
-
end
|
40
|
+
response = http_client.post(url, {key:'value'}.to_json, headers)
|
41
|
+
puts response.body
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: moguera-authentication
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hiro-su
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- LICENSE.txt
|
82
82
|
- README.md
|
83
83
|
- Rakefile
|
84
|
+
- lib/faraday/moguera_authentication.rb
|
84
85
|
- lib/moguera/authentication.rb
|
85
86
|
- lib/moguera/authentication/exception.rb
|
86
87
|
- lib/moguera/authentication/request.rb
|
@@ -91,6 +92,8 @@ files:
|
|
91
92
|
- lib/rails/moguera_authentication/install.rb
|
92
93
|
- lib/rails/moguera_authentication/railtie.rb
|
93
94
|
- moguera-authentication.gemspec
|
95
|
+
- sample/Gemfile
|
96
|
+
- sample/client-faraday.rb
|
94
97
|
- sample/client.rb
|
95
98
|
- sample/config.ru
|
96
99
|
- sample/credential.json
|
@@ -120,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
123
|
version: '0'
|
121
124
|
requirements: []
|
122
125
|
rubyforge_project:
|
123
|
-
rubygems_version: 2.
|
126
|
+
rubygems_version: 2.4.5
|
124
127
|
signing_key:
|
125
128
|
specification_version: 4
|
126
129
|
summary: Simple REST API Authentication.
|