wine_bouncer 0.3.1 → 0.4.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: 1d520f0842f9978dde501b13eecd7ec124f30a57
4
- data.tar.gz: 4f74158125be0303fb0e4c3efb28407190c3628d
3
+ metadata.gz: 4f574523e9139e98523e7ee4fa55f53c08d523d5
4
+ data.tar.gz: 57f194faf3e53dd0382c9ad5d55193510eca3646
5
5
  SHA512:
6
- metadata.gz: 752d4043b4360f1e8baa23457e611d6cdb3fea714e07e518652adc51a8e95099f798576cc36acc4e550201722e42adc437c3ad68435c6fae499f9a7d5b0db83f
7
- data.tar.gz: e160c6f796b00889e233d6da793754c7053ddc3bc296b6471fe81fcff13ef8cf9781829bcacd43377e42ec59a9076a8b874768c003321b7fb40cb8e839801d62
6
+ metadata.gz: 8f15e202eff6141fef5a1717ab23a542b63ab49ca8558aa98dfebb3f91b8a00512893720b1c8e0858cde16d55158334522c17997b0a9411051ad2c86af60f46f
7
+ data.tar.gz: a232f4bc101f50924f4c794071c1c4411498da7a45b6558994471569441cc61b7a55ff12de8480a76c0094f6fa417f75585d101d982c572a064c76d1d39741e4
data/.travis.yml CHANGED
@@ -2,20 +2,26 @@ before_install:
2
2
  - gem update bundler
3
3
  - bundle --version
4
4
  language: ruby
5
+ cache: bundler
5
6
  rvm:
6
- - 1.9.3
7
7
  - 2.0
8
8
  - 2.1
9
+ - 2.2
9
10
  env:
10
- - rails=3.2.18 grape=0.9.0
11
- - rails=4.1.1 grape=0.9.0
12
11
  - rails=3.2.18 grape=0.10.0
13
- - rails=4.1.1 grape=0.10.0 doorkeeper=1.4.1
14
- - rails=4.1.1 grape=0.10.0
15
- - rails=4.1.1 grape=0.11.0 doorkeeper=2.1.3
12
+ - rails=3.2.18 grape=0.12.0
13
+ - rails=4.1.1 grape=0.12.0 doorkeeper=2.0.1
14
+ - rails=4.1.1 grape=0.12.0 doorkeeper=2.1.4
15
+ - rails=4.2.0 grape=0.10.0 doorkeeper=2.2.1
16
+ - rails=4.2.0 grape=0.11.0 doorkeeper=2.2.1
17
+ - rails=4.2.0 grape=0.12.0 doorkeeper=2.2.1
16
18
  matrix:
17
- allow_failures:
18
- - rvm: 1.9.3
19
+ exclude:
20
+ - env: rails=3.2.18 grape=0.10.0
21
+ rvm: 2.2
22
+
23
+ - env: rails=3.2.18 grape=0.12.0
24
+ rvm: 2.2
19
25
  addons:
20
26
  code_climate:
21
27
  repo_token: ab1b6ce5f973da033f80ae2e99fadbb32b2f9c37892703956d8ef954c8e8134e
data/CHANGELOG.md CHANGED
@@ -1,22 +1,30 @@
1
1
  Changelog
2
2
  =========
