warden-oauth2-strategies 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b5f58493bf08099b52076a588bec5a9b085a87dc
4
- data.tar.gz: c035adbefd44c2d638f4083837bdf177556d4daa
3
+ metadata.gz: 0c6a34c8e622339f8691e13f71bdc4e24750098a
4
+ data.tar.gz: c85473c8b74ac773e500284e3499572866a47c0f
5
5
  SHA512:
6
- metadata.gz: 82c79f570379db6077afae398c31ac2fae751e6e1dabdd38c44a653340d48432eb98125dde64905ce2cd515cd47c4f7f67add125a569595e46acc650f965bca2
7
- data.tar.gz: 9fa9d1e8aaa201fa5a1644d985f4456e26aab48c9ed625a71b3cd2b0ff2c565340421ff0fc32f6e1bb61912034681bedc668cf01dd2145e07f11f3ebeb50ddba
6
+ metadata.gz: bfb7486551c23f787779fd628a1de71de1acdd56ec6aee88acff8fdeb741aa7a83c83e1755fa9cb42845abab8a705ca2b6c0bb606b2e16b95992b66b5255924a
7
+ data.tar.gz: ea455fafa45ee5d0bf75b5bc3f7caa1c280f33bcb2c2fc5ec330c2bd7cef4cd03dbdede5e2f64125cc45e498567b9dc49320b5d920cca9f337f461f23f409baa
data/.travis.yml CHANGED
@@ -1,7 +1,5 @@
1
1
  rvm:
2
2
  - 1.9.3
3
- - 1.9.2
4
- - 1.8.7
5
3
  - jruby
6
4
  - rbx
7
5
  script: "bundle exec rake"
data/README.md CHANGED
@@ -15,12 +15,14 @@ require 'warden-oauth2'
15
15
 
16
16
  class MyAPI < Grape::API
17
17
  use Warden::Manager do |config|
18
- strategies.add :bearer, Warden::OAuth2::Strategies::Bearer
19
- strategies.add :client_credentials, Warden::OAuth2::Strategies::ClientCredentials
20
- strategies.add :resource_owner_password_credentials, Warden::OAuth2::Strategies::ResourceOwnerPasswordCredentials
21
- strategies.add :public, Warden::OAuth2::Strategies::Public
22
-
23
- config.default_strategies :bearer, :client_credentials, :resource_owner_password_credentials, :public
18
+ config.strategies.add :bearer, Warden::OAuth2::Strategies::Bearer
19
+ config.strategies.add :client_credentials, Warden::OAuth2::Strategies::ClientCredentials
20
+ config.strategies.add :resource_owner_password_credentials, Warden::OAuth2::Strategies::ResourceOwnerPasswordCredentials
21
+ config.strategies.add :issuing_access_token, Warden::OAuth2::Strategies::IssuingAccessToken
22
+ config.strategies.add :accessing_protected_resource, Warden::OAuth2::Strategies::AccessingProtectedResource
23
+
24
+ config.default_strategies :client_credentials, :resource_owner_password_credentials, :issuing_access_token
25
+ config.default_strategies :bearer, :accessing_protected_resource
24
26
  config.failure_app Warden::OAuth2::FailureApp
25
27
  end
26
28
 
@@ -162,6 +164,14 @@ Use `.valid?` on the client application to determine if user credentials are cor
162
164
 
163
165
  **User:** The Warden user is set to the access token returned by `.locate`.
164
166
 
167
+ ### Issuing Access Token
168
+
169
+ This strategy is a fallback strategy when cannot issue access token due to unspecified grant_type
170
+
171
+ ### Accessing Protected Resource
172
+
173
+ This strategy is a fallback strategy when cannot validate access to protected resource due to unspecified token
174
+
165
175
  ### Public
166
176
 
167
177
  This strategy succeeds by default and only fails if the authentication
@@ -21,8 +21,8 @@ module Warden
21
21
  headers['X-Accepted-OAuth-Scopes'] = (strategy.scope || :public).to_s
22
22
  else
23
23
  status = 400
24
- body[:error] = "invalid_grant"
25
- body[:error_description] = "grant_type is not specified or invalid"
24
+ body[:error] = 'invalid_request'
25
+ body[:error_description] = 'cannot determine authentication method'
26
26
  end
27
27
  [status, headers, [JSON.dump(body)]]
28
28
  end
@@ -0,0 +1,18 @@
1
+ require 'warden-oauth2'
2
+
3
+ module Warden
4
+ module OAuth2
5
+ module Strategies
6
+ class AccessingProtectedResource < Bearer
7
+ def valid?
8
+ !super
9
+ end
10
+
11
+ def authenticate!
12
+ self.error_description = 'Bearer Token is not provided'
13
+ fail! 'invalid_client'
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -4,6 +4,7 @@ module Warden
4
4
  module OAuth2
