rack-oauth_proxy 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6c33bd03642050ec16695d9edd4eb0d128c1b26d
4
- data.tar.gz: 18abbeca292daa9d059f18cfa3b13d86d86b04f8
3
+ metadata.gz: 99386f17d5ddd6f0ddc8308d40ebdeaedfd48e20
4
+ data.tar.gz: a4c3ddb81f3c181adc915c84ff1f7b3fca6c92f8
5
5
  SHA512:
6
- metadata.gz: 2834913040a3706d41932e707744bbddec7bc2d522364fe0f8656c8c0c5ef93d12cce00adf69523b3495dc83700dde5d80e6a17125cba5a1a1232872563be432
7
- data.tar.gz: b037d89e8c295df21a9c4cc88ccf02dd9807f01442c979d13c2f69784a65735d0fb81ccc3dcfff72b61ca8e06f5a7fb9a628e2b65c62b15884838ccd36eccd06
6
+ metadata.gz: 4088da5b01435bd30d7160742a260a2f4f2e6069fab7821cb244f8f0c44439d962192ae68753b7c5fe5181ca35b9f07adb21d9037b0901a4dc59713c3e4ef873
7
+ data.tar.gz: 770fcd4e6ddf166764ce63ea4da869da42aa4d229b16700219196eb6c4b9895359798a4053896a59893cfc849d0f8de7db70e64865974e7aac51dbef0ad53479
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ - 2.1.0
5
+ branches:
6
+ only:
7
+ - master
8
+ env:
9
+ global:
10
+ secure: VhmOZev4085aQTNbSgM76VLajpURnOGktBbRkbjrRlIwGckhAXlc6WZ0f8LkQu7ZY9zXggBwGerImNxkEmEi1fvsky4T1Lj9wlnzm8kckrNSEuUO+59T9hag5+dAQLRxyZMoLQyvJalCI+Y1H8aaBJt39VlppmihNzJONf0wiw8=
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.2.0
2
+ * `env["rack-oauth_proxy.response"]` is a Faraday::Response
3
+
1
4
  ## 0.1.0
2
5
  * Add `:propagated_header_fields` option
3
6
  * Use fadaday
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
- # Rack::OauthProxy
1
+ # Rack::OauthProxy [![Build Status](https://travis-ci.org/r7kamura/rack-oauth_proxy.png)](https://travis-ci.org/r7kamura/rack-oauth_proxy) [![Code Climate](https://codeclimate.com/github/r7kamura/rack-oauth_proxy.png)](https://codeclimate.com/github/r7kamura/rack-oauth_proxy) [![Code Climate](https://codeclimate.com/github/r7kamura/rack-oauth_proxy/coverage.png)](https://codeclimate.com/github/r7kamura/rack-oauth_proxy)
2
+
2
3
  Delegates OAuth authentication to other authentication server.
3
4
 
4
5
  ## Usage
data/Rakefile CHANGED
@@ -1 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task default: :spec
@@ -1,6 +1,3 @@
1
- require "rack/oauth_proxy/access_tokens/base"
2
- require "rack/oauth_proxy/access_tokens/invalid"
3
- require "rack/oauth_proxy/access_tokens/valid"
4
1
  require "rack/oauth_proxy/client"
5
2
  require "rack/oauth_proxy/client/request"
6
3
  require "rack/oauth_proxy/version"
@@ -13,7 +10,7 @@ module Rack
13
10
  end
14
11
 
15
12
  def call(env)
16
- env["rack-oauth_proxy.access_token"] = client.fetch(env)
13
+ env["rack-oauth_proxy.response"] = client.fetch(env)
17
14
  @app.call(env)
18
15
  end
19
16
 
@@ -12,10 +12,7 @@ module Rack
12
12
 
13
13
  def fetch(env)
14
14
  request = Request.new(env, options)
15
- response = connection.get(url, request.params, request.header)
16
- AccessTokens::Valid.new(response.body)
17
- rescue
18
- AccessTokens::Invalid.new
15
+ connection.get(url, request.params, request.header)
19
16
  end
20
17
 
21
18
  private
@@ -23,7 +20,6 @@ module Rack
23
20
  def connection
24
21
  @connection ||= Faraday.new(headers: header) do |connection|
