openid_connect 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +7 -6
- data/LICENSE +20 -0
- data/README.rdoc +31 -0
- data/VERSION +1 -1
- data/lib/openid_connect.rb +3 -0
- data/lib/openid_connect/access_token.rb +38 -0
- data/lib/openid_connect/client.rb +36 -0
- data/lib/openid_connect/exception.rb +30 -0
- data/openid_connect.gemspec +5 -4
- metadata +30 -14
data/Gemfile.lock
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
openid_connect (0.0.
|
5
|
-
activemodel
|
6
|
-
attr_required
|
7
|
-
|
8
|
-
|
4
|
+
openid_connect (0.0.2)
|
5
|
+
activemodel (>= 3)
|
6
|
+
attr_required (>= 0.0.3)
|
7
|
+
json (>= 1.4.3)
|
8
|
+
jwt (>= 0.1.3)
|
9
|
+
rack-oauth2 (>= 0.9)
|
9
10
|
tzinfo
|
10
11
|
validate_email
|
11
12
|
validate_url
|
@@ -33,7 +34,7 @@ GEM
|
|
33
34
|
mime-types (1.16)
|
34
35
|
polyglot (0.3.2)
|
35
36
|
rack (1.3.2)
|
36
|
-
rack-oauth2 (0.9.
|
37
|
+
rack-oauth2 (0.9.1)
|
37
38
|
activesupport (>= 2.3)
|
38
39
|
attr_required (>= 0.0.3)
|
39
40
|
httpclient (>= 2.2.0.2)
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 nov matake
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
= OpenIDConnect
|
2
|
+
|
3
|
+
OpenID Connect Server & Client Library
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
gem install openid_connect
|
8
|
+
|
9
|
+
== Resources
|
10
|
+
|
11
|
+
* View Source on GitHub (http://github.com/nov/openid_connect)
|
12
|
+
* Report Issues on GitHub (http://github.com/nov/openid_connect/issues)
|
13
|
+
|
14
|
+
== Examples
|
15
|
+
|
16
|
+
* Running on Heroku (https://openid-connect.herokuapp.com)
|
17
|
+
* Source on GitHub (https://github.com/nov/openid_connect_sample)
|
18
|
+
|
19
|
+
== Note on Patches/Pull Requests
|
20
|
+
|
21
|
+
* Fork the project.
|
22
|
+
* Make your feature addition or bug fix.
|
23
|
+
* Add tests for it. This is important so I don't break it in a
|
24
|
+
future version unintentionally.
|
25
|
+
* Commit, do not mess with rakefile, version, or history.
|
26
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
27
|
+
* Send me a pull request. Bonus points for topic branches.
|
28
|
+
|
29
|
+
== Copyright
|
30
|
+
|
31
|
+
Copyright (c) 2011 nov matake. See LICENSE for details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/lib/openid_connect.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
+
require 'json'
|
1
2
|
require 'rack/oauth2'
|
2
3
|
require 'rack/oauth2/server/authorize/extension/id_token'
|
3
4
|
require 'rack/oauth2/server/authorize/extension/id_token_and_token'
|
4
5
|
|
6
|
+
require 'openid_connect/client'
|
7
|
+
require 'openid_connect/access_token'
|
5
8
|
require 'openid_connect/response_object'
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module OpenIDConnect
|
2
|
+
class AccessToken < Rack::OAuth2::AccessToken::Bearer
|
3
|
+
attr_required :client
|
4
|
+
|
5
|
+
def user_info!(scheme = :openid)
|
6
|
+
klass = case scheme
|
7
|
+
when :openid
|
8
|
+
UserInfo::OpenID
|
9
|
+
else
|
10
|
+
raise "Unknown Scheme: #{scheme}"
|
11
|
+
end
|
12
|
+
klass.new resource_request do
|
13
|
+
get absolute_uri_for(user_info_endpoint)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def id_token!
|
18
|
+
IdToken.new resource_request do
|
19
|
+
get absolute_uri_for(introspection_endpoint)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def resource_request
|
26
|
+
access_token_requied!
|
27
|
+
res = yield
|
28
|
+
case res.status
|
29
|
+
when 200
|
30
|
+
JSON.parse(res.body).with_indifferent_access
|
31
|
+
when 401
|
32
|
+
raise OpenIDConnect::Unauthorized.new('Access Token Invalid or Expired')
|
33
|
+
else
|
34
|
+
raise OpenIDConnect::BadRequest.new('API Access Faild')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module OpenIDConnect
|
2
|
+
class Client < Rack::OAuth2::Client
|
3
|
+
attr_optional :introspection_endpoint, :user_info_endpoint
|
4
|
+
|
5
|
+
def initialize(attributes = {})
|
6
|
+
super
|
7
|
+
@user_info_endpoint ||= '/user_info'
|
8
|
+
@introspection_endpoint ||= '/id_tokens'
|
9
|
+
end
|
10
|
+
|
11
|
+
def authorization_uri(params = {})
|
12
|
+
params[:response_type] ||= :token
|
13
|
+
params[:scope] = setup_required_scope params[:scope]
|
14
|
+
Rack::OAuth2::Util.redirect_uri absolute_uri_for(authorization_endpoint), :query, params.merge(
|
15
|
+
:client_id => self.identifier,
|
16
|
+
:redirect_uri => self.redirect_uri
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def access_token!
|
21
|
+
token = super
|
22
|
+
AccessToken.new token.token_response.merge(:client => self)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def setup_required_scope(scopes)
|
28
|
+
scopes = Array(scopes).join(' ').split(' ')
|
29
|
+
if scopes.include?('openid')
|
30
|
+
scopes
|
31
|
+
else
|
32
|
+
(scopes << 'openid')
|
33
|
+
end.join(' ')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module OpenIDConnect
|
2
|
+
class Exception < StandardError; end
|
3
|
+
|
4
|
+
class HttpError < Exception
|
5
|
+
attr_accessor :status, :response
|
6
|
+
def initialize(status, message, response = nil)
|
7
|
+
@status = status
|
8
|
+
@message = message
|
9
|
+
@response = response
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class BadRequest < HttpError
|
14
|
+
def initialize(message, response = nil)
|
15
|
+
super 400, message, response
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Unauthorized < HttpError
|
20
|
+
def initialize(message, response = nil)
|
21
|
+
super 401, message, response
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Forbidden < HttpError
|
26
|
+
def initialize(message, response = nil)
|
27
|
+
super 403, message, response
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/openid_connect.gemspec
CHANGED
@@ -10,13 +10,14 @@ 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"
|
13
|
+
s.add_runtime_dependency "activemodel", ">= 3"
|
14
14
|
s.add_runtime_dependency "validate_url"
|
15
15
|
s.add_runtime_dependency "validate_email"
|
16
16
|
s.add_runtime_dependency "tzinfo"
|
17
|
-
s.add_runtime_dependency "jwt"
|
18
|
-
s.add_runtime_dependency "
|
19
|
-
s.add_runtime_dependency "
|
17
|
+
s.add_runtime_dependency "jwt", ">= 0.1.3"
|
18
|
+
s.add_runtime_dependency "json", ">= 1.4.3"
|
19
|
+
s.add_runtime_dependency "attr_required", ">= 0.0.3"
|
20
|
+
s.add_runtime_dependency "rack-oauth2", ">= 0.9"
|
20
21
|
s.add_development_dependency "rake", ">= 0.8"
|
21
22
|
s.add_development_dependency "rcov", ">= 0.9"
|
22
23
|
s.add_development_dependency "rspec", ">= 2"
|
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.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- nov matake
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-08-
|
13
|
+
date: 2011-08-15 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activemodel
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: "
|
23
|
+
version: "3"
|
24
24
|
type: :runtime
|
25
25
|
version_requirements: *id001
|
26
26
|
- !ruby/object:Gem::Dependency
|
@@ -64,64 +64,75 @@ dependencies:
|
|
64
64
|
requirements:
|
65
65
|
- - ">="
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version:
|
67
|
+
version: 0.1.3
|
68
68
|
type: :runtime
|
69
69
|
version_requirements: *id005
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
|
-
name:
|
71
|
+
name: json
|
72
72
|
prerelease: false
|
73
73
|
requirement: &id006 !ruby/object:Gem::Requirement
|
74
74
|
none: false
|
75
75
|
requirements:
|
76
76
|
- - ">="
|
77
77
|
- !ruby/object:Gem::Version
|
78
|
-
version:
|
78
|
+
version: 1.4.3
|
79
79
|
type: :runtime
|
80
80
|
version_requirements: *id006
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
|
-
name:
|
82
|
+
name: attr_required
|
83
83
|
prerelease: false
|
84
84
|
requirement: &id007 !ruby/object:Gem::Requirement
|
85
85
|
none: false
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.
|
89
|
+
version: 0.0.3
|
90
90
|
type: :runtime
|
91
91
|
version_requirements: *id007
|
92
92
|
- !ruby/object:Gem::Dependency
|
93
|
-
name:
|
93
|
+
name: rack-oauth2
|
94
94
|
prerelease: false
|
95
95
|
requirement: &id008 !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: "0.9"
|
101
|
+
type: :runtime
|
102
|
+
version_requirements: *id008
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: rake
|
105
|
+
prerelease: false
|
106
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
96
107
|
none: false
|
97
108
|
requirements:
|
98
109
|
- - ">="
|
99
110
|
- !ruby/object:Gem::Version
|
100
111
|
version: "0.8"
|
101
112
|
type: :development
|
102
|
-
version_requirements: *
|
113
|
+
version_requirements: *id009
|
103
114
|
- !ruby/object:Gem::Dependency
|
104
115
|
name: rcov
|
105
116
|
prerelease: false
|
106
|
-
requirement: &
|
117
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
107
118
|
none: false
|
108
119
|
requirements:
|
109
120
|
- - ">="
|
110
121
|
- !ruby/object:Gem::Version
|
111
122
|
version: "0.9"
|
112
123
|
type: :development
|
113
|
-
version_requirements: *
|
124
|
+
version_requirements: *id010
|
114
125
|
- !ruby/object:Gem::Dependency
|
115
126
|
name: rspec
|
116
127
|
prerelease: false
|
117
|
-
requirement: &
|
128
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
118
129
|
none: false
|
119
130
|
requirements:
|
120
131
|
- - ">="
|
121
132
|
- !ruby/object:Gem::Version
|
122
133
|
version: "2"
|
123
134
|
type: :development
|
124
|
-
version_requirements: *
|
135
|
+
version_requirements: *id011
|
125
136
|
description: OpenID Connect Server & Client Library
|
126
137
|
email:
|
127
138
|
- nov@matake.jp
|
@@ -135,9 +146,14 @@ files:
|
|
135
146
|
- .gitignore
|
136
147
|
- Gemfile
|
137
148
|
- Gemfile.lock
|
149
|
+
- LICENSE
|
150
|
+
- README.rdoc
|
138
151
|
- Rakefile
|
139
152
|
- VERSION
|
140
153
|
- lib/openid_connect.rb
|
154
|
+
- lib/openid_connect/access_token.rb
|
155
|
+
- lib/openid_connect/client.rb
|
156
|
+
- lib/openid_connect/exception.rb
|
141
157
|
- lib/openid_connect/response_object.rb
|
142
158
|
- lib/openid_connect/response_object/id_token.rb
|
143
159
|
- lib/openid_connect/response_object/user_info.rb
|