5
5
  module Strategies
6
6
  class Base < Warden::Strategies::Base
7
+ attr_writer :error_description
7
8
  def store?
8
9
  false
9
10
  end
@@ -11,6 +12,10 @@ module Warden
11
12
  def error_status
12
13
  400
13
14
  end
15
+
16
+ def error_description
17
+ @error_description || ''
18
+ end
14
19
  end
15
20
  end
16
21
  end
@@ -5,16 +5,16 @@ module Warden
5
5
  module OAuth2
6
6
  module Strategies
7
7
  class Client < Base
8
- attr_reader :client, :client_id, :client_secret, :error_description
8
+ attr_reader :client, :client_id, :client_secret
9
9
 
10
10
  def authenticate!
11
11
  @client = client_from_http_basic || client_from_request_params
12
12
 
13
13
  if self.client
14
- fail "invalid_scope" and return if scope && client.respond_to?(:scope) && !client.scope?(scope)
14
+ fail 'invalid_scope' and return if scope && client.respond_to?(:scope) && !client.scope?(scope)
15
15
  client_authenticated
16
16
  else
17
- fail "invalid_client"
17
+ fail 'invalid_client'
18
18
  end
19
19
  end
20
20
 
@@ -36,14 +36,12 @@ module Warden
36
36
 
37
37
  def error_status
38
38
  case message
39
- when "invalid_client" then 401
40
- when "invalid_scope" then 403
39
+ when 'invalid_client' then 401
40
+ when 'invalid_scope' then 403
41
41
  else 400
42
42
  end
43
43
  end
44
44
 
45
- protected
46
- attr_writer :error_description
47
45
  def model
48
46
  raise 'Model should be defined in a child strategy'
49
47
  end
@@ -0,0 +1,18 @@
1
+ require 'warden-oauth2'
2
+
3
+ module Warden
4
+ module OAuth2
5
+ module Strategies
6
+ class IssuingAccessToken < Base
7
+ def valid?
8
+ !params.include?('grant_type')
9
+ end
10
+
11
+ def authenticate!
12
+ self.error_description = 'grant_type is not specified or invalid'
13
+ fail! 'invalid_grant'
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,5 +1,5 @@
1
1
  module Warden
2
2
  module OAuth2
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
data/lib/warden/oauth2.rb CHANGED
@@ -29,6 +29,8 @@ module Warden
29
29
  autoload :Client, 'warden/oauth2/strategies/client'
30
30
  autoload :ClientCredentials, 'warden/oauth2/strategies/client_credentials'
31
31
  autoload :ResourceOwnerPasswordCredentials, 'warden/oauth2/strategies/resource_owner_password_credentials'
32
+ autoload :IssuingAccessToken, 'warden/oauth2/strategies/issuing_access_token'
33
+ autoload :AccessingProtectedResource, 'warden/oauth2/strategies/accessing_protected_resource'
32
34
  autoload :Bearer, 'warden/oauth2/strategies/bearer'
33
35
  end
34
36
  end
@@ -4,11 +4,11 @@ describe Warden::OAuth2::FailureApp do
4
4
  let(:app) { subject }
5
5
  let(:warden) { double(:winning_strategy => @strategy) }
6
6
 
7
- it 'defaults to invalid_grant if strategy is not found' do
7
+ it 'defaults to invalid_request if strategy is not found' do
8
8
  @strategy = nil
9
9
  get '/unauthenticated', {}, 'warden' => warden
10
10
  last_response.status.should == 400
11
- last_response.body.should == '{"error":"invalid_grant","error_description":"grant_type is not specified or invalid"}'
11
+ last_response.body.should == '{"error":"invalid_request","error_description":"cannot determine authentication method"}'
12
12
  end
13
13
  it 'uses empty string is strategy does not provide a description' do