25
22
  connection.adapter :net_http
26
- connection.response :raise_error
27
23
  connection.response :json
28
24
  end
29
25
  end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class OauthProxy
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -20,8 +20,10 @@ Gem::Specification.new do |spec|
20
20
  spec.add_dependency "faraday_middleware"
21
21
  spec.add_dependency "rack"
22
22
  spec.add_development_dependency "bundler", "~> 1.5"
23
+ spec.add_development_dependency "codeclimate-test-reporter"
23
24
  spec.add_development_dependency "pry"
24
25
  spec.add_development_dependency "rake"
25
26
  spec.add_development_dependency "rspec", "2.14.1"
26
- spec.add_development_dependency "webmock"
27
+ spec.add_development_dependency "simplecov"
28
+ spec.add_development_dependency "webmock", "1.17.4"
27
29
  end
@@ -1,15 +1,19 @@
1
1
  require "spec_helper"
2
- require "securerandom"
3
- require "stringio"
4
2
 
5
- describe Rack::OauthProxy::Client do
3
+ describe Rack::OauthProxy do
6
4
  before do
7
5
  stub_request(:get, url).to_return(status: 401, body: {}.to_json)
8
6
  stub_request(:get, url).with(headers: { "Authorization" => "Bearer #{token}" }).to_return(response)
9
7
  end
10
8
 
11
- let(:client) do
12
- described_class.new(options)
9
+ let(:application) do
10
+ opts = options
11
+ Rack::Builder.app do
12
+ use Rack::OauthProxy, opts
13
+ run ->(env) do
14
+ env
15
+ end
16
+ end
13
17
  end
14
18
 
15
19
  let(:options) do
@@ -44,13 +48,25 @@ describe Rack::OauthProxy::Client do
44
48
  end
45
49
 
46
50
  let(:body) do
47
- {}.to_json
51
+ attributes.to_json
52
+ end
53
+
54
+ let(:attributes) do
55
+ {
56
+ "token" => token,
57
+ }
58
+ end
59
+
60
+ let(:result) do
61
+ application.call(env)["rack-oauth_proxy.response"]
48
62
  end
49
63
 
50
- context "#fetch" do
64
+ describe "#call" do
51
65
  context "when authentication succeeded" do
52
66
  it "returns valid access token" do
53
- client.fetch(env).should be_a Rack::OauthProxy::AccessTokens::Valid
67
+ result.should be_a Faraday::Response
68
+ result.status.should == 200
69
+ result.body.should == attributes
54
70
  a_request(:get, url).with(headers: { "Authorization" => "Bearer #{token}" }).should have_been_made
55
71
  end
56
72
  end
@@ -61,7 +77,8 @@ describe Rack::OauthProxy::Client do
61
77
  end
62
78
 
63
79
  it "returns invalid access token" do
64
- client.fetch(env).should be_a Rack::OauthProxy::AccessTokens::Invalid
80
+ result.should be_a Faraday::Response
81
+ result.status.should == 401
65
82
  a_request(:get, url).should have_been_made
66
83
  end
67
84
  end
@@ -72,7 +89,8 @@ describe Rack::OauthProxy::Client do
72
89
  end
73
90
 
74
91
  it "propagates specified fields" do
75
- client.fetch(env).should be_a Rack::OauthProxy::AccessTokens::Invalid
92
+ result.should be_a Faraday::Response
93
+ result.status.should == 401
76
94
  a_request(:get, url).with(headers: { "DUMMY" => "dummy" }).should have_been_made
77
95
  end
78
96
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,16 @@
1
+ require "simplecov"
2
+ SimpleCov.start
3
+
4
+ require "webmock/rspec"
5
+
6
+ if ENV["CI"]
7
+ require "codeclimate-test-reporter"
8
+ CodeClimate::TestReporter.start
9
+ WebMock.allow_net_connect!
10
+ end
11
+
1
12
  $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2
13
  require "rack/oauth_proxy"
3
- require "webmock/rspec"
4
14
 
5
15
  RSpec.configure do |config|
6
16
  config.treat_symbols_as_metadata_keys_with_true_values = true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-oauth_proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: codeclimate-test-reporter
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: pry
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -109,7 +123,7 @@ dependencies:
109
123
  - !ruby/object:Gem::Version
