rack-oauth2 1.12.0 → 1.14.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
  SHA256:
3
- metadata.gz: c09e887a3c902ebbbfd1b2a1698d8a4d68d28e18e75616c629dd75e981e2a9d2
4
- data.tar.gz: c0142a2c05df047f0d8f1e9ac11f428983d27a8945d5ae5be213be41b5615e20
3
+ metadata.gz: '088da2d085846ab34b5eff33247abacd16b94041fd9cf2f4cf89a70e955318b9'
4
+ data.tar.gz: e7799db50a8441912d39ff193e2531ff0f5400ac4a2d6b8e3bce6121193ff9a7
5
5
  SHA512:
6
- metadata.gz: ab1002bdd363b2edab71e8eeebd9872bca8ea2be6ad2a99875543974a2b85340ddcb42fc4ddf22f779b18429dc48a9d36fd91e9059391b76b537c04293ac2056
7
- data.tar.gz: bdffd308340040287a3a8777cdaaaa9de58873d4d27e080dc719b4715ca53fd413bc726f19382b63cd086ad3dd47ac139a665f0acfcd25d2bb2a5e266d8dafce
6
+ metadata.gz: b8418d25dcd7acbaecc740e44fa67dc36dd63399be872151b3df0118359298ff73c855c566af0353409da0cba0e96c3c779dabfc92f0140e47321e987c84370e
7
+ data.tar.gz: 4969ef8fdf1b4dd67ad8f8aa18591d0a0a353718f817a662a27af4e34a13dc7d4cc2e09a2bd345fb2736b502bcc38a9dcebc7681efb60d6123f16cfe3440dcaa
data/.travis.yml CHANGED
@@ -2,6 +2,6 @@ before_install:
2
2
  - gem install bundler
3
3
 
4
4
  rvm:
5
- - 2.3.6
6
- - 2.4.3
7
- - 2.5.0
5
+ - 2.5.8
6
+ - 2.6.6
7
+ - 2.7.1
data/README.rdoc CHANGED
@@ -28,17 +28,11 @@ http://tools.ietf.org/html/draft-ietf-oauth-v2-http-mac-01
28
28
 
29
29
  === Bearer
30
30
 
31
- Running on Heroku
32
- https://rack-oauth2-sample.heroku.com
33
-
34
31
  Source on GitHub
35
32
  https://github.com/nov/rack-oauth2-sample
36
33
 
37
34
  === MAC
38
35
 
39
- Running on Heroku
40
- https://rack-oauth2-sample-mac.heroku.com
41
-
42
36
  Source on GitHub
43
37
  https://github.com/nov/rack-oauth2-sample-mac
44
38
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.12.0
1
+ 1.14.0
@@ -73,17 +73,20 @@ module Rack
73
73
  http_client = Rack::OAuth2.http_client
74
74
 
75
75
  # NOTE:
76
- # Using Array#estract_options! for backward compatibility.
76
+ # Using Array#extract_options! for backward compatibility.
77
77
  # Until v1.0.5, the first argument was 'client_auth_method' in scalar.
78
78
  options = args.extract_options!
79
- client_auth_method = args.first || options.delete(:client_auth_method) || :basic
79
+ client_auth_method = args.first || options.delete(:client_auth_method).try(:to_sym) || :basic
80
80
 
81
81
  params[:scope] = Array(options.delete(:scope)).join(' ') if options[:scope].present?
82
82
  params.merge! options
83
83
 
84
84
  case client_auth_method
85
85
  when :basic
86
- cred = ["#{identifier}:#{secret}"].pack('m').tr("\n", '')
86
+ cred = Base64.strict_encode64 [
87
+ Util.www_form_urlencode(identifier),
88
+ Util.www_form_urlencode(secret)
89
+ ].join(':')
87
90
  headers.merge!(
88
91
  'Authorization' => "Basic #{cred}"
89
92
  )
@@ -5,7 +5,7 @@ module Rack
5
5
  module ResponseExt
6
6
  def redirect?
7
7
  ensure_finish do
8
- @response.redirect?
8
+ super
9
9
  end
10
10
  end
11
11
 
@@ -17,7 +17,7 @@ module Rack
17
17
 
18
18
  def json
19
19
  ensure_finish do
20
- @response.body
20
+ @body
21
21
  end
22
22
  end
23
23
 
@@ -39,7 +39,7 @@ module Rack
39
39
  end
40
40
 
41
41
  def ensure_finish
42
- @status, @header, @response = finish unless finished?
42
+ @status, @header, @body = finish unless finished?
43
43
  yield
44
44
  end
45
45
  end
@@ -3,14 +3,14 @@ module Rack
3
3
  module URN
