openid_connect 0.0.0 → 0.0.1
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/.gitignore +21 -4
- data/Gemfile.lock +67 -0
- data/VERSION +1 -1
- data/lib/openid_connect.rb +3 -5
- data/lib/openid_connect/response_object.rb +42 -0
- data/lib/openid_connect/response_object/id_token.rb +13 -0
- data/lib/openid_connect/response_object/user_info.rb +3 -0
- data/lib/openid_connect/response_object/user_info/open_id.rb +47 -0
- data/lib/openid_connect/response_object/user_info/open_id/address.rb +12 -0
- data/lib/rack/oauth2/server/authorize/{extensions → extension}/id_token.rb +16 -3
- data/lib/rack/oauth2/server/authorize/{extensions → extension}/id_token_and_token.rb +6 -1
- data/openid_connect.gemspec +5 -0
- data/spec/openid_connect/response_object/id_token_spec.rb +11 -0
- data/spec/openid_connect/response_object/user_info/open_id/address_spec.rb +27 -0
- data/spec/openid_connect/response_object/user_info/open_id_spec.rb +101 -0
- data/spec/openid_connect/response_object_spec.rb +55 -0
- data/spec/rack/oauth2/server/authorize/extension/id_token_and_token_spec.rb +51 -0
- data/spec/rack/oauth2/server/authorize/extension/id_token_spec.rb +51 -0
- metadata +85 -12
data/.gitignore
CHANGED
@@ -1,4 +1,21 @@
|
|
1
|
-
|
2
|
-
.
|
3
|
-
|
4
|
-
|
1
|
+
## MAC OS
|
2
|
+
.DS_Store
|
3
|
+
|
4
|
+
## TEXTMATE
|
5
|
+
*.tmproj
|
6
|
+
tmtags
|
7
|
+
|
8
|
+
## EMACS
|
9
|
+
*~
|
10
|
+
\#*
|
11
|
+
.\#*
|
12
|
+
|
13
|
+
## VIM
|
14
|
+
*.swp
|
15
|
+
|
16
|
+
## PROJECT::GENERAL
|
17
|
+
coverage
|
18
|
+
rdoc
|
19
|
+
pkg
|
20
|
+
|
21
|
+
## PROJECT::SPECIFIC
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
openid_connect (0.0.0)
|
5
|
+
activemodel
|
6
|
+
attr_required
|
7
|
+
rack-oauth2 (>= 0.9.0)
|
8
|
+
tzinfo
|
9
|
+
validate_email
|
10
|
+
validate_url
|
11
|
+
|
12
|
+
GEM
|
13
|
+
remote: http://rubygems.org/
|
14
|
+
specs:
|
15
|
+
activemodel (3.0.9)
|
16
|
+
activesupport (= 3.0.9)
|
17
|
+
builder (~> 2.1.2)
|
18
|
+
i18n (~> 0.5.0)
|
19
|
+
activesupport (3.0.9)
|
20
|
+
attr_required (0.0.3)
|
21
|
+
builder (2.1.2)
|
22
|
+
diff-lcs (1.1.2)
|
23
|
+
httpclient (2.2.1)
|
24
|
+
i18n (0.5.0)
|
25
|
+
json (1.5.3)
|
26
|
+
mail (2.3.0)
|
27
|
+
i18n (>= 0.4.0)
|
28
|
+
mime-types (~> 1.16)
|
29
|
+
treetop (~> 1.4.8)
|
30
|
+
mime-types (1.16)
|
31
|
+
polyglot (0.3.2)
|
32
|
+
rack (1.3.2)
|
33
|
+
rack-oauth2 (0.9.0)
|
34
|
+
activesupport (>= 2.3)
|
35
|
+
attr_required (>= 0.0.3)
|
36
|
+
httpclient (>= 2.2.0.2)
|
37
|
+
i18n
|
38
|
+
json (>= 1.4.3)
|
39
|
+
rack (>= 1.1)
|
40
|
+
rake (0.9.2)
|
41
|
+
rcov (0.9.10)
|
42
|
+
rspec (2.6.0)
|
43
|
+
rspec-core (~> 2.6.0)
|
44
|
+
rspec-expectations (~> 2.6.0)
|
45
|
+
rspec-mocks (~> 2.6.0)
|
46
|
+
rspec-core (2.6.4)
|
47
|
+
rspec-expectations (2.6.0)
|
48
|
+
diff-lcs (~> 1.1.2)
|
49
|
+
rspec-mocks (2.6.0)
|
50
|
+
treetop (1.4.10)
|
51
|
+
polyglot
|
52
|
+
polyglot (>= 0.3.1)
|
53
|
+
tzinfo (0.3.29)
|
54
|
+
validate_email (0.1.5)
|
55
|
+
activemodel (>= 3.0)
|
56
|
+
mail (>= 2.2.5)
|
57
|
+
validate_url (0.2.0)
|
58
|
+
activemodel (>= 3.0.0)
|
59
|
+
|
60
|
+
PLATFORMS
|
61
|
+
ruby
|
62
|
+
|
63
|
+
DEPENDENCIES
|
64
|
+
openid_connect!
|
65
|
+
rake (>= 0.8)
|
66
|
+
rcov (>= 0.9)
|
67
|
+
rspec (>= 2)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.1
|
data/lib/openid_connect.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
require 'rack/oauth2'
|
2
|
-
require 'rack/oauth2/server/authorize/
|
3
|
-
require 'rack/oauth2/server/authorize/
|
2
|
+
require 'rack/oauth2/server/authorize/extension/id_token'
|
3
|
+
require 'rack/oauth2/server/authorize/extension/id_token_and_token'
|
4
4
|
|
5
|
-
|
6
|
-
# Your code goes here...
|
7
|
-
end
|
5
|
+
require 'openid_connect/response_object'
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'active_model'
|
2
|
+
require 'tzinfo'
|
3
|
+
require 'validate_url'
|
4
|
+
require 'validate_email'
|
5
|
+
require 'attr_required'
|
6
|
+
require 'attr_optional'
|
7
|
+
|
8
|
+
module OpenIDConnect
|
9
|
+
class ResponseObject
|
10
|
+
include ActiveModel::Validations, AttrRequired, AttrOptional
|
11
|
+
|
12
|
+
def initialize(attributes = {})
|
13
|
+
all_attriutes.each do |_attr_|
|
14
|
+
self.send :"#{_attr_}=", attributes[_attr_]
|
15
|
+
end
|
16
|
+
attr_missing!
|
17
|
+
end
|
18
|
+
|
19
|
+
def all_attriutes
|
20
|
+
required_attributes + optional_attributes
|
21
|
+
end
|
22
|
+
|
23
|
+
def require_at_least_one_attributes
|
24
|
+
all_blank = all_attriutes.all? do |key|
|
25
|
+
self.send(key).blank?
|
26
|
+
end
|
27
|
+
errors.add :base, 'At least one attribute is required' if all_blank
|
28
|
+
end
|
29
|
+
|
30
|
+
def as_json(options = {})
|
31
|
+
all_attriutes.inject({}) do |hash, _attr_|
|
32
|
+
hash.merge! _attr_ => self.send(_attr_)
|
33
|
+
end.delete_if do |key, value|
|
34
|
+
value.nil?
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
Dir[File.dirname(__FILE__) + '/response_object/*.rb'].each do |file|
|
41
|
+
require file
|
42
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module OpenIDConnect
|
2
|
+
class ResponseObject
|
3
|
+
module UserInfo
|
4
|
+
class OpenID < ResponseObject
|
5
|
+
attr_optional :id, :name, :given_name, :family_name, :middle_name, :nickname
|
6
|
+
|
7
|
+
attr_optional :phone_number
|
8
|
+
|
9
|
+
attr_optional :verified, :gender, :zoneinfo, :locale
|
10
|
+
validates_inclusion_of :verified, :in => [true, false], :allow_nil => true
|
11
|
+
validates_inclusion_of :gender, :in => [:male, :female], :allow_nil => true
|
12
|
+
validates_inclusion_of :zoneinfo, :in => TZInfo::TimezoneProxy.all.collect(&:name), :allow_nil => true
|
13
|
+
# TODO: validate locale
|
14
|
+
|
15
|
+
attr_optional :birthday, :updated_time
|
16
|
+
|
17
|
+
attr_optional :profile, :picture, :website
|
18
|
+
validates :profile, :picture, :website, :url => true, :allow_nil => true
|
19
|
+
|
20
|
+
attr_optional :email
|
21
|
+
validates :email, :email => true, :allow_nil => true
|
22
|
+
|
23
|
+
attr_optional :address
|
24
|
+
validate :validate_address
|
25
|
+
|
26
|
+
validate :require_at_least_one_attributes
|
27
|
+
|
28
|
+
def validate_address
|
29
|
+
errors.add :address, 'cannot be blank' unless address.blank? || address.valid?
|
30
|
+
end
|
31
|
+
|
32
|
+
def address=(hash_or_address)
|
33
|
+
@address = case hash_or_address
|
34
|
+
when Hash
|
35
|
+
Address.new hash_or_address
|
36
|
+
when Address
|
37
|
+
hash_or_address
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
Dir[File.dirname(__FILE__) + '/open_id/*.rb'].each do |file|
|
46
|
+
require file
|
47
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module OpenIDConnect
|
2
|
+
class ResponseObject
|
3
|
+
module UserInfo
|
4
|
+
class OpenID
|
5
|
+
class Address < ResponseObject
|
6
|
+
attr_optional :formatted, :street_address, :locality, :region, :postal_code, :country
|
7
|
+
validate :require_at_least_one_attributes
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -2,7 +2,7 @@ module Rack
|
|
2
2
|
module OAuth2
|
3
3
|
module Server
|
4
4
|
class Authorize
|
5
|
-
module
|
5
|
+
module Extension
|
6
6
|
class IdToken < Abstract::Handler
|
7
7
|
class << self
|
8
8
|
def response_type_for?(response_type)
|
@@ -16,15 +16,28 @@ module Rack
|
|
16
16
|
super
|
17
17
|
end
|
18
18
|
|
19
|
-
class Request < Authorize::
|
19
|
+
class Request < Authorize::Request
|
20
20
|
def initialize(env)
|
21
21
|
super
|
22
22
|
@response_type = :id_token
|
23
23
|
attr_missing!
|
24
24
|
end
|
25
|
+
|
26
|
+
def error_params_location
|
27
|
+
:fragment
|
28
|
+
end
|
25
29
|
end
|
26
30
|
|
27
|
-
class Response < Authorize::
|
31
|
+
class Response < Authorize::Response
|
32
|
+
attr_required :id_token
|
33
|
+
|
34
|
+
def protocol_params
|
35
|
+
super.merge :id_token => id_token.to_jwt
|
36
|
+
end
|
37
|
+
|
38
|
+
def protocol_params_location
|
39
|
+
:fragment
|
40
|
+
end
|
28
41
|
end
|
29
42
|
end
|
30
43
|
end
|
@@ -2,7 +2,7 @@ module Rack
|
|
2
2
|
module OAuth2
|
3
3
|
module Server
|
4
4
|
class Authorize
|
5
|
-
module
|
5
|
+
module Extension
|
6
6
|
class IdTokenAndToken < Abstract::Handler
|
7
7
|
class << self
|
8
8
|
def response_type_for?(response_type)
|
@@ -25,6 +25,11 @@ module Rack
|
|
25
25
|
end
|
26
26
|
|
27
27
|
class Response < Authorize::Token::Response
|
28
|
+
attr_required :id_token
|
29
|
+
|
30
|
+
def protocol_params
|
31
|
+
super.merge :id_token => id_token.to_jwt
|
32
|
+
end
|
28
33
|
end
|
29
34
|
end
|
30
35
|
end
|
data/openid_connect.gemspec
CHANGED
@@ -10,6 +10,11 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
11
11
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
12
|
s.require_paths = ["lib"]
|
13
|
+
s.add_runtime_dependency "activemodel"
|
14
|
+
s.add_runtime_dependency "validate_url"
|
15
|
+
s.add_runtime_dependency "validate_email"
|
16
|
+
s.add_runtime_dependency "tzinfo"
|
17
|
+
s.add_runtime_dependency "attr_required"
|
13
18
|
s.add_runtime_dependency "rack-oauth2", ">= 0.9.0"
|
14
19
|
s.add_development_dependency "rake", ">= 0.8"
|
15
20
|
s.add_development_dependency "rcov", ">= 0.9"
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OpenIDConnect::ResponseObject::IdToken do
|
4
|
+
let(:klass) { OpenIDConnect::ResponseObject::IdToken }
|
5
|
+
|
6
|
+
describe 'attributes' do
|
7
|
+
subject { klass }
|
8
|
+
its(:required_attributes) { should == [:iss, :user_id, :aud, :exp] }
|
9
|
+
its(:optional_attributes) { should == [:iso29115, :nonce, :issued_to] }
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OpenIDConnect::ResponseObject::UserInfo::OpenID::Address do
|
4
|
+
let(:klass) { OpenIDConnect::ResponseObject::UserInfo::OpenID::Address }
|
5
|
+
|
6
|
+
describe 'attributes' do
|
7
|
+
subject { klass }
|
8
|
+
its(:required_attributes) { should == [] }
|
9
|
+
its(:optional_attributes) { should == [:formatted, :street_address, :locality, :region, :postal_code, :country] }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'validations' do
|
13
|
+
subject do
|
14
|
+
instance = klass.new attributes
|
15
|
+
instance.valid?
|
16
|
+
instance
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'when all attributes are blank' do
|
20
|
+
let :attributes do
|
21
|
+
{}
|
22
|
+
end
|
23
|
+
its(:valid?) { should be_false }
|
24
|
+
its(:errors) { should include :base }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OpenIDConnect::ResponseObject::UserInfo::OpenID do
|
4
|
+
let(:klass) { OpenIDConnect::ResponseObject::UserInfo::OpenID }
|
5
|
+
let(:instance) { klass.new attributes }
|
6
|
+
subject { instance }
|
7
|
+
|
8
|
+
describe 'attributes' do
|
9
|
+
subject { klass }
|
10
|
+
its(:required_attributes) { should == [] }
|
11
|
+
its(:optional_attributes) do
|
12
|
+
should == [
|
13
|
+
:id, :name, :given_name, :family_name, :middle_name, :nickname,
|
14
|
+
:phone_number,
|
15
|
+
:verified, :gender, :zoneinfo, :locale,
|
16
|
+
:birthday, :updated_time,
|
17
|
+
:profile, :picture, :website,
|
18
|
+
:email,
|
19
|
+
:address
|
20
|
+
]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'validations' do
|
25
|
+
subject do
|
26
|
+
_instance_ = instance
|
27
|
+
_instance_.valid?
|
28
|
+
_instance_
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when all attributes are blank' do
|
32
|
+
let :attributes do
|
33
|
+
{}
|
34
|
+
end
|
35
|
+
its(:valid?) { should be_false }
|
36
|
+
its(:errors) { should include :base }
|
37
|
+
end
|
38
|
+
|
39
|
+
[:verified, :gender, :zoneinfo].each do |one_of_list|
|
40
|
+
context "when #{one_of_list} is invalid" do
|
41
|
+
let :attributes do
|
42
|
+
{one_of_list => 'Out of List'}
|
43
|
+
end
|
44
|
+
its(:valid?) { should be_false }
|
45
|
+
its(:errors) { should include one_of_list }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "when locale is invalid" do
|
50
|
+
it :TODO
|
51
|
+
end
|
52
|
+
|
53
|
+
[:profile, :picture, :website].each do |url|
|
54
|
+
context "when #{url} is invalid" do
|
55
|
+
let :attributes do
|
56
|
+
{url => 'Invalid'}
|
57
|
+
end
|
58
|
+
its(:valid?) { should be_false }
|
59
|
+
its(:errors) { should include url }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'when address is blank' do
|
64
|
+
let :attributes do
|
65
|
+
{:address => {}}
|
66
|
+
end
|
67
|
+
its(:valid?) { should be_false }
|
68
|
+
its(:errors) { should include :address }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe '#address=' do
|
73
|
+
context 'when Hash is given' do
|
74
|
+
let :attributes do
|
75
|
+
{:address => {}}
|
76
|
+
end
|
77
|
+
its(:address) { should be_a OpenIDConnect::ResponseObject::UserInfo::OpenID::Address }
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'when Address is given' do
|
81
|
+
let :attributes do
|
82
|
+
{:address => OpenIDConnect::ResponseObject::UserInfo::OpenID::Address.new}
|
83
|
+
end
|
84
|
+
its(:address) { should be_a OpenIDConnect::ResponseObject::UserInfo::OpenID::Address }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe '#to_json' do
|
89
|
+
let :attributes do
|
90
|
+
{
|
91
|
+
:id => 'http://example.com/nov.matake#12345',
|
92
|
+
:address => {
|
93
|
+
:formatted => 'Tokyo, Japan'
|
94
|
+
}
|
95
|
+
}
|
96
|
+
end
|
97
|
+
its(:to_json) do
|
98
|
+
should == attributes.to_json
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OpenIDConnect::ResponseObject do
|
4
|
+
class OpenIDConnect::ResponseObject::SubClass < OpenIDConnect::ResponseObject
|
5
|
+
attr_required :required
|
6
|
+
attr_optional :optional
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:klass) { OpenIDConnect::ResponseObject::SubClass }
|
10
|
+
subject { klass.new attributes }
|
11
|
+
|
12
|
+
context 'when required attributes are given' do
|
13
|
+
context 'when optional attributes are given' do
|
14
|
+
let :attributes do
|
15
|
+
{:required => 'Required', :optional => 'Optional'}
|
16
|
+
end
|
17
|
+
its(:required) { should == 'Required' }
|
18
|
+
its(:optional) { should == 'Optional' }
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'otherwise' do
|
22
|
+
let :attributes do
|
23
|
+
{:required => 'Required'}
|
24
|
+
end
|
25
|
+
its(:required) { should == 'Required' }
|
26
|
+
its(:optional) { should == nil }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'otherwise' do
|
31
|
+
context 'when optional attributes are given' do
|
32
|
+
let :attributes do
|
33
|
+
{:optional => 'Optional'}
|
34
|
+
end
|
35
|
+
it do
|
36
|
+
expect { klass.new attributes }.should raise_error AttrRequired::AttrMissing
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'otherwise' do
|
41
|
+
it do
|
42
|
+
expect { klass.new }.should raise_error AttrRequired::AttrMissing
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#as_json' do
|
48
|
+
let :attributes do
|
49
|
+
{:required => 'Required', :optional => 'Optional'}
|
50
|
+
end
|
51
|
+
its(:as_json) do
|
52
|
+
should == {:required => 'Required', :optional => 'Optional'}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rack::OAuth2::Server::Authorize::Extension::IdTokenAndToken do
|
4
|
+
let(:request) { Rack::MockRequest.new app }
|
5
|
+
let(:redirect_uri) { 'http://client.example.com/callback' }
|
6
|
+
let(:access_token) { 'access_token' }
|
7
|
+
let(:response) do
|
8
|
+
request.get("/?response_type=id_token%20token&client_id=client&redirect_uri=#{redirect_uri}")
|
9
|
+
end
|
10
|
+
|
11
|
+
context "when approved" do
|
12
|
+
subject { response }
|
13
|
+
let(:bearer_token) { Rack::OAuth2::AccessToken::Bearer.new(:access_token => access_token) }
|
14
|
+
let :app do
|
15
|
+
Rack::OAuth2::Server::Authorize.new do |request, response|
|
16
|
+
response.redirect_uri = redirect_uri
|
17
|
+
response.access_token = bearer_token
|
18
|
+
response.approve!
|
19
|
+
end
|
20
|
+
end
|
21
|
+
its(:status) { should == 302 }
|
22
|
+
its(:location) { should == "#{redirect_uri}#access_token=#{access_token}&token_type=bearer" }
|
23
|
+
|
24
|
+
context 'when refresh_token is given' do
|
25
|
+
let :bearer_token do
|
26
|
+
Rack::OAuth2::AccessToken::Bearer.new(
|
27
|
+
:access_token => access_token,
|
28
|
+
:refresh_token => 'refresh'
|
29
|
+
)
|
30
|
+
end
|
31
|
+
its(:location) { should == "#{redirect_uri}#access_token=#{access_token}&token_type=bearer" }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'when denied' do
|
36
|
+
let :app do
|
37
|
+
Rack::OAuth2::Server::Authorize.new do |request, response|
|
38
|
+
request.verify_redirect_uri! redirect_uri
|
39
|
+
request.access_denied!
|
40
|
+
end
|
41
|
+
end
|
42
|
+
it 'should redirect with error in fragment' do
|
43
|
+
response.status.should == 302
|
44
|
+
error_message = {
|
45
|
+
:error => :access_denied,
|
46
|
+
:error_description => Rack::OAuth2::Server::Authorize::ErrorMethods::DEFAULT_DESCRIPTION[:access_denied]
|
47
|
+
}
|
48
|
+
response.location.should == "#{redirect_uri}##{error_message.to_query}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rack::OAuth2::Server::Authorize::Extension::IdToken do
|
4
|
+
let(:request) { Rack::MockRequest.new app }
|
5
|
+
let(:redirect_uri) { 'http://client.example.com/callback' }
|
6
|
+
let(:access_token) { 'access_token' }
|
7
|
+
let(:response) do
|
8
|
+
request.get("/?response_type=id_token&client_id=client&redirect_uri=#{redirect_uri}")
|
9
|
+
end
|
10
|
+
|
11
|
+
context "when approved" do
|
12
|
+
subject { response }
|
13
|
+
let(:bearer_token) { Rack::OAuth2::AccessToken::Bearer.new(:access_token => access_token) }
|
14
|
+
let :app do
|
15
|
+
Rack::OAuth2::Server::Authorize.new do |request, response|
|
16
|
+
response.redirect_uri = redirect_uri
|
17
|
+
response.access_token = bearer_token
|
18
|
+
response.approve!
|
19
|
+
end
|
20
|
+
end
|
21
|
+
its(:status) { should == 302 }
|
22
|
+
its(:location) { should == "#{redirect_uri}#access_token=#{access_token}&token_type=bearer" }
|
23
|
+
|
24
|
+
context 'when refresh_token is given' do
|
25
|
+
let :bearer_token do
|
26
|
+
Rack::OAuth2::AccessToken::Bearer.new(
|
27
|
+
:access_token => access_token,
|
28
|
+
:refresh_token => 'refresh'
|
29
|
+
)
|
30
|
+
end
|
31
|
+
its(:location) { should == "#{redirect_uri}#access_token=#{access_token}&token_type=bearer" }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'when denied' do
|
36
|
+
let :app do
|
37
|
+
Rack::OAuth2::Server::Authorize.new do |request, response|
|
38
|
+
request.verify_redirect_uri! redirect_uri
|
39
|
+
request.access_denied!
|
40
|
+
end
|
41
|
+
end
|
42
|
+
it 'should redirect with error in fragment' do
|
43
|
+
response.status.should == 302
|
44
|
+
error_message = {
|
45
|
+
:error => :access_denied,
|
46
|
+
:error_description => Rack::OAuth2::Server::Authorize::ErrorMethods::DEFAULT_DESCRIPTION[:access_denied]
|
47
|
+
}
|
48
|
+
response.location.should == "#{redirect_uri}##{error_message.to_query}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
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.
|
5
|
+
version: 0.0.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- nov matake
|
@@ -10,52 +10,107 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-08-
|
13
|
+
date: 2011-08-13 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
16
|
+
name: activemodel
|
17
17
|
prerelease: false
|
18
18
|
requirement: &id001 !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0
|
23
|
+
version: "0"
|
24
24
|
type: :runtime
|
25
25
|
version_requirements: *id001
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
|
-
name:
|
27
|
+
name: validate_url
|
28
28
|
prerelease: false
|
29
29
|
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: validate_email
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: tzinfo
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
type: :runtime
|
58
|
+
version_requirements: *id004
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: attr_required
|
61
|
+
prerelease: false
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
type: :runtime
|
69
|
+
version_requirements: *id005
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rack-oauth2
|
72
|
+
prerelease: false
|
73
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 0.9.0
|
79
|
+
type: :runtime
|
80
|
+
version_requirements: *id006
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: rake
|
83
|
+
prerelease: false
|
84
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
30
85
|
none: false
|
31
86
|
requirements:
|
32
87
|
- - ">="
|
33
88
|
- !ruby/object:Gem::Version
|
34
89
|
version: "0.8"
|
35
90
|
type: :development
|
36
|
-
version_requirements: *
|
91
|
+
version_requirements: *id007
|
37
92
|
- !ruby/object:Gem::Dependency
|
38
93
|
name: rcov
|
39
94
|
prerelease: false
|
40
|
-
requirement: &
|
95
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
41
96
|
none: false
|
42
97
|
requirements:
|
43
98
|
- - ">="
|
44
99
|
- !ruby/object:Gem::Version
|
45
100
|
version: "0.9"
|
46
101
|
type: :development
|
47
|
-
version_requirements: *
|
102
|
+
version_requirements: *id008
|
48
103
|
- !ruby/object:Gem::Dependency
|
49
104
|
name: rspec
|
50
105
|
prerelease: false
|
51
|
-
requirement: &
|
106
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
52
107
|
none: false
|
53
108
|
requirements:
|
54
109
|
- - ">="
|
55
110
|
- !ruby/object:Gem::Version
|
56
111
|
version: "2"
|
57
112
|
type: :development
|
58
|
-
version_requirements: *
|
113
|
+
version_requirements: *id009
|
59
114
|
description: OpenID Connect Server & Client Library
|
60
115
|
email:
|
61
116
|
- nov@matake.jp
|
@@ -68,12 +123,24 @@ extra_rdoc_files: []
|
|
68
123
|
files:
|
69
124
|
- .gitignore
|
70
125
|
- Gemfile
|
126
|
+
- Gemfile.lock
|
71
127
|
- Rakefile
|
72
128
|
- VERSION
|
73
129
|
- lib/openid_connect.rb
|
74
|
-
- lib/
|
75
|
-
- lib/
|
130
|
+
- lib/openid_connect/response_object.rb
|
131
|
+
- lib/openid_connect/response_object/id_token.rb
|
132
|
+
- lib/openid_connect/response_object/user_info.rb
|
133
|
+
- lib/openid_connect/response_object/user_info/open_id.rb
|
134
|
+
- lib/openid_connect/response_object/user_info/open_id/address.rb
|
135
|
+
- lib/rack/oauth2/server/authorize/extension/id_token.rb
|
136
|
+
- lib/rack/oauth2/server/authorize/extension/id_token_and_token.rb
|
76
137
|
- openid_connect.gemspec
|
138
|
+
- spec/openid_connect/response_object/id_token_spec.rb
|
139
|
+
- spec/openid_connect/response_object/user_info/open_id/address_spec.rb
|
140
|
+
- spec/openid_connect/response_object/user_info/open_id_spec.rb
|
141
|
+
- spec/openid_connect/response_object_spec.rb
|
142
|
+
- spec/rack/oauth2/server/authorize/extension/id_token_and_token_spec.rb
|
143
|
+
- spec/rack/oauth2/server/authorize/extension/id_token_spec.rb
|
77
144
|
- spec/spec_helper.rb
|
78
145
|
homepage: https://github.com/nov/openid_connect
|
79
146
|
licenses: []
|
@@ -103,4 +170,10 @@ signing_key:
|
|
103
170
|
specification_version: 3
|
104
171
|
summary: OpenID Connect Server & Client Library
|
105
172
|
test_files:
|
173
|
+
- spec/openid_connect/response_object/id_token_spec.rb
|
174
|
+
- spec/openid_connect/response_object/user_info/open_id/address_spec.rb
|
175
|
+
- spec/openid_connect/response_object/user_info/open_id_spec.rb
|
176
|
+
- spec/openid_connect/response_object_spec.rb
|
177
|
+
- spec/rack/oauth2/server/authorize/extension/id_token_and_token_spec.rb
|
178
|
+
- spec/rack/oauth2/server/authorize/extension/id_token_spec.rb
|
106
179
|
- spec/spec_helper.rb
|