openid_connect 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- openid_connect (0.0.6)
4
+ openid_connect (0.0.7)
5
5
  activemodel (>= 3)
6
6
  attr_required (>= 0.0.3)
7
7
  json (>= 1.4.3)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.7
1
+ 0.0.8
@@ -1,6 +1,6 @@
1
1
  require 'json'
2
2
  require 'rack/oauth2'
3
- require 'rack/oauth2/server/authorize/token_with_id_token'
3
+ require 'rack/oauth2/server/id_token_support'
4
4
 
5
5
  require 'openid_connect/exception'
6
6
  require 'openid_connect/client'
@@ -0,0 +1,21 @@
1
+ module IdTokenSupport
2
+ def self.included(klass)
3
+ klass.send :attr_optional, :id_token
4
+ klass.class_eval do
5
+ def protocol_params_with_id_token
6
+ protocol_params_without_id_token.merge(
7
+ :id_token => id_token.try(:to_jwt)
8
+ )
9
+ end
10
+ alias_method_chain :protocol_params, :id_token
11
+ end
12
+ end
13
+ end
14
+
15
+ class Rack::OAuth2::Server::Token::Response
16
+ include TokenWithIdToken
17
+ end
18
+
19
+ class Rack::OAuth2::Server::Authorize::Token::Response
20
+ include TokenWithIdToken
21
+ end
@@ -2,6 +2,7 @@ require 'spec_helper.rb'
2
2
  require 'rack/oauth2/server/authorize/extension/code_and_token'
3
3
 
4
4
  describe Rack::OAuth2::Server::Authorize::Extension::CodeAndToken do
5
+ subject { response }
5
6
  let(:request) { Rack::MockRequest.new app }
6
7
  let(:response) { request.get("/?response_type=code%20token&client_id=client") }
7
8
  let(:redirect_uri) { 'http://client.example.com/callback' }
@@ -17,7 +18,6 @@ describe Rack::OAuth2::Server::Authorize::Extension::CodeAndToken do
17
18
  end
18
19
 
19
20
  context "when id_token is given" do
20
- subject { response }
21
21
  let :app do
22
22
  Rack::OAuth2::Server::Authorize.new do |request, response|
23
23
  response.redirect_uri = redirect_uri
@@ -32,7 +32,6 @@ describe Rack::OAuth2::Server::Authorize::Extension::CodeAndToken do
32
32
  end
33
33
 
34
34
  context "otherwise" do
35
- subject { response }
36
35
  let :app do
37
36
  Rack::OAuth2::Server::Authorize.new do |request, response|
38
37
  response.redirect_uri = redirect_uri
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper.rb'
2
2
 
3
3
  describe Rack::OAuth2::Server::Authorize::Token do
4
+ subject { response }
4
5
  let(:request) { Rack::MockRequest.new app }
5
6
  let(:response) { request.get("/?response_type=token&client_id=client") }
6
7
  let(:redirect_uri) { 'http://client.example.com/callback' }
@@ -16,7 +17,6 @@ describe Rack::OAuth2::Server::Authorize::Token do
16
17
  end
17
18
 
18
19
  context "when id_token is given" do
19
- subject { response }
20
20
  let :app do
21
21
  Rack::OAuth2::Server::Authorize.new do |request, response|
22
22
  response.redirect_uri = redirect_uri
@@ -30,7 +30,6 @@ describe Rack::OAuth2::Server::Authorize::Token do
30
30
  end
31
31
 
32
32
  context "otherwise" do
33
- subject { response }
34
33
  let :app do
35
34
  Rack::OAuth2::Server::Authorize.new do |request, response|
36
35
  response.redirect_uri = redirect_uri