4
4
  module TokenType
5
5
  JWT = 'urn:ietf:params:oauth:token-type:jwt' # RFC7519
6
- ACCESS_TOKEN = 'urn:ietf:params:oauth:token-type:access-token' # draft-ietf-oauth-token-exchange
7
- REFRESH_TOKEN = 'urn:ietf:params:oauth:token-type:refresh-token' # draft-ietf-oauth-token-exchange
6
+ ACCESS_TOKEN = 'urn:ietf:params:oauth:token-type:access_token' # RFC8693
7
+ REFRESH_TOKEN = 'urn:ietf:params:oauth:token-type:refresh_token' # RFC8693
8
8
  end
9
9
 
10
10
  module GrantType
11
11
  JWT_BEARER = 'urn:ietf:params:oauth:grant-type:jwt-bearer' # RFC7523
12
12
  SAML2_BEARER = 'urn:ietf:params:oauth:grant-type:saml2-bearer' # RFC7522
13
- TOKEN_EXCHANGE = 'urn:ietf:params:oauth:grant-type:token-exchange' # draft-ietf-oauth-token-exchange
13
+ TOKEN_EXCHANGE = 'urn:ietf:params:oauth:grant-type:token-exchange' # RFC8693
14
14
  end
15
15
 
16
16
  module ClientAssertionType
