openid_connect 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +2 -2
- data/VERSION +1 -1
- data/lib/openid_connect.rb +1 -0
- data/lib/openid_connect/client.rb +3 -6
- data/lib/openid_connect/response_object/id_token.rb +7 -3
- data/lib/openid_connect/server/id_token.rb +46 -0
- data/lib/openid_connect/server/id_token/error.rb +30 -0
- data/spec/openid_connect/response_object/id_token_spec.rb +11 -2
- data/spec/openid_connect/server/id_token_spec.rb +67 -0
- metadata +63 -1
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
openid_connect (0.0.
|
4
|
+
openid_connect (0.0.10)
|
5
5
|
activemodel (>= 3)
|
6
6
|
attr_required (>= 0.0.3)
|
7
7
|
json (>= 1.4.3)
|
@@ -63,7 +63,7 @@ GEM
|
|
63
63
|
validate_url (0.2.0)
|
64
64
|
activemodel (>= 3.0.0)
|
65
65
|
webmock (1.7.2)
|
66
|
-
addressable (
|
66
|
+
addressable (> 2.2.5, ~> 2.2)
|
67
67
|
crack (>= 0.1.7)
|
68
68
|
|
69
69
|
PLATFORMS
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.11
|
data/lib/openid_connect.rb
CHANGED
@@ -28,12 +28,9 @@ module OpenIDConnect
|
|
28
28
|
private
|
29
29
|
|
30
30
|
def setup_required_scope(scopes)
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
else
|
35
|
-
(scopes << 'openid')
|
36
|
-
end.join(' ')
|
31
|
+
_scopes_ = Array(scopes).join(' ').split(' ')
|
32
|
+
_scopes_ << 'openid' unless _scopes_.include?('openid')
|
33
|
+
_scopes_.join(' ')
|
37
34
|
end
|
38
35
|
|
39
36
|
def handle_success_response(response)
|
@@ -8,10 +8,14 @@ module OpenIDConnect
|
|
8
8
|
attr_required :iss, :user_id, :aud, :exp
|
9
9
|
attr_optional :iso29115, :nonce, :issued_to, :secret
|
10
10
|
|
11
|
+
def initialize(attributes = {})
|
12
|
+
super
|
13
|
+
@exp = @exp.to_i
|
14
|
+
end
|
15
|
+
|
11
16
|
def verify!(client_id)
|
12
|
-
aud == client_id or
|
13
|
-
|
14
|
-
raise InvalidToken.new('Invalid audience or issued_to')
|
17
|
+
exp.to_i >= Time.now.to_i && aud == client_id or
|
18
|
+
raise InvalidToken.new('Invalid audience or expired')
|
15
19
|
end
|
16
20
|
|
17
21
|
def to_jwt
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module OpenIDConnect
|
2
|
+
module Server
|
3
|
+
class IdToken < Rack::OAuth2::Server::Abstract::Handler
|
4
|
+
def call(env)
|
5
|
+
@request = Request.new(env)
|
6
|
+
@response = Response.new(request)
|
7
|
+
super.finish
|
8
|
+
rescue Rack::OAuth2::Server::Abstract::Error => e
|
9
|
+
e.finish
|
10
|
+
end
|
11
|
+
|
12
|
+
class Request < Rack::OAuth2::Server::Abstract::Request
|
13
|
+
attr_required :id_token
|
14
|
+
|
15
|
+
# NOTE: client_id is required in Rack::OAuth2 and should not exist here.
|
16
|
+
undef_method :client_id, :client_id=
|
17
|
+
@required_attributes.delete :client_id
|
18
|
+
|
19
|
+
def initialize(env)
|
20
|
+
super
|
21
|
+
@id_token = params['id_token']
|
22
|
+
attr_missing!
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class Response < Rack::OAuth2::Server::Abstract::Response
|
27
|
+
attr_required :id_token
|
28
|
+
|
29
|
+
def protocol_params
|
30
|
+
id_token.as_json
|
31
|
+
end
|
32
|
+
|
33
|
+
def finish
|
34
|
+
attr_missing!
|
35
|
+
write Rack::OAuth2::Util.compact_hash(protocol_params).to_json
|
36
|
+
header['Content-Type'] = 'application/json'
|
37
|
+
header['Cache-Control'] = 'no-store'
|
38
|
+
header['Pragma'] = 'no-cache'
|
39
|
+
super
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
require 'openid_connect/server/id_token/error'
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module OpenIDConnect
|
2
|
+
module Server
|
3
|
+
class IdToken
|
4
|
+
class BadRequest < Rack::OAuth2::Server::Abstract::BadRequest; end
|
5
|
+
|
6
|
+
module ErrorMethods
|
7
|
+
DEFAULT_DESCRIPTION = {
|
8
|
+
:invalid_request => "The request is missing a required parameter.",
|
9
|
+
:invalid_id_token => "The ID Token is not valid for the requested resource, is malformed, is in an incorrect format, or is expired."
|
10
|
+
}
|
11
|
+
|
12
|
+
def self.included(klass)
|
13
|
+
DEFAULT_DESCRIPTION.each do |error, default_description|
|
14
|
+
klass.class_eval <<-ERROR
|
15
|
+
def #{error}!(description = "#{default_description}", options = {})
|
16
|
+
bad_request! :#{error}, description, options
|
17
|
+
end
|
18
|
+
ERROR
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def bad_request!(error, description = nil, options = {})
|
23
|
+
raise BadRequest.new(error, description, options)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
Request.send :include, ErrorMethods
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -4,12 +4,13 @@ describe OpenIDConnect::ResponseObject::IdToken do
|
|
4
4
|
let(:klass) { OpenIDConnect::ResponseObject::IdToken }
|
5
5
|
let(:id_token) { klass.new attributes }
|
6
6
|
let(:attributes) { required_attributes }
|
7
|
+
let(:ext) { 10.minutes.from_now }
|
7
8
|
let :required_attributes do
|
8
9
|
{
|
9
10
|
:iss => 'https://server.example.com',
|
10
11
|
:user_id => 'user_id',
|
11
12
|
:aud => 'client_id',
|
12
|
-
:exp =>
|
13
|
+
:exp => ext
|
13
14
|
}
|
14
15
|
end
|
15
16
|
|
@@ -22,6 +23,13 @@ describe OpenIDConnect::ResponseObject::IdToken do
|
|
22
23
|
describe '#verify!' do
|
23
24
|
context 'when valid client_id is given' do
|
24
25
|
it { id_token.verify!('client_id').should be_true }
|
26
|
+
|
27
|
+
context 'when expired' do
|
28
|
+
let(:ext) { 10.minutes.ago }
|
29
|
+
it do
|
30
|
+
expect { id_token.verify! 'client_id' }.should raise_error OpenIDConnect::ResponseObject::IdToken::InvalidToken
|
31
|
+
end
|
32
|
+
end
|
25
33
|
end
|
26
34
|
|
27
35
|
context 'otherwise' do
|
@@ -56,8 +64,9 @@ describe OpenIDConnect::ResponseObject::IdToken do
|
|
56
64
|
subject { klass.from_jwt id_token.to_jwt, 'secret' }
|
57
65
|
let(:attributes) { required_attributes.merge(:secret => 'secret') }
|
58
66
|
it { should be_a klass }
|
59
|
-
[:iss, :user_id, :aud, :
|
67
|
+
[:iss, :user_id, :aud, :secret].each do |key|
|
60
68
|
its(key) { should == attributes[key] }
|
61
69
|
end
|
70
|
+
its(:exp) { should == attributes[:exp].to_i }
|
62
71
|
end
|
63
72
|
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe OpenIDConnect::Server::IdToken do
|
4
|
+
let(:request) { Rack::MockRequest.new app }
|
5
|
+
let :app do
|
6
|
+
OpenIDConnect::Server::IdToken.new do |req, res|
|
7
|
+
res.id_token = id_token
|
8
|
+
end
|
9
|
+
end
|
10
|
+
let :env do
|
11
|
+
Rack::MockRequest.env_for(
|
12
|
+
'/id_token',
|
13
|
+
:params => params
|
14
|
+
)
|
15
|
+
end
|
16
|
+
let :params do
|
17
|
+
{:id_token => id_token.to_jwt}
|
18
|
+
end
|
19
|
+
let :id_token do
|
20
|
+
OpenIDConnect::ResponseObject::IdToken.new(
|
21
|
+
:iss => 'https://server.example.com',
|
22
|
+
:user_id => 'user_id',
|
23
|
+
:aud => 'client_id',
|
24
|
+
:exp => 1313424327,
|
25
|
+
:secret => 'secret'
|
26
|
+
)
|
27
|
+
end
|
28
|
+
subject { request.post('/id_token', :params => params) }
|
29
|
+
|
30
|
+
context 'when valid id_token is given' do
|
31
|
+
it 'should extract it' do
|
32
|
+
status, header, response = app.call(env)
|
33
|
+
status.should == 200
|
34
|
+
json = response.body.first
|
35
|
+
json.should include '"aud":"client_id"'
|
36
|
+
json.should include '"user_id":"user_id"'
|
37
|
+
json.should include '"exp":1313424327'
|
38
|
+
json.should include '"iss":"https://server.example.com"'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'otherwise' do
|
43
|
+
context 'when missing' do
|
44
|
+
let :params do
|
45
|
+
{}
|
46
|
+
end
|
47
|
+
it do
|
48
|
+
status, header, response = app.call(env)
|
49
|
+
status.should == 400
|
50
|
+
response.body.first.should include '"error":"invalid_request"'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'when rejected by authenticator' do
|
55
|
+
let :app do
|
56
|
+
OpenIDConnect::Server::IdToken.new do |req, res|
|
57
|
+
req.invalid_id_token! 'Expired or Invalid Format'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
it do
|
61
|
+
status, header, response = app.call(env)
|
62
|
+
status.should == 400
|
63
|
+
response.body.first.should include '"error":"invalid_id_token"'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
metadata
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openid_connect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
4
5
|
prerelease:
|
5
|
-
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 11
|
10
|
+
version: 0.0.11
|
6
11
|
platform: ruby
|
7
12
|
authors:
|
8
13
|
- nov matake
|
@@ -20,6 +25,9 @@ dependencies:
|
|
20
25
|
requirements:
|
21
26
|
- - ">="
|
22
27
|
- !ruby/object:Gem::Version
|
28
|
+
hash: 5
|
29
|
+
segments:
|
30
|
+
- 3
|
23
31
|
version: "3"
|
24
32
|
type: :runtime
|
25
33
|
version_requirements: *id001
|
@@ -31,6 +39,9 @@ dependencies:
|
|
31
39
|
requirements:
|
32
40
|
- - ">="
|
33
41
|
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 0
|
34
45
|
version: "0"
|
35
46
|
type: :runtime
|
36
47
|
version_requirements: *id002
|
@@ -42,6 +53,9 @@ dependencies:
|
|
42
53
|
requirements:
|
43
54
|
- - ">="
|
44
55
|
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
45
59
|
version: "0"
|
46
60
|
type: :runtime
|
47
61
|
version_requirements: *id003
|
@@ -53,6 +67,9 @@ dependencies:
|
|
53
67
|
requirements:
|
54
68
|
- - ">="
|
55
69
|
- !ruby/object:Gem::Version
|
70
|
+
hash: 3
|
71
|
+
segments:
|
72
|
+
- 0
|
56
73
|
version: "0"
|
57
74
|
type: :runtime
|
58
75
|
version_requirements: *id004
|
@@ -64,6 +81,11 @@ dependencies:
|
|
64
81
|
requirements:
|
65
82
|
- - ">="
|
66
83
|
- !ruby/object:Gem::Version
|
84
|
+
hash: 29
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
- 1
|
88
|
+
- 3
|
67
89
|
version: 0.1.3
|
68
90
|
type: :runtime
|
69
91
|
version_requirements: *id005
|
@@ -75,6 +97,11 @@ dependencies:
|
|
75
97
|
requirements:
|
76
98
|
- - ">="
|
77
99
|
- !ruby/object:Gem::Version
|
100
|
+
hash: 1
|
101
|
+
segments:
|
102
|
+
- 1
|
103
|
+
- 4
|
104
|
+
- 3
|
78
105
|
version: 1.4.3
|
79
106
|
type: :runtime
|
80
107
|
version_requirements: *id006
|
@@ -86,6 +113,11 @@ dependencies:
|
|
86
113
|
requirements:
|
87
114
|
- - ">="
|
88
115
|
- !ruby/object:Gem::Version
|
116
|
+
hash: 25
|
117
|
+
segments:
|
118
|
+
- 0
|
119
|
+
- 0
|
120
|
+
- 3
|
89
121
|
version: 0.0.3
|
90
122
|
type: :runtime
|
91
123
|
version_requirements: *id007
|
@@ -97,6 +129,10 @@ dependencies:
|
|
97
129
|
requirements:
|
98
130
|
- - ">="
|
99
131
|
- !ruby/object:Gem::Version
|
132
|
+
hash: 25
|
133
|
+
segments:
|
134
|
+
- 0
|
135
|
+
- 9
|
100
136
|
version: "0.9"
|
101
137
|
type: :runtime
|
102
138
|
version_requirements: *id008
|
@@ -108,6 +144,10 @@ dependencies:
|
|
108
144
|
requirements:
|
109
145
|
- - ">="
|
110
146
|
- !ruby/object:Gem::Version
|
147
|
+
hash: 27
|
148
|
+
segments:
|
149
|
+
- 0
|
150
|
+
- 8
|
111
151
|
version: "0.8"
|
112
152
|
type: :development
|
113
153
|
version_requirements: *id009
|
@@ -119,6 +159,10 @@ dependencies:
|
|
119
159
|
requirements:
|
120
160
|
- - ">="
|
121
161
|
- !ruby/object:Gem::Version
|
162
|
+
hash: 25
|
163
|
+
segments:
|
164
|
+
- 0
|
165
|
+
- 9
|
122
166
|
version: "0.9"
|
123
167
|
type: :development
|
124
168
|
version_requirements: *id010
|
@@ -130,6 +174,9 @@ dependencies:
|
|
130
174
|
requirements:
|
131
175
|
- - ">="
|
132
176
|
- !ruby/object:Gem::Version
|
177
|
+
hash: 7
|
178
|
+
segments:
|
179
|
+
- 2
|
133
180
|
version: "2"
|
134
181
|
type: :development
|
135
182
|
version_requirements: *id011
|
@@ -141,6 +188,11 @@ dependencies:
|
|
141
188
|
requirements:
|
142
189
|
- - ">="
|
143
190
|
- !ruby/object:Gem::Version
|
191
|
+
hash: 11
|
192
|
+
segments:
|
193
|
+
- 1
|
194
|
+
- 6
|
195
|
+
- 2
|
144
196
|
version: 1.6.2
|
145
197
|
type: :development
|
146
198
|
version_requirements: *id012
|
@@ -171,6 +223,8 @@ files:
|
|
171
223
|
- lib/openid_connect/response_object/user_info.rb
|
172
224
|
- lib/openid_connect/response_object/user_info/open_id.rb
|
173
225
|
- lib/openid_connect/response_object/user_info/open_id/address.rb
|
226
|
+
- lib/openid_connect/server/id_token.rb
|
227
|
+
- lib/openid_connect/server/id_token/error.rb
|
174
228
|
- lib/rack/oauth2/server/id_token_response.rb
|
175
229
|
- openid_connect.gemspec
|
176
230
|
- spec/helpers/webmock_helper.rb
|
@@ -190,6 +244,7 @@ files:
|
|
190
244
|
- spec/openid_connect/response_object/user_info/open_id/address_spec.rb
|
191
245
|
- spec/openid_connect/response_object/user_info/open_id_spec.rb
|
192
246
|
- spec/openid_connect/response_object_spec.rb
|
247
|
+
- spec/openid_connect/server/id_token_spec.rb
|
193
248
|
- spec/rack/oauth2/server/authorize/code_and_token_spec.rb
|
194
249
|
- spec/rack/oauth2/server/authorize/token_spec.rb
|
195
250
|
- spec/rack/oauth2/server/token/authorization_code_spec.rb
|
@@ -208,12 +263,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
208
263
|
requirements:
|
209
264
|
- - ">="
|
210
265
|
- !ruby/object:Gem::Version
|
266
|
+
hash: 3
|
267
|
+
segments:
|
268
|
+
- 0
|
211
269
|
version: "0"
|
212
270
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
213
271
|
none: false
|
214
272
|
requirements:
|
215
273
|
- - ">="
|
216
274
|
- !ruby/object:Gem::Version
|
275
|
+
hash: 3
|
276
|
+
segments:
|
277
|
+
- 0
|
217
278
|
version: "0"
|
218
279
|
requirements: []
|
219
280
|
|
@@ -240,6 +301,7 @@ test_files:
|
|
240
301
|
- spec/openid_connect/response_object/user_info/open_id/address_spec.rb
|
241
302
|
- spec/openid_connect/response_object/user_info/open_id_spec.rb
|
242
303
|
- spec/openid_connect/response_object_spec.rb
|
304
|
+
- spec/openid_connect/server/id_token_spec.rb
|
243
305
|
- spec/rack/oauth2/server/authorize/code_and_token_spec.rb
|
244
306
|
- spec/rack/oauth2/server/authorize/token_spec.rb
|
245
307
|
- spec/rack/oauth2/server/token/authorization_code_spec.rb
|