3
+
4
+ ## Next
5
+
6
+ ## 0.4.0
7
+ * [#42](https://github.com/antek-drzewiecki/wine_bouncer/pull/42): Added support for Doorkeeper 2.2
8
+ * [#41](https://github.com/antek-drzewiecki/wine_bouncer/pull/41): Added support for Grape 0.12.0, Removed support for Grape 0.8 and 0.9 (though they still work).
9
+ * [#39](https://github.com/antek-drzewiecki/wine_bouncer/pull/39): Add option to disable WineBouncer conditionally. Thanks @Fryie .
10
+
3
11
  ## 0.3.1
4
- [#31](https://github.com/antek-drzewiecki/wine_bouncer/pull/31): Improves support for default scopes trough DSL.
5
- [#30](https://github.com/antek-drzewiecki/wine_bouncer/pull/30): Restricted grape dependencies to the next minor level of grape.
6
- [#29](https://github.com/antek-drzewiecki/wine_bouncer/pull/29): Doorkeepers dependencies are restricted to minor levels. Thanks @nickcharlton
7
- [#27](https://github.com/antek-drzewiecki/wine_bouncer/pull/27): Fixes DSL default and protected strategy. Fixes #24 and #26.
12
+ * [#31](https://github.com/antek-drzewiecki/wine_bouncer/pull/31): Improves support for default scopes trough DSL.
13
+ * [#30](https://github.com/antek-drzewiecki/wine_bouncer/pull/30): Restricted grape dependencies to the next minor level of grape.
14
+ * [#29](https://github.com/antek-drzewiecki/wine_bouncer/pull/29): Doorkeepers dependencies are restricted to minor levels. Thanks @nickcharlton
15
+ * [#27](https://github.com/antek-drzewiecki/wine_bouncer/pull/27): Fixes DSL default and protected strategy. Fixes #24 and #26.
8
16
 
9
17
  ## 0.3.0
10
- [#21](https://github.com/antek-drzewiecki/wine_bouncer/pull/21): Added an Easy DSL for WineBouncer. Thanks @masarakki .
11
- [#23](https://github.com/antek-drzewiecki/wine_bouncer/pull/23): Added support for Doorkeeper 2.1.1 and refactored strategies.
18
+ * [#21](https://github.com/antek-drzewiecki/wine_bouncer/pull/21): Added an Easy DSL for WineBouncer. Thanks @masarakki .
19
+ * [#23](https://github.com/antek-drzewiecki/wine_bouncer/pull/23): Added support for Doorkeeper 2.1.1 and refactored strategies.
12
20
 
13
21
  ## 0.2.2
14
- [#17](https://github.com/antek-drzewiecki/wine_bouncer/pull/17): Added a new protected strategy. Thanks @whatasunnyday .
22
+ * [#17](https://github.com/antek-drzewiecki/wine_bouncer/pull/17): Added a new protected strategy. Thanks @whatasunnyday .
15
23
 
16
24
  ## 0.2.1
17
- [#12](https://github.com/antek-drzewiecki/wine_bouncer/pull/12): Added a rails generator to generate the WineBouncer configuration file. Thanks @whatasunnyday.
18
- [#7](https://github.com/antek-drzewiecki/wine_bouncer/pull/7): Added support for Doorkeeper 2.0.0 and 2.0.1. Thanks @whatasunnyday .
25
+ * [#12](https://github.com/antek-drzewiecki/wine_bouncer/pull/12): Added a rails generator to generate the WineBouncer configuration file. Thanks @whatasunnyday.
26
+ * [#7](https://github.com/antek-drzewiecki/wine_bouncer/pull/7): Added support for Doorkeeper 2.0.0 and 2.0.1. Thanks @whatasunnyday .
19
27
 
20
28
  ## 0.2.0
21
- [#4](https://github.com/antek-drzewiecki/wine_bouncer/pull/4): Support for newer versions of grape ( > 0.8 ).
22
- [#6](https://github.com/antek-drzewiecki/wine_bouncer/pull/6): Added the option to configure the resource owner.
29
+ * [#4](https://github.com/antek-drzewiecki/wine_bouncer/pull/4): Support for newer versions of grape ( > 0.8 ).
30
+ * [#6](https://github.com/antek-drzewiecki/wine_bouncer/pull/6): Added the option to configure the resource owner.
data/Gemfile CHANGED
@@ -1,8 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- ENV['grape'] ||= '0.10.0'
4
- ENV['rails'] ||= '4.1.1'
5
- ENV['doorkeeper'] ||= '2.0.1'
3
+ ENV['grape'] ||= '0.12.0'
4
+ ENV['rails'] ||= '4.2.0'
5
+ ENV['doorkeeper'] ||= '2.2.1'
6
6
 
7
7
  gem 'rails', ENV['rails']
8
8
 
data/README.md CHANGED
@@ -19,6 +19,7 @@ Table of Contents
19
19
  * [Swagger](#swagger)
20
20
  * [Protected](#protected)
21
21
  * [Token information](#token-information)
22
+ * [Disable WineBouncer](#disable-winebouncer)
22
23
  * [Exceptions and Exception handling](#exceptions-and-exception-handling)
23
24
  * [Example Application](#example-application)
24
25
  * [Development](#development)
@@ -26,16 +27,16 @@ Table of Contents
26
27
 
27
28
 
28
29
  ## Requirements
29
- - Ruby > 1.9.3
30
- - Doorkeeper > 1.4.0 and < 2.2
31
- - Grape > 0.8 and < 0.12
30
+ - Ruby > 2.0
31
+ - Doorkeeper > 1.4.0 and < 3
32
+ - Grape > 0.10 and < 0.13
32
33
 
33
34
  ## Installation
34
35
 
35
36
  Add this line to your application's Gemfile:
36
37
 
37
38
  ```ruby
38
- gem 'wine_bouncer'
39
+ gem 'wine_bouncer', '~> 0.4.0'
39
40
  ```
40
41
 
41
42
  And then execute:
@@ -46,7 +47,7 @@ bundle
46
47
 
47
48
  ## Upgrading
48
49
  When upgrading from a previous version, see [UPGRADING](UPGRADING.md). You might also be interested at the [CHANGELOG](CHANGELOG.md).
49
- Note this is the last version that will support Grape 0.8 and 0.9. Grape 0.10 will be the next minimum Grape version.
50
+
50
51
 
51
52
  ## Usage
52
53
  WineBouncer is a custom Grape Middleware used for Authentication and Authorization. We assume you have a Grape API mounted in your Rails application together with Doorkeeper.
@@ -185,6 +186,26 @@ To protect your endpoint with other scopes append the following method `oauth2 '
185
186
 
186
187
  WineBouncer comes with free extras! Methods for `resource_owner` and `doorkeeper_access_token` get included in your endpoints. You can use them to get the current resource owner, and the access_token object of doorkeeper.
187
188
 
189
+ ### Disable WineBouncer
190
+
191
+ If you want to disable WineBouncer conditionally - e.g. in specs - you can add a block to the WineBouncer configuration. When this block evaluates to true, any request will be unprotected. For example:
192
+ ```{ruby}
193
+ WineBouncer.configure do |config|
194
+ config.disable do
195
+ Rails.env.test?
196
+ end
197
+ end
198
+ ```
199
+
200
+ The block is newly evaluated for every request, so you could in principle have something like:
201
+ ```{ruby}
202
+ config.disable do
203
+ [true, false].sample
204
+ end
205
+ ```
206
+
207
+ You probably shouldn't, though.
208
+
188
209
  ## Exceptions and Exception handling
189
210
 
190
211
  This gem raises the following exceptions which can be handled in your Grape API, see [Grape documentation](https://github.com/intridea/grape#exception-handling).
@@ -194,9 +215,9 @@ This gem raises the following exceptions which can be handled in your Grape API,
194
215
  * `WineBouncer::Errors::OAuthForbiddenError`
195
216
  when the token is found but scopes do not match.
196
217
 
197
- ## Example Application
218
+ ## Example/Template Application
198
219
 
199
- A full working sample app can be found on [sethherr page](https://github.com/sethherr/grape-doorkeeper) and can be accessed on [heroku](https://grape-doorkeeper.herokuapp.com/)
220
+ A full working sample app (or starter template) can be found at [grape-doorkeeper on github](https://github.com/sethherr/grape-doorkeeper). It has one click deploy to Heroku and [a live example](https://grape-doorkeeper.herokuapp.com/).
200
221
 
201
222
  ## Development
202
223
 
@@ -30,6 +30,16 @@ module WineBouncer
30
30
  fail(Errors::UnconfiguredError, 'Please define define_resource_owner to configure the resource owner') unless @defined_resource_owner
31
31
  @defined_resource_owner
32
32
  end
33
+
34
+ # when the block evaluates to true, WineBouncer should be disabled
35
+ # if no block is provided, WineBouncer is always enabled
36
+ def disable(&block)
37
+ @disable_block = block
38
+ end
39
+
40
+ def disable_block
41
+ @disable_block || ->() { false }
42
+ end
33
43
  end
34
44
 
35
45
  def self.configuration
@@ -1,6 +1,7 @@
1
1
  module WineBouncer
2
2
  class OAuth2 < Grape::Middleware::Base
3
3
 
4
+ include Doorkeeper::Helpers::Controller
4
5
  ###
5
6
  # returns the api context
6
7
  ###
@@ -22,17 +23,10 @@ module WineBouncer
22
23
  ###
23
24
  # Returns the request context.
24
25
  ###
25
- def doorkeeper_request
26
+ def request
26
27
  @_doorkeeper_request
27
28
  end
28
29
 
29
- ###
30
- # Authenticates from a request and returns a valid or invalid token.
31
- ###
32
- def doorkeeper_token
33
- @_doorkeeper_token ||= Doorkeeper.authenticate(doorkeeper_request,Doorkeeper.configuration.access_token_methods)
34
- end
35
-
36
30
  ###
37
31
  # Returns true if the doorkeeper token is valid, false otherwise.
38
32
  ###
@@ -86,6 +80,8 @@ module WineBouncer
86
80
  # Before do.
87
81
  ###
88
82
  def before
83
+ return if WineBouncer.configuration.disable_block.call
84
+
89
85
  set_auth_strategy(WineBouncer.configuration.auth_strategy)
90
86
  auth_strategy.api_context = context
91
87
  #extend the context with auth methods.
@@ -1,3 +1,3 @@
1
1
  module WineBouncer
2
- VERSION = '0.3.1'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -54,6 +54,11 @@ module Api
54
54
  { hello: 'oauth dsl default scopes' }
55
55
  end
56
56
 
57
+ oauth2 'multiple', 'scopes'
58
+ get '/oauth2_dsl_multiple_scopes' do
59
+ { hello: 'oauth2 dsl multiple scopes' }
60
+ end
61
+
57
62
  end
58
63
 
59
64
  class DefaultApiUnderTest < Grape::API
@@ -139,6 +139,32 @@ describe Api::MountedDefaultApiUnderTest, type: :api do
139
139
  expect { get '/default_api/oauth2_dsl_custom_scope', nil, 'HTTP_AUTHORIZATION' => "Bearer #{token.token}" }.to raise_exception(WineBouncer::Errors::OAuthForbiddenError)
140
140
  end
141
141
  end
142
+
143
+ context 'oauth2_dsl_multiple_scopes' do
144
+
145
+ it 'allows call on the first scope' do
146
+ scope_token = FactoryGirl.create :clientless_access_token, resource_owner_id: user.id, scopes: 'multiple'
147
+ get '/default_api/oauth2_dsl_multiple_scopes', nil, 'HTTP_AUTHORIZATION' => "Bearer #{scope_token.token}"
148
+ expect(last_response.status).to eq(200)
149
+ json = JSON.parse(last_response.body)
150
+ expect(json).to have_key('hello')
151
+ expect(json['hello']).to eq('oauth2 dsl multiple scopes')
152
+ end
153
+
154
+ it 'allows call on the second scope' do
155
+ scope_token = FactoryGirl.create :clientless_access_token, resource_owner_id: user.id, scopes: 'scopes'
156
+ get '/default_api/oauth2_dsl_multiple_scopes', nil, 'HTTP_AUTHORIZATION' => "Bearer #{scope_token.token}"
157
+ expect(last_response.status).to eq(200)
158
+ json = JSON.parse(last_response.body)
159
+ expect(json).to have_key('hello')
160
+ expect(json['hello']).to eq('oauth2 dsl multiple scopes')
161
+ end
162
+
163
+ it 'raises an error scope does not match any of the scopes' do
164
+ expect { get '/default_api/oauth2_dsl_multiple_scopes' }.to raise_exception(WineBouncer::Errors::OAuthUnauthorizedError)
165
+ end
166
+
167
+ end
142
168
  end
143
169
 
144
170
  context 'not_described_world' do
@@ -18,6 +18,27 @@ describe Api::MountedProtectedApiUnderTest, type: :api do
18
18
  end
19
19
  end
20
20
 
21
+ context 'when WineBouncer is disabled' do
22
+ before :all do
23
+ WineBouncer.configure do |c|
24
+ c.disable { true }
25
+ end
26
+ end
27
+
28
+ after :all do
29
+ WineBouncer.configure do |c|
30
+ c.disable { false }
31
+ end
32
+ end
33
+
34
+ it 'allows request to protected resource without token' do
35
+ get '/protected_api/protected'
36
+ expect(last_response.status).to eq(200)
37
+ json = JSON.parse(last_response.body)
38
+ expect(json).to have_key('hello')
39
+ end
40
+ end
41
+
21
42
  context 'tokens and scopes' do
22
43
  it 'gives access when the token and scope are correct' do
23
44
  get '/protected_api/protected', nil, 'HTTP_AUTHORIZATION' => "Bearer #{token.token}"
data/wine_bouncer.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.name = "wine_bouncer"
8
8
  spec.version = WineBouncer::VERSION
9
9
  spec.authors = ["Antek Drzewiecki"]
10
- spec.email = ["antek.drzewiecki@tass.nl"]
10
+ spec.email = ["antek.drzewiecki@altran.com"]
11
11
  spec.summary = %q{A Ruby gem that allows Oauth2 protection with Doorkeeper for Grape Api's}
12
12
  spec.homepage = ""
13
13
  spec.license = "MIT"
@@ -17,8 +17,8 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.add_runtime_dependency 'grape', '~> 0.8', '< 0.12'
21
- spec.add_runtime_dependency 'doorkeeper', '>= 1.4', '< 2.2'
20
+ spec.add_runtime_dependency 'grape', '~> 0.10', '< 0.13'
21
+ spec.add_runtime_dependency 'doorkeeper', '>= 1.4', '< 3.0'
22
22
 
23
23
  spec.add_development_dependency "railties"
24
24
  spec.add_development_dependency "bundler", "~> 1.7"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wine_bouncer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antek Drzewiecki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-05 00:00:00.000000000 Z
11
+ date: 2015-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grape
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '0.8'
19
+ version: '0.10'
20
20
  - - <
21
21
  - !ruby/object:Gem::Version
22
- version: '0.12'
22
+ version: '0.13'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: '0.8'
29
+ version: '0.10'
30
30
  - - <
31
31
  - !ruby/object:Gem::Version
32
- version: '0.12'
32
+ version: '0.13'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: doorkeeper
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -39,7 +39,7 @@ dependencies:
39
39
  version: '1.4'
40
40
  - - <
41
41
  - !ruby/object:Gem::Version
42
- version: '2.2'
42
+ version: '3.0'
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
@@ -49,7 +49,7 @@ dependencies:
49
49
  version: '1.4'
50
50
  - - <
51
51
  - !ruby/object:Gem::Version
52
- version: '2.2'
52
+ version: '3.0'
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: railties
55
55
  requirement: !ruby/object:Gem::Requirement
@@ -164,7 +164,7 @@ dependencies:
164
164
  version: 1.3.0
165
165
  description:
166
166
  email:
167
- - antek.drzewiecki@tass.nl
167
+ - antek.drzewiecki@altran.com
168
168
  executables: []
169
169
  extensions: []
170
170
  extra_rdoc_files: []