@@ -0,0 +1,44 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe Rack::OAuth2::Server::Token::AuthorizationCode do
4
+ subject { response }
5
+ let(:request) { Rack::MockRequest.new app }
6
+ let :response do
7
+ request.post('/', :params => {
8
+ :grant_type => 'authorization_code',
9
+ :client_id => 'client_id',
10
+ :code => 'authorization_code',
11
+ :redirect_uri => 'http://client.example.com/callback'
12
+ })
13
+ end
14
+ let :id_token do
15
+ OpenIDConnect::ResponseObject::IdToken.new(
16
+ :iss => 'https://server.example.com',
17
+ :user_id => 'user_id',
18
+ :aud => 'client_id',
19
+ :exp => 1313424327,
20
+ :secret => 'secret'
21
+ )
22
+ end
23
+
24
+ context "when id_token is given" do
25
+ let :app do
26
+ Rack::OAuth2::Server::Token.new do |request, response|
27
+ response.access_token = Rack::OAuth2::AccessToken::Bearer.new(:access_token => 'access_token')
28
+ response.id_token = id_token
29
+ end
30
+ end
31
+ its(:status) { should == 200 }
32
+ its(:body) { should include "\"id_token\":\"#{id_token.to_jwt}\"" }
33
+ end
34
+
35
+ context "otherwise" do
36
+ let :app do
37
+ Rack::OAuth2::Server::Token.new do |request, response|
38
+ response.access_token = Rack::OAuth2::AccessToken::Bearer.new(:access_token => 'access_token')
39
+ end
40
+ end
41
+ its(:status) { should == 200 }
42
+ its(:body) { should_not include "id_token" }
43
+ end
44
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe Rack::OAuth2::Server::Token::RefreshToken do
4
+ subject { response }
5
+ let(:request) { Rack::MockRequest.new app }
6
+ let :response do
7
+ request.post('/', :params => {
8
+ :grant_type => "refresh_token",
9
+ :client_id => "client_id",
10
+ :refresh_token => "refresh_token"
11
+ })
12
+ end
13
+ let :id_token do
14
+ OpenIDConnect::ResponseObject::IdToken.new(
15
+ :iss => 'https://server.example.com',
16
+ :user_id => 'user_id',
17
+ :aud => 'client_id',
18
+ :exp => 1313424327,
19
+ :secret => 'secret'
20
+ )
21
+ end
22
+
23
+ context "when id_token is given" do
24
+ let :app do
25
+ Rack::OAuth2::Server::Token.new do |request, response|
26
+ response.access_token = Rack::OAuth2::AccessToken::Bearer.new(:access_token => 'access_token')
27
+ response.id_token = id_token
28
+ end
29
+ end
30
+ its(:status) { should == 200 }
31
+ its(:body) { should include "\"id_token\":\"#{id_token.to_jwt}\"" }
32
+ end
33
+
34
+ context "otherwise" do
35
+ let :app do
36
+ Rack::OAuth2::Server::Token.new do |request, response|
37
+ response.access_token = Rack::OAuth2::AccessToken::Bearer.new(:access_token => 'access_token')
38
+ end
39
+ end
40
+ its(:status) { should == 200 }
41
+ its(:body) { should_not include "id_token" }
42
+ end
43
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: openid_connect
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.7
5
+ version: 0.0.8
6
6
  platform: ruby
7
7
  authors:
8
8
  - nov matake
@@ -171,7 +171,7 @@ files:
171
171
  - lib/openid_connect/response_object/user_info.rb
172
172
  - lib/openid_connect/response_object/user_info/open_id.rb
173
173
  - lib/openid_connect/response_object/user_info/open_id/address.rb
174
- - lib/rack/oauth2/server/authorize/token_with_id_token.rb
174
+ - lib/rack/oauth2/server/id_token_support.rb
175
175
  - openid_connect.gemspec
176
176
  - spec/helpers/webmock_helper.rb
177
177
  - spec/mock_response/access_token/bearer.json
@@ -191,6 +191,8 @@ files:
191
191
  - spec/openid_connect/response_object_spec.rb
192
192
  - spec/rack/oauth2/server/authorize/code_and_token_spec.rb
193
193
  - spec/rack/oauth2/server/authorize/token_spec.rb
194
+ - spec/rack/oauth2/server/token/authorization_code_spec.rb
195
+ - spec/rack/oauth2/server/token/refresh_token_spec.rb
194
196
  - spec/spec_helper.rb
195
197
  homepage: https://github.com/nov/openid_connect
196
198
  licenses: []
@@ -238,4 +240,6 @@ test_files:
238
240
  - spec/openid_connect/response_object_spec.rb
239
241
  - spec/rack/oauth2/server/authorize/code_and_token_spec.rb
240
242
  - spec/rack/oauth2/server/authorize/token_spec.rb
243
+ - spec/rack/oauth2/server/token/authorization_code_spec.rb
244
+ - spec/rack/oauth2/server/token/refresh_token_spec.rb
241
245
  - spec/spec_helper.rb
@@ -1,10 +0,0 @@
1
- class Rack::OAuth2::Server::Authorize::Token::Response
2
- attr_optional :id_token
3
-
4
- def protocol_params_with_id_token
5
- protocol_params_without_id_token.merge(
6
- :id_token => id_token.try(:to_jwt)
7
- )
8
- end
9
- alias_method_chain :protocol_params, :id_token
10
- end