openid_connect 0.0.9 → 0.0.10

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.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- openid_connect (0.0.8)
4
+ openid_connect (0.0.9)
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.9
1
+ 0.0.10
@@ -1,6 +1,6 @@
1
1
  require 'json'
2
2
  require 'rack/oauth2'
3
- require 'rack/oauth2/id_token_support'
3
+ require 'rack/oauth2/server/id_token_response'
4
4
 
5
5
  require 'openid_connect/exception'
6
6
  require 'openid_connect/client'
@@ -1,6 +1,7 @@
1
1
  module OpenIDConnect
2
2
  class AccessToken < Rack::OAuth2::AccessToken::Bearer
3
3
  attr_required :client
4
+ attr_optional :id_token
4
5
 
5
6
  def initialize(attributes = {})
6
7
  super
@@ -1,14 +1,11 @@
1
- require 'rack/oauth2/client/error'
2
- require 'rack/oauth2/client/grant'
3
-
4
1
  module OpenIDConnect
5
2
  class Client < Rack::OAuth2::Client
6
- attr_optional :introspection_endpoint, :user_info_endpoint
3
+ attr_optional :check_session_endpoint, :user_info_endpoint
7
4
 
8
5
  def initialize(attributes = {})
9
6
  super
10
7
  @user_info_endpoint ||= '/user_info'
11
- @introspection_endpoint ||= '/id_tokens'
8
+ @check_session_endpoint ||= '/id_token'
12
9
  end
13
10
 
14
11
  def authorization_uri(params = {})
@@ -20,14 +17,8 @@ module OpenIDConnect
20
17
  )
21
18
  end
22
19
 
23
- def access_token!
24
- token = super
25
- raise Exception.new("Unexpected Token Type: #{token.token_type}") unless token.token_type == :bearer
26
- AccessToken.new token.token_response.merge(:client => self)
27
- end
28
-
29
- def introspection_uri
30
- absolute_uri_for introspection_endpoint
20
+ def check_session_uri
21
+ absolute_uri_for check_session_endpoint
31
22
  end
32
23
 
33
24
  def user_info_uri
@@ -44,5 +35,17 @@ module OpenIDConnect
44
35
  (scopes << 'openid')
45
36
  end.join(' ')
46
37
  end
38
+
39
+ def handle_success_response(response)
40
+ token_hash = JSON.parse(response.body).with_indifferent_access
41
+ case token_type = token_hash[:token_type].try(:downcase)
42
+ when 'bearer'
43
+ AccessToken.new token_hash.merge(:client => self)
44
+ else
45
+ raise Exception.new("Unexpected Token Type: #{token_type}")
46
+ end
47
+ rescue JSON::ParserError
48
+ raise Exception.new("Unknown Token Type")
49
+ end
47
50
  end
48
51
  end
@@ -0,0 +1,17 @@
1
+ module Rack::OAuth2::Server
2
+ module IdTokenResponse
3
+ def self.included(klass)
4
+ klass.send :attr_optional, :id_token
5
+ klass.class_eval do
6
+ def protocol_params_with_id_token
7
+ protocol_params_without_id_token.merge(
8
+ :id_token => id_token.try(:to_jwt)
9
+ )
10
+ end
11
+ alias_method_chain :protocol_params, :id_token
12
+ end
13
+ end
14
+ end
15
+ Token::Response.send :include, IdTokenResponse
16
+ Authorize::Token::Response.send :include, IdTokenResponse
17
+ end
@@ -39,23 +39,13 @@ describe OpenIDConnect::AccessToken do
39
39
  )
40
40
  end
41
41
  its(:id_token) { should be_a OpenIDConnect::ResponseObject::IdToken }
42
- describe '#token_response' do
43
- let(:token_response) { access_token.token_response }
44
- it 'should stringfy it' do
45
- token_response[:id_token].should be_a String
46
- end
47
- end
42
+ its(:token_response) { should_not include :id_token }
48
43
  end
49
44
 
50
45
  context 'when JWT string' do
51
46
  let(:id_token) { 'id_token' }
52
47
  its(:id_token) { should == 'id_token' }
53
- describe '#token_response' do
54
- let(:token_response) { access_token.token_response }
55
- it 'should keep it as is' do
56
- token_response[:id_token].should == 'id_token'
57
- end
58
- end
48
+ its(:token_response) { should_not include :id_token }
59
49
  end
60
50
  end
61
51
 
@@ -19,12 +19,12 @@ describe OpenIDConnect::Client do
19
19
  end
20
20
  its(:authorization_uri) { should include 'https://server.example.com/oauth2/authorize' }
21
21
  its(:authorization_uri) { should include 'scope=openid' }
22
- its(:introspection_uri) { should == 'https://server.example.com/id_tokens' }
22
+ its(:check_session_uri) { should == 'https://server.example.com/id_token' }
23
23
  its(:user_info_uri) { should == 'https://server.example.com/user_info' }
24
24
  end
25
25
 
26
26
  context 'otherwise' do
27
- [:authorization_uri, :introspection_uri, :user_info_uri].each do |endpoint|
27
+ [:authorization_uri, :check_session_uri, :user_info_uri].each do |endpoint|
28
28
  describe endpoint do
29
29
  it do
30
30
  expect { client.send endpoint }.should raise_error 'No Host Info'
@@ -94,8 +94,7 @@ describe OpenIDConnect::ResponseObject::UserInfo::OpenID do
94
94
  }
95
95
  }
96
96
  end
97
- its(:to_json) do
98
- should == attributes.to_json
99
- end
97
+ its(:to_json) { should include '"id":"http://example.com/nov.matake#12345"'}
98
+ its(:to_json) { should include '"address":{"formatted":"Tokyo, Japan"}'}
100
99
  end
101
100
  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.9
5
+ version: 0.0.10
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/id_token_support.rb
174
+ - lib/rack/oauth2/server/id_token_response.rb
175
175
  - openid_connect.gemspec
176
176
  - spec/helpers/webmock_helper.rb
177
177
  - spec/mock_response/access_token/bearer.json
@@ -1,42 +0,0 @@
1
- module Rack::OAuth2
2
- module IdTokenSupport
3
- def self.included(klass)
4
- klass.send :attr_optional, :id_token
5
- end
6
-
7
- module AccessTokenExt
8
- def self.included(klass)
9
- klass.send :include, IdTokenSupport
10
- klass.class_eval do
11
- def token_response_with_id_token(options = {})
12
- token_response_without_id_token.merge(
13
- :id_token => if id_token.respond_to?(:to_jwt)
14
- id_token.to_jwt
15
- else
16
- id_token
17
- end
18
- )
19
- end
20
- alias_method_chain :token_response, :id_token
21
- end
22
- end
23
- end
24
- AccessToken::Bearer.send :include, IdTokenSupport, AccessTokenExt
25
-
26
- module ServerResponseExt
27
- def self.included(klass)
28
- klass.send :include, IdTokenSupport
29
- klass.class_eval do
30
- def protocol_params_with_id_token
31
- protocol_params_without_id_token.merge(
32
- :id_token => id_token.try(:to_jwt)
33
- )
34
- end
35
- alias_method_chain :protocol_params, :id_token
36
- end
37
- end
38
- end
39
- Server::Token::Response.send :include, ServerResponseExt
40
- Server::Authorize::Token::Response.send :include, ServerResponseExt
41
- end
42
- end