warden-oauth2-strategies 0.0.3 → 0.0.4

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: f69d35d74b8c3c2634402bbcef1763f247ed8766
4
- data.tar.gz: 9f6f94e8081c71a097f8a7faba877bb2200e395d
3
+ metadata.gz: b5f58493bf08099b52076a588bec5a9b085a87dc
4
+ data.tar.gz: c035adbefd44c2d638f4083837bdf177556d4daa
5
5
  SHA512:
6
- metadata.gz: 684cddb78f24c07f0369cb774ad52a9052d8af3260384417ade64cf4d93f359a03c3b1393c21dacc28c40eb9a3c900199719446aa7711662af21ef678dc031e0
7
- data.tar.gz: 77d117334f06d35b5d5819e6f784ddfa3c814fee60ef69de004f2b293364d1c278df06176699f8a89dd91de226fe07f5f97f332c5ef46a88c3b01eac47f8957d
6
+ metadata.gz: 82c79f570379db6077afae398c31ac2fae751e6e1dabdd38c44a653340d48432eb98125dde64905ce2cd515cd47c4f7f67add125a569595e46acc650f965bca2
7
+ data.tar.gz: 9fa9d1e8aaa201fa5a1644d985f4456e26aab48c9ed625a71b3cd2b0ff2c565340421ff0fc32f6e1bb61912034681bedc668cf01dd2145e07f11f3ebeb50ddba
@@ -9,18 +9,22 @@ module Warden
9
9
  def call(env)
10
10
  warden = env['warden']
11
11
  strategy = warden.winning_strategy
12
- error_description = strategy.respond_to?(:error_description) ? strategy.error_description : ''
13
12
 
14
- body = {}
15
- body[:error] = strategy.message
16
- body[:error_description] = error_description
17
- body = JSON.dump(body)
18
- status = strategy.error_status
19
13
  headers = {'Content-Type' => 'application/json'}
14
+ body = {}
15
+ if strategy
16
+ error_description = strategy.respond_to?(:error_description) ? strategy.error_description : ''
17
+ body[:error] = strategy.message
18
+ body[:error_description] = error_description
19
+ status = strategy.error_status
20
20
 
21
- headers['X-Accepted-OAuth-Scopes'] = (strategy.scope || :public).to_s
22
-
23
- [status, headers, [body]]
21
+ headers['X-Accepted-OAuth-Scopes'] = (strategy.scope || :public).to_s
22
+ else
23
+ status = 400
24
+ body[:error] = "invalid_grant"
25
+ body[:error_description] = "grant_type is not specified or invalid"
26
+ end
27
+ [status, headers, [JSON.dump(body)]]
24
28
  end
25
29
  end
26
30
  end
@@ -1,5 +1,5 @@
1
1
  module Warden
2
2
  module OAuth2
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
@@ -2,8 +2,14 @@ require 'spec_helper'
2
2
 
3
3
  describe Warden::OAuth2::FailureApp do
4
4
  let(:app) { subject }
5
- let(:warden) { double(:winning_strategy => @strategy || strategy) }
5
+ let(:warden) { double(:winning_strategy => @strategy) }
6
6
 
7
+ it 'defaults to invalid_grant if strategy is not found' do
8
+ @strategy = nil
9
+ get '/unauthenticated', {}, 'warden' => warden
10
+ last_response.status.should == 400
11
+ last_response.body.should == '{"error":"invalid_grant","error_description":"grant_type is not specified or invalid"}'
12
+ end
7
13
  it 'uses empty string is strategy does not provide a description' do
8
14
  @strategy = double(error_status: 500,:message => 'custom', scope: 'bla')
9
15
  get '/unauthenticated', {}, 'warden' => warden
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.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - AirService