@@ -8,6 +8,10 @@ module Rack
8
8
  URI.encode(text, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
9
9
  end
10
10
 
11
+ def www_form_urlencode(text)
12
+ URI.encode_www_form_component(text)
13
+ end
14
+
11
15
  def base64_encode(text)
12
16
  Base64.encode64(text).delete("\n")
13
17
  end
data/rack-oauth2.gemspec CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
13
13
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
14
14
  s.files = `git ls-files`.split("\n")
15
15
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
- s.add_runtime_dependency 'rack', '< 2.1'
16
+ s.add_runtime_dependency 'rack', '>= 2.1.0'
17
17
  s.add_runtime_dependency 'httpclient'
18
18
  s.add_runtime_dependency 'activesupport'
19
19
  s.add_runtime_dependency 'attr_required'
@@ -1,10 +1,12 @@
1
1
  require 'spec_helper.rb'
2
2
 
3
3
  describe Rack::OAuth2::Client do
4
+ let(:client_id) { 'client_id' }
5
+ let(:client_secret) { 'client_secret' }
4
6
  let :client do
5
7
  Rack::OAuth2::Client.new(
6
- identifier: 'client_id',
7
- secret: 'client_secret',
8
+ identifier: client_id,
9
+ secret: client_secret,
8
10
  host: 'server.example.com',
9
11
  redirect_uri: 'https://client.example.com/callback'
10
12
  )
@@ -97,6 +99,24 @@ describe Rack::OAuth2::Client do
97
99
  client.access_token!
98
100
  end
99
101
 
102
+ context 'when Basic auth method is used' do
103
+ context 'when client_id is a url' do
104
+ let(:client_id) { 'https://client.example.com'}
105
+
106
+ it 'should be encoded in "application/x-www-form-urlencoded"' do
107
+ mock_response(
108
+ :post,
109
+ 'https://server.example.com/oauth2/token',
110
+ 'tokens/bearer.json',
111
+ request_header: {
112
+ 'Authorization' => 'Basic aHR0cHMlM0ElMkYlMkZjbGllbnQuZXhhbXBsZS5jb206Y2xpZW50X3NlY3JldA=='
113
+ }
114
+ )
115
+ client.access_token!
116
+ end
117
+ end
118
+ end
119
+
100
120
  context 'when jwt_bearer auth method specified' do
101
121
  context 'when client_secret is given' do
102
122
  it 'should be JWT bearer client assertion w/ auto-generated HS256-signed JWT assertion' do
@@ -10,7 +10,7 @@ describe Rack::OAuth2::Server::Resource::BadRequest do
10
10
  status, header, response = error.finish
11
11
  status.should == 400
12
12
  header['Content-Type'].should == 'application/json'
13
- response.body.should == ['{"error":"invalid_request"}']
13
+ response.should == ['{"error":"invalid_request"}']
14
14
  end
15
15
  end
16
16
  end
@@ -44,7 +44,7 @@ describe Rack::OAuth2::Server::Resource::Unauthorized do
44
44
  status.should == 401
45
45
  header['Content-Type'].should == 'application/json'
46
46
  header['WWW-Authenticate'].should == "Scheme realm=\"#{realm}\", error=\"invalid_token\""
47
- response.body.should == ['{"error":"invalid_token"}']
47
+ response.should == ['{"error":"invalid_token"}']
48
48
  end
49
49
 
50
50
  context 'when error_code is not invalid_token' do
@@ -53,7 +53,7 @@ describe Rack::OAuth2::Server::Resource::Unauthorized do
53
53
  it 'should have error_code in body but not in WWW-Authenticate header' do
54
54
  status, header, response = error_with_scheme.finish
55
55
  header['WWW-Authenticate'].should == "Scheme realm=\"#{realm}\""
56
- response.body.first.should include '"error":"something"'
56
+ response.first.should include '"error":"something"'
57
57
  end
58
58
  end
59
59
 
@@ -63,7 +63,7 @@ describe Rack::OAuth2::Server::Resource::Unauthorized do
63
63
  it 'should have error_code in body but not in WWW-Authenticate header' do
64
64
  status, header, response = error_with_scheme.finish
65
65
  header['WWW-Authenticate'].should == "Scheme realm=\"#{realm}\""
66
- response.body.first.should == '{"error":"unauthorized"}'
66
+ response.first.should == '{"error":"unauthorized"}'
67
67
  end
68
68
  end
69
69
 
@@ -74,7 +74,7 @@ describe Rack::OAuth2::Server::Resource::Unauthorized do
74
74
  it 'should use given realm' do
75
75
  status, header, response = error_with_scheme.finish
76
76
  header['WWW-Authenticate'].should == "Scheme realm=\"#{realm}\""
77
- response.body.first.should include '"error":"something"'
77
+ response.first.should include '"error":"something"'
78
78
  end
79
79
  end
80
80
  end
@@ -91,7 +91,7 @@ describe Rack::OAuth2::Server::Resource::Forbidden do
91
91
  status, header, response = error.finish
92
92
  status.should == 403
93
93
  header['Content-Type'].should == 'application/json'
94
- response.body.should == ['{"error":"insufficient_scope"}']
94
+ response.should == ['{"error":"insufficient_scope"}']
95
95
  end
96
96
  end
97
97
 
@@ -100,7 +100,7 @@ describe Rack::OAuth2::Server::Resource::Forbidden do
100
100
 
101
101
  it 'should have blank WWW-Authenticate header' do
102
102
  status, header, response = error.finish
103
- response.body.first.should include '"scope":"scope1 scope2"'
103
+ response.first.should include '"scope":"scope1 scope2"'
104
104
  end
105
105
  end
106
106
  end
@@ -10,7 +10,7 @@ describe Rack::OAuth2::Server::Token::BadRequest do
10
10
  status, header, response = error.finish
11
11
  status.should == 400
12
12
  header['Content-Type'].should == 'application/json'
13
- response.body.should == ['{"error":"invalid_request"}']
13
+ response.should == ['{"error":"invalid_request"}']
14
14
  end
15
15
  end
16
16
  end
@@ -26,7 +26,7 @@ describe Rack::OAuth2::Server::Token::Unauthorized do
26
26
  status.should == 401
27
27
  header['Content-Type'].should == 'application/json'
28
28
  header['WWW-Authenticate'].should == 'Basic realm="OAuth2 Token Endpoint"'
29
- response.body.should == ['{"error":"invalid_request"}']
29
+ response.should == ['{"error":"invalid_request"}']
30
30
  end
31
31
  end
32
32
  end
@@ -74,4 +74,4 @@ describe Rack::OAuth2::Server::Token::ErrorMethods do
74
74
  end
75
75
  end
76
76
  end
77
- end
77
+ end
@@ -30,7 +30,7 @@ describe Rack::OAuth2::Server::Token do
30
30
  it 'should fail with unsupported_grant_type' do
31
31
  status, header, response = app.call(env)
32
32
  status.should == 400
33
- response.body.first.should include '"error":"invalid_request"'
33
+ response.first.should include '"error":"invalid_request"'
34
34
  end
35
35
  end
36
36
 
@@ -14,6 +14,11 @@ describe Rack::OAuth2::Util do
14
14
  it { should == '%3D%2B%20.-%2F' }
15
15
  end
16
16
 
17
+ describe '.www_form_urlencode' do
18
+ subject { util.www_form_urlencode '=+ .-/' }
19
+ it { should == '%3D%2B+.-%2F' }
20
+ end
21
+
17
22
  describe '.base64_encode' do
18
23
  subject { util.base64_encode '=+ .-/' }
19
24
  it { should == 'PSsgLi0v' }
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-oauth2
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.12.0
4
+ version: 1.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - nov matake
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-25 00:00:00.000000000 Z
11
+ date: 2020-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "<"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '2.1'
19
+ version: 2.1.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "<"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '2.1'
26
+ version: 2.1.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: httpclient
29
29
  requirement: !ruby/object:Gem::Requirement