openid_connect 0.3.5 → 0.3.6

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.
data/Gemfile.lock CHANGED
@@ -1,12 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- openid_connect (0.3.5)
4
+ openid_connect (0.3.6)
5
5
  activemodel (>= 3)
6
6
  attr_required (>= 0.0.5)
7
7
  json (>= 1.4.3)
8
- json-jwt (>= 0.3.0)
9
- rack-oauth2 (>= 0.14.2)
8
+ json-jwt (>= 0.3.3)
9
+ rack-oauth2 (>= 1.0.0)
10
10
  swd (>= 0.1.2)
11
11
  tzinfo
12
12
  validate_email
@@ -35,8 +35,7 @@ GEM
35
35
  httpclient (2.3.0.1)
36
36
  i18n (0.6.1)
37
37
  json (1.7.5)
38
- json (1.7.5-java)
39
- json-jwt (0.3.2)
38
+ json-jwt (0.3.3)
40
39
  activesupport (>= 2.3)
41
40
  i18n
42
41
  json (>= 1.4.3)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.5
1
+ 0.3.6
@@ -1,6 +1,6 @@
1
1
  module OpenIDConnect
2
2
  module JWTnizable
3
- def to_jwt(key, algorithm = :RS256)
3
+ def to_jwt(key, algorithm = :RS256, &block)
4
4
  token = JSON::JWT.new as_json
5
5
  yield token if block_given?
6
6
  if algorithm != :none
@@ -26,6 +26,7 @@ module OpenIDConnect
26
26
  alias_method_chain :as_json, :user_info
27
27
 
28
28
  include JWTnizable
29
+
29
30
  class << self
30
31
  def decode(jwt_string, key)
31
32
  new JSON::JWT.decode(jwt_string, key)
@@ -7,6 +7,7 @@ module OpenIDConnect
7
7
 
8
8
  attr_required :iss, :user_id, :aud, :exp, :iat
9
9
  attr_optional :acr, :auth_time, :nonce, :user_jwk, :at_hash, :c_hash
10
+ attr_accessor :access_token, :code
10
11
 
11
12
  def initialize(attributes = {})
12
13
  super
@@ -24,6 +25,31 @@ module OpenIDConnect
24
25
  end
25
26
 
26
27
  include JWTnizable
28
+ def to_jwt_with_at_hash_and_c_hash(key, algorithm = :RS256, &block)
29
+ hash_length = algorithm.to_s[2, 3].to_i
30
+ if access_token
31
+ token = case access_token
32
+ when Rack::OAuth2::AccessToken
33
+ access_token.access_token
34
+ else
35
+ access_token
36
+ end
37
+ self.at_hash = left_half_hash_of token, hash_length
38
+ end
39
+ if code
40
+ self.c_hash = left_half_hash_of code, hash_length
41
+ end
42
+ to_jwt_without_at_hash_and_c_hash key, algorithm, &block
43
+ end
44
+ alias_method_chain :to_jwt, :at_hash_and_c_hash
45
+
46
+ private
47
+
48
+ def left_half_hash_of(string, hash_length)
49
+ digest = OpenSSL::Digest::Digest.new("SHA#{hash_length}").digest string
50
+ UrlSafeBase64.encode64 digest[0, hash_length / (2 * 8)]
51
+ end
52
+
27
53
  class << self
28
54
  def decode(jwt_string, key)
29
55
  if key == :self_issued
@@ -16,9 +16,9 @@ Gem::Specification.new do |s|
16
16
  s.add_runtime_dependency "activemodel", ">= 3"
17
17
  s.add_runtime_dependency "validate_url"
18
18
  s.add_runtime_dependency "validate_email"
19
- s.add_runtime_dependency "json-jwt", ">= 0.3.0"
19
+ s.add_runtime_dependency "json-jwt", ">= 0.3.3"
20
20
  s.add_runtime_dependency "swd", ">= 0.1.2"
21
- s.add_runtime_dependency "rack-oauth2", ">= 0.14.2"
21
+ s.add_runtime_dependency "rack-oauth2", ">= 1.0.0"
22
22
  s.add_development_dependency "rake", ">= 0.8"
23
23
  s.add_development_dependency "rspec", ">= 2"
24
24
  s.add_development_dependency "webmock", ">= 1.6.2"
@@ -137,6 +137,70 @@ describe OpenIDConnect::ResponseObject::IdToken do
137
137
  h.should include 'x5u'
138
138
  end
139
139
  end
