rack-oauth2 1.3.0 → 1.3.1

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: 3156ef7d62d479a2dc6440483abe7b39c85e9821
4
- data.tar.gz: 790fb2e44712d9f7ec357aa5a1b8046e3ef8e8d6
3
+ metadata.gz: 3c9ef17a769a22815156fa9a794447925496fe4c
4
+ data.tar.gz: d613d947f2a001b1c5b172919a7c118e678e4682
5
5
  SHA512:
6
- metadata.gz: 9e371dbbf23d56d48e72c2c6b185667a9b9b2db2cf1094551f05c1d6b655e25944a8fbcd08d64ec2b32d8e820665351687e3a878399cc90490c012f0b2dd8e58
7
- data.tar.gz: 1d847249e2170350d1d303a16332a01cbe8fb902476dbd097e848d78094b82bbfa178e3d8475543de20024b2d7a1bb820b9bb086e85607366a781ff57c4ae611
6
+ metadata.gz: ec69d172bb0cfaa870990b0752c4488cd006328b5ccc8dddb282034a49b7915a6c0e3658340ff59c7fce17f2cab95ba61de25403682cc9704dc6587acaf312b2
7
+ data.tar.gz: 74a77e9be5eb7e8778e0c7b077eb22a2fc72555d2a076fdf9dde3c4c7f18f5c87e5594db54d7316de69f8b03770a5132b918f105b2eb3c323e022d1a6de9b774
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.0
1
+ 1.3.1
data/lib/rack/oauth2.rb CHANGED
@@ -61,6 +61,7 @@ module Rack
61
61
  end
62
62
  end
63
63
 
64
+ require 'rack/oauth2/urn'
64
65
  require 'rack/oauth2/util'
65
66
  require 'rack/oauth2/server'
66
67
  require 'rack/oauth2/client'
@@ -57,6 +57,13 @@ module Rack
57
57
  )
58
58
  end
59
59
 
60
+ def subject_token=(subject_token, subject_token_type = URN::TokenType::JWT)
61
+ @grant = Grant::TokenExchange.new(
62
+ subject_token: subject_token,
63
+ subject_token_type: subject_token_type
64
+ )
65
+ end
66
+
60
67
  def access_token!(*args)
61
68
  headers, params = {}, @grant.as_json
62
69
 
@@ -32,4 +32,5 @@ require 'rack/oauth2/client/grant/password'
32
32
  require 'rack/oauth2/client/grant/client_credentials'
33
33
  require 'rack/oauth2/client/grant/refresh_token'
34
34
  require 'rack/oauth2/client/grant/jwt_bearer'
35
- require 'rack/oauth2/client/grant/saml2_bearer'
35
+ require 'rack/oauth2/client/grant/saml2_bearer'
36
+ require 'rack/oauth2/client/grant/token_exchange'
@@ -6,7 +6,7 @@ module Rack
6
6
  attr_required :assertion
7
7
 
8
8
  def grant_type
9
- 'urn:ietf:params:oauth:grant-type:jwt-bearer'
9
+ URN::GrantType::JWT_BEARER
10
10
  end
11
11
  end
12
12
  end
@@ -6,7 +6,7 @@ module Rack
6
6
  attr_required :assertion
7
7
 
8
8
  def grant_type
9
- 'urn:ietf:params:oauth:grant-type:saml2-bearer'
9
+ URN::GrantType::SAML2_BEARER
10
10
  end
11
11
  end
12
12
  end
@@ -0,0 +1,15 @@
1
+ module Rack
2
+ module OAuth2
3
+ class Client
4
+ class Grant
5
+ class TokenExchange < Grant
6
+ attr_required :subject_token, :subject_token_type
7
+
8
+ def grant_type
9
+ URN::GrantType::TOKEN_EXCHANGE
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,4 +1,5 @@
1
1
  require 'rack/oauth2/server/abstract'
2
2
  require 'rack/oauth2/server/authorize'
3
3
  require 'rack/oauth2/server/token'