110
124
  version: 2.14.1
111
125
  - !ruby/object:Gem::Dependency
112
- name: webmock
126
+ name: simplecov
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
129
  - - ">="
@@ -122,6 +136,20 @@ dependencies:
122
136
  - - ">="
123
137
  - !ruby/object:Gem::Version
124
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: webmock
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '='
144
+ - !ruby/object:Gem::Version
145
+ version: 1.17.4
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '='
151
+ - !ruby/object:Gem::Version
152
+ version: 1.17.4
125
153
  description:
126
154
  email:
127
155
  - r7kamura@gmail.com
@@ -130,6 +158,7 @@ extensions: []
130
158
  extra_rdoc_files: []
131
159
  files:
132
160
  - ".gitignore"
161
+ - ".travis.yml"
133
162
  - CHANGELOG.md
134
163
  - Gemfile
135
164
  - LICENSE.txt
@@ -137,14 +166,11 @@ files:
137
166
  - Rakefile
138
167
  - lib/rack-oauth_proxy.rb
139
168
  - lib/rack/oauth_proxy.rb
140
- - lib/rack/oauth_proxy/access_tokens/base.rb
141
- - lib/rack/oauth_proxy/access_tokens/invalid.rb
142
- - lib/rack/oauth_proxy/access_tokens/valid.rb
143
169
  - lib/rack/oauth_proxy/client.rb
144
170
  - lib/rack/oauth_proxy/client/request.rb
145
171
  - lib/rack/oauth_proxy/version.rb
146
172
  - rack-oauth_proxy.gemspec
147
- - spec/rack/oauth_proxy/client_spec.rb
173
+ - spec/rack/oauth_proxy_spec.rb
148
174
  - spec/spec_helper.rb
149
175
  homepage: https://github.com/r7kamura/rack-oauth_proxy
150
176
  licenses:
@@ -171,5 +197,5 @@ signing_key:
171
197
  specification_version: 4
172
198
  summary: Delegates OAuth authentication to other authentication server
173
199
  test_files:
174
- - spec/rack/oauth_proxy/client_spec.rb
200
+ - spec/rack/oauth_proxy_spec.rb
175
201
  - spec/spec_helper.rb
@@ -1,39 +0,0 @@
1
- module Rack
2
- class OauthProxy
3
- module AccessTokens
4
- class Base
5
- ATTRIBUTE_NAMES = %w[
6
- application_id
7
- expired_at
8
- refresh_token
9
- resource_owner_id
10
- scope
11
- token
12
- token_type
13
- ]
14
-
15
- ATTRIBUTE_NAMES.each {|name| attr_accessor name }
16
-
17
- def initialize(attributes)
18
- raise NotImplementedError, "You must implement #{self.class}##{__method__}"
19
- end
20
-
21
- def accessible?
22
- raise NotImplementedError, "You must implement #{self.class}##{__method__}"
23
- end
24
-
25
- def revoked?
26
- raise NotImplementedError, "You must implement #{self.class}##{__method__}"
27
- end
28
-
29
- def expired?
30
- raise NotImplementedError, "You must implement #{self.class}##{__method__}"
31
- end
32
-
33
- def scopes
34
- scope.split(" ") if scope
35
- end
36
- end
37
- end
38
- end
39
- end
@@ -1,22 +0,0 @@
1
- module Rack
2
- class OauthProxy
3
- module AccessTokens
4
- class Invalid < Base
5
- def initialize(attributes = nil)
6
- end
7
-
8
- def accessible?
9
- false
10
- end
11
-
12
- def revoked?
13
- false
14
- end
15
-
16
- def expired?
17
- false
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,23 +0,0 @@
1
- module Rack
2
- class OauthProxy
3
- module AccessTokens
4
- class Valid < Base
5
- def initialize(attributes)
6
- ATTRIBUTE_NAMES.each {|name| send("#{name}=", attributes[name]) }
7
- end
8
-
9
- def accessible?
10
- true
11
- end
12
-
13
- def revoked?
14
- false
15
- end
16
-
17
- def expired?
18
- false
19
- end
20
- end
21
- end
22
- end
23
- end