140
+
141
+ context 'when access_token is given' do
142
+ shared_examples_for :id_token_with_at_hash do
143
+ it 'should include at_hash' do
144
+ t = id_token.to_jwt private_key
145
+ jwt = JSON::JWT.decode t, public_key
146
+ jwt.should include :at_hash
147
+ jwt.should_not include :c_hash
148
+ jwt[:at_hash].should == UrlSafeBase64.encode64(
149
+ OpenSSL::Digest::SHA256.digest('access_token')[0, 128 / 8]
150
+ )
151
+ end
152
+ end
153
+
154
+ context 'when access_token is a Rack::OAuth2::AccessToken' do
155
+ before { id_token.access_token = Rack::OAuth2::AccessToken::Bearer.new(access_token: 'access_token') }
156
+ it_should_behave_like :id_token_with_at_hash
157
+ end
158
+
159
+ context 'when access_token is a String' do
160
+ before { id_token.access_token = 'access_token' }
161
+ it_should_behave_like :id_token_with_at_hash
162
+ end
163
+ end
164
+
165
+ context 'when code is given' do
166
+ before { id_token.code = 'authorization_code' }
167
+ it 'should include at_hash' do
168
+ t = id_token.to_jwt private_key
169
+ jwt = JSON::JWT.decode t, public_key
170
+ jwt.should_not include :at_hash
171
+ jwt.should include :c_hash
172
+ jwt[:c_hash].should == UrlSafeBase64.encode64(
173
+ OpenSSL::Digest::SHA256.digest('authorization_code')[0, 128 / 8]
174
+ )
175
+ end
176
+ end
177
+
178
+ context 'when both access_token and code are given' do
179
+ before do
180
+ id_token.access_token = 'access_token'
181
+ id_token.code = 'authorization_code'
182
+ end
183
+ it 'should include at_hash' do
184
+ t = id_token.to_jwt private_key
185
+ jwt = JSON::JWT.decode t, public_key
186
+ jwt.should include :at_hash
187
+ jwt.should include :c_hash
188
+ jwt[:at_hash].should == UrlSafeBase64.encode64(
189
+ OpenSSL::Digest::SHA256.digest('access_token')[0, 128 / 8]
190
+ )
191
+ jwt[:c_hash].should == UrlSafeBase64.encode64(
192
+ OpenSSL::Digest::SHA256.digest('authorization_code')[0, 128 / 8]
193
+ )
194
+ end
195
+ end
196
+
197
+ context 'when neither access_token nor code are given' do
198
+ it 'should include at_hash' do
199
+ t = id_token.to_jwt private_key
200
+ jwt = JSON::JWT.decode t, public_key
201
+ jwt.should_not include :at_hash, :c_hash
202
+ end
203
+ end
140
204
  end
141
205
 
142
206
  describe '#as_json' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openid_connect
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-18 00:00:00.000000000 Z
12
+ date: 2012-10-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -114,7 +114,7 @@ dependencies:
114
114
  requirements:
115
115
  - - ! '>='
116
116
  - !ruby/object:Gem::Version
117
- version: 0.3.0
117
+ version: 0.3.3
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
@@ -122,7 +122,7 @@ dependencies:
122
122
  requirements:
123
123
  - - ! '>='
124
124
  - !ruby/object:Gem::Version
125
- version: 0.3.0
125
+ version: 0.3.3
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: swd
128
128
  requirement: !ruby/object:Gem::Requirement
@@ -146,7 +146,7 @@ dependencies:
146
146
  requirements:
147
147
  - - ! '>='
148
148
  - !ruby/object:Gem::Version
149
- version: 0.14.2
149
+ version: 1.0.0
150
150
  type: :runtime
151
151
  prerelease: false
152
152
  version_requirements: !ruby/object:Gem::Requirement
@@ -154,7 +154,7 @@ dependencies:
154
154
  requirements:
155
155
  - - ! '>='
156
156
  - !ruby/object:Gem::Version
157
- version: 0.14.2
157
+ version: 1.0.0
158
158
  - !ruby/object:Gem::Dependency
159
159
  name: rake
160
160
  requirement: !ruby/object:Gem::Requirement
@@ -327,7 +327,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
327
327
  version: '0'
328
328
  segments:
329
329
  - 0
330
- hash: -3677536846198614585
330
+ hash: 2386054182410413464
331
331
  required_rubygems_version: !ruby/object:Gem::Requirement
332
332
  none: false
333
333
  requirements:
@@ -336,7 +336,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
336
336
  version: '0'
337
337
  segments:
338
338
  - 0
339
- hash: -3677536846198614585
339
+ hash: 2386054182410413464
340
340
  requirements: []
341
341
  rubyforge_project:
342
342
  rubygems_version: 1.8.24