4
- require 'rack/oauth2/server/resource'
4
+ require 'rack/oauth2/server/resource'
5
+ require 'rack/oauth2/server/rails'
@@ -11,8 +11,13 @@ module Rack
11
11
  super.merge(state: state)
12
12
  end
13
13
 
14
+ def redirect?
15
+ redirect_uri.present? &&
16
+ protocol_params_location.present?
17
+ end
18
+
14
19
  def finish
15
- if redirect_uri.present? && protocol_params_location.present?
20
+ if redirect?
16
21
  super do |response|
17
22
  response.redirect Util.redirect_uri(redirect_uri, protocol_params_location, protocol_params)
18
23
  end
@@ -0,0 +1,14 @@
1
+ module Rack
2
+ module OAuth2
3
+ module Server
4
+ module Rails
5
+ REQUEST = 'rack_oauth2.request'
6
+ RESPONSE = 'rack_oauth2.response'
7
+ ERROR = 'rack_oauth2.error'
8
+ end
9
+ end
10
+ end
11
+ end
12
+
13
+ require 'rack/oauth2/server/rails/response_ext'
14
+ require 'rack/oauth2/server/rails/authorize'
@@ -0,0 +1,44 @@
1
+ module Rack
2
+ module OAuth2
3
+ module Server
4
+ module Rails
5
+ class Authorize < Server::Authorize
6
+ def initialize(app)
7
+ super()
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ prepare_oauth_env env
13
+ @app.call env
14
+ rescue Rack::OAuth2::Server::Abstract::Error => e
15
+ e.finish
16
+ end
17
+
18
+ private
19
+
20
+ def prepare_oauth_env(env)
21
+ response_type = response_type_for(
22
+ Server::Authorize::Request.new(env)
23
+ ).new
24
+ response_type.call(env)
25
+ response_type.response.extend ResponseExt
26
+ env[REQUEST] = response_type.request
27
+ env[RESPONSE] = response_type.response
28
+ rescue Rack::OAuth2::Server::Abstract::Error => e
29
+ env[ERROR] = e
30
+ end
31
+
32
+ module ResponseExt
33
+ include Rails::ResponseExt
34
+
35
+ def approve!
36
+ super
37
+ finish
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,49 @@
1
+ module Rack
2
+ module OAuth2
3
+ module Server
4
+ module Rails
5
+ module ResponseExt
6
+ def redirect?
7
+ ensure_finish do
8
+ @response.redirect?
9
+ end
10
+ end
11
+
12
+ def location
13
+ ensure_finish do
14
+ super
15
+ end
16
+ end
17
+
18
+ def json
19
+ ensure_finish do
20
+ @response.body
21
+ end
22
+ end
23
+
24
+ def header
25
+ ensure_finish do
26
+ @header
27
+ end
28
+ end
29
+
30
+ def finish
31
+ @finished = true
32
+ super
33
+ end
34
+
35
+ private
36
+
37
+ def finished?
38
+ !!@finished
39
+ end
40
+
41
+ def ensure_finish
42
+ @status, @header, @response = finish unless finished?
43
+ yield
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -23,9 +23,9 @@ module Rack
23
23
  ClientCredentials
24
24
  when 'refresh_token'
25
25
  RefreshToken
26
- when 'urn:ietf:params:oauth:grant-type:jwt-bearer'
26
+ when URN::GrantType::JWT_BEARER
27
27
  JWTBearer
28
- when 'urn:ietf:params:oauth:grant-type:saml2-bearer'
28
+ when URN::GrantType::SAML2_BEARER
29
29
  SAML2Bearer
30
30
  when ''
31
31
  request.attr_missing!
@@ -15,7 +15,7 @@ module Rack
15
15
 
16
16
  def initialize(env)
17
17
  super
18
- @grant_type = 'urn:ietf:params:oauth:grant-type:jwt-bearer'
18
+ @grant_type = URN::GrantType::JWT_BEARER
19
19
  @assertion = params['assertion']
20
20
  attr_missing!
21
21
  end
@@ -15,7 +15,7 @@ module Rack
15
15
 