14
14
  @strategy = double(error_status: 500,:message => 'custom', scope: 'bla')
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe Warden::OAuth2::Strategies::AccessingProtectedResource do
4
+ let(:strategy){ described_class }
5
+ subject{ strategy.new({'rack.input' => {}}) }
6
+
7
+ describe '#valid?' do
8
+ Rack::Auth::AbstractRequest::AUTHORIZATION_KEYS.each do |key|
9
+ it 'returns true if token string is not correct' do
10
+ subject.stub(:env).and_return({key => 'Some sneaky key'})
11
+ subject.should be_valid
12
+ end
13
+ end
14
+ it 'returns true if token string is not specified' do
15
+ subject.stub(:env).and_return({})
16
+ subject.should be_valid
17
+ end
18
+ it 'returns false if token string is correct' do
19
+ subject.stub(:env).and_return({'HTTP_AUTHORIZATION' => 'Bearer abc'})
20
+ subject.should_not be_valid
21
+ end
22
+ end
23
+ describe '#authenticate!' do
24
+ it 'fails with invalid_client' do
25
+ subject._run!
26
+ subject.result.should == :failure
27
+ subject.message.should == 'invalid_client'
28
+ subject.error_status.should == 400
29
+ subject.error_description.should_not be_empty
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Warden::OAuth2::Strategies::IssuingAccessToken do
4
+ let(:strategy){ described_class }
5
+ subject{ strategy.new({'rack.input' => {}}) }
6
+
7
+ describe '#valid?' do
8
+ it 'returns false when grant_type is specified' do
9
+ subject.stub(:params).and_return({'grant_type' => 'whatever'})
10
+ subject.should_not be_valid
11
+ end
12
+ it 'returns true when the grant_type is not specified' do
13
+ subject.stub(:params).and_return({})
14
+ subject.should be_valid
15
+ end
16
+ end
17
+ describe '#authenticate!' do
18
+ it 'fails with invalid grant' do
19
+ subject._run!
20
+ subject.result.should == :failure
21
+ subject.message.should == 'invalid_grant'
22
+ subject.error_status.should == 400
23
+ subject.error_description.should_not be_empty
24
+ end
25
+ end
26
+ end
@@ -15,6 +15,7 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Warden::OAuth2::VERSION
17
17
  gem.licenses = ['MIT']
18
+ gem.required_ruby_version = '>= 1.9.3'
18
19
 
19
20
  gem.add_dependency 'warden'
20
21
  gem.add_development_dependency 'rake'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: warden-oauth2-strategies
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - AirService
@@ -84,19 +84,23 @@ files:
84
84
  - lib/warden/oauth2.rb
85
85
  - lib/warden/oauth2/error_app.rb
86
86
  - lib/warden/oauth2/failure_app.rb
87
+ - lib/warden/oauth2/strategies/accessing_protected_resource.rb
87
88
  - lib/warden/oauth2/strategies/base.rb
88
89
  - lib/warden/oauth2/strategies/bearer.rb
89
90
  - lib/warden/oauth2/strategies/client.rb
90
91
  - lib/warden/oauth2/strategies/client_credentials.rb
92
+ - lib/warden/oauth2/strategies/issuing_access_token.rb
91
93
  - lib/warden/oauth2/strategies/public.rb
92
94
  - lib/warden/oauth2/strategies/resource_owner_password_credentials.rb
93
95
  - lib/warden/oauth2/strategies/token.rb
94
96
  - lib/warden/oauth2/version.rb
95
97
  - spec/spec_helper.rb
96
98
  - spec/warden/oauth2/failure_app_spec.rb
99
+ - spec/warden/oauth2/strategies/accessing_protected_resource_spec.rb
97
100
  - spec/warden/oauth2/strategies/bearer_spec.rb
98
101
  - spec/warden/oauth2/strategies/client_credentials_spec.rb
99
102
  - spec/warden/oauth2/strategies/client_spec.rb
103
+ - spec/warden/oauth2/strategies/issuing_access_token_spec.rb
100
104
  - spec/warden/oauth2/strategies/public_spec.rb
101
105
  - spec/warden/oauth2/strategies/resource_owner_password_credentials_spec.rb
102
106
  - spec/warden/oauth2/strategies/token_spec.rb
@@ -113,7 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
117
  requirements:
114
118
  - - '>='
115
119
  - !ruby/object:Gem::Version
116
- version: '0'
120
+ version: 1.9.3
117
121
  required_rubygems_version: !ruby/object:Gem::Requirement
118
122
  requirements:
119
123
  - - '>='
@@ -121,16 +125,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
125
  version: '0'
122
126
  requirements: []
123
127
  rubyforge_project:
124
- rubygems_version: 2.1.11
128
+ rubygems_version: 2.2.1
125
129
  signing_key:
126
130
  specification_version: 4
127
131
  summary: OAuth 2.0 strategies for Warden
128
132
  test_files:
129
133
  - spec/spec_helper.rb
130
134
  - spec/warden/oauth2/failure_app_spec.rb
135
+ - spec/warden/oauth2/strategies/accessing_protected_resource_spec.rb
131
136
  - spec/warden/oauth2/strategies/bearer_spec.rb
132
137
  - spec/warden/oauth2/strategies/client_credentials_spec.rb
133
138
  - spec/warden/oauth2/strategies/client_spec.rb
139
+ - spec/warden/oauth2/strategies/issuing_access_token_spec.rb
134
140
  - spec/warden/oauth2/strategies/public_spec.rb
135
141
  - spec/warden/oauth2/strategies/resource_owner_password_credentials_spec.rb
136
142
  - spec/warden/oauth2/strategies/token_spec.rb