16
16
  def initialize(env)
17
17
  super
18
- @grant_type = 'urn:ietf:params:oauth:grant-type:saml2-bearer'
18
+ @grant_type = URN::GrantType::SAML2_BEARER
19
19
  @assertion = params['assertion']
20
20
  attr_missing!
21
21
  end
@@ -0,0 +1,22 @@
1
+ module Rack
2
+ module OAuth2
3
+ module URN
4
+ module TokenType
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
8
+ end
9
+
10
+ module GrantType
11
+ JWT_BEARER = 'urn:ietf:params:oauth:grant-type:jwt-bearer' # RFC7523
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
14
+ end
15
+
16
+ module ClientAssertionType
17
+ JWT_BEARER = 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer' # RFC7523
18
+ SAML2_BEARER = 'urn:ietf:params:oauth:client-assertion-type:saml2-bearer' # RFC7522
19
+ end
20
+ end
21
+ end
22
+ end
data/rack-oauth2.gemspec CHANGED
@@ -23,5 +23,5 @@ Gem::Specification.new do |s|
23
23
  s.add_development_dependency "simplecov"
24
24
  s.add_development_dependency "rspec"
25
25
  s.add_development_dependency "rspec-its"
26
- s.add_development_dependency "webmock"
26
+ s.add_development_dependency "webmock", "< 1.24"
27
27
  end
@@ -79,7 +79,7 @@ describe Rack::OAuth2::Util do
79
79
  end
80
80
  end
81
81
 
82
- context 'when exactry same' do
82
+ context 'when exactly same' do
83
83
  it { util.uri_match?(uri, uri).should == true }
84
84
  end
85
85
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-oauth2
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - nov matake
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-16 00:00:00.000000000 Z
11
+ date: 2016-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -140,16 +140,16 @@ dependencies:
140
140
  name: webmock
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ">="
143
+ - - "<"
144
144
  - !ruby/object:Gem::Version
145
- version: '0'
145
+ version: '1.24'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - ">="
150
+ - - "<"
151
151
  - !ruby/object:Gem::Version
152
- version: '0'
152
+ version: '1.24'
153
153
  description: OAuth 2.0 Server & Client Library. Both Bearer and MAC token type are
154
154
  supported.
155
155
  email: nov@matake.jp
@@ -186,6 +186,7 @@ files:
186
186
  - lib/rack/oauth2/client/grant/password.rb
187
187
  - lib/rack/oauth2/client/grant/refresh_token.rb
188
188
  - lib/rack/oauth2/client/grant/saml2_bearer.rb
189
+ - lib/rack/oauth2/client/grant/token_exchange.rb
189
190
  - lib/rack/oauth2/debugger.rb
190
191
  - lib/rack/oauth2/debugger/request_filter.rb
191
192
  - lib/rack/oauth2/server.rb
@@ -200,6 +201,9 @@ files:
200
201
  - lib/rack/oauth2/server/authorize/extension.rb
201
202
  - lib/rack/oauth2/server/authorize/extension/code_and_token.rb
202
203
  - lib/rack/oauth2/server/authorize/token.rb
204
+ - lib/rack/oauth2/server/rails.rb
205
+ - lib/rack/oauth2/server/rails/authorize.rb
206
+ - lib/rack/oauth2/server/rails/response_ext.rb
203
207
  - lib/rack/oauth2/server/resource.rb
204
208
  - lib/rack/oauth2/server/resource/bearer.rb
205
209
  - lib/rack/oauth2/server/resource/bearer/error.rb
@@ -216,6 +220,7 @@ files:
216
220
  - lib/rack/oauth2/server/token/password.rb
217
221
  - lib/rack/oauth2/server/token/refresh_token.rb
218
222
  - lib/rack/oauth2/server/token/saml2_bearer.rb
223
+ - lib/rack/oauth2/urn.rb
219
224
  - lib/rack/oauth2/util.rb
220
225
  - rack-oauth2.gemspec
221
226
  - spec/helpers/time.rb