rack-oauth2 0.2.2.1 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/LICENSE +1 -1
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/rack/oauth2.rb +2 -0
- data/lib/rack/oauth2/server/abstract/request.rb +10 -18
- data/lib/rack/oauth2/server/abstract/response.rb +3 -15
- data/lib/rack/oauth2/server/authorize.rb +8 -8
- data/lib/rack/oauth2/server/authorize/code.rb +2 -5
- data/lib/rack/oauth2/server/authorize/code_and_token.rb +3 -5
- data/lib/rack/oauth2/server/authorize/token.rb +3 -5
- data/lib/rack/oauth2/server/token.rb +8 -11
- data/lib/rack/oauth2/server/token/assertion.rb +2 -5
- data/lib/rack/oauth2/server/token/authorization_code.rb +2 -5
- data/lib/rack/oauth2/server/token/password.rb +2 -5
- data/lib/rack/oauth2/server/token/refresh_token.rb +2 -5
- data/rack-oauth2.gemspec +1 -0
- data/spec/rack/oauth2/server/authorize_spec.rb +1 -0
- data/spec/rack/oauth2/server/util_spec.rb +2 -0
- metadata +45 -12
- data/Gemfile.lock +0 -41
data/.gitignore
CHANGED
data/LICENSE
CHANGED
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
data/lib/rack/oauth2.rb
CHANGED
@@ -3,33 +3,25 @@ module Rack
|
|
3
3
|
module Server
|
4
4
|
module Abstract
|
5
5
|
class Request < Rack::Request
|
6
|
-
|
6
|
+
include AttrRequired, AttrOptional
|
7
|
+
attr_required :client_id
|
8
|
+
attr_optional :scope
|
7
9
|
|
8
10
|
def initialize(env)
|
9
11
|
super
|
10
|
-
missing_params = verify_required_params
|
11
12
|
@client_id ||= params['client_id']
|
12
13
|
@scope = Array(params['scope'].to_s.split(' '))
|
13
|
-
missing_params << :client_id if @client_id.blank?
|
14
|
-
unless missing_params.blank?
|
15
|
-
invalid_request!("'#{missing_params.join('\', \'')}' required.", :state => @state, :redirect_uri => @redirect_uri)
|
16
|
-
end
|
17
|
-
if params['client_id'].present? && @client_id != params['client_id']
|
18
|
-
invalid_client!("Multiple client credentials are provided.")
|
19
|
-
end
|
20
14
|
end
|
21
15
|
|
22
|
-
def
|
23
|
-
[]
|
24
|
-
|
25
|
-
|
26
|
-
def verify_required_params
|
27
|
-
missing_params = []
|
28
|
-
required_params.each do |key|
|
29
|
-
missing_params << key unless params[key.to_s]
|
16
|
+
def attr_missing_with_error_handling!
|
17
|
+
if params['client_id'].present? && @client_id != params['client_id']
|
18
|
+
invalid_client!("Multiple client credentials are provided.")
|
30
19
|
end
|
31
|
-
|
20
|
+
attr_missing_without_error_handling!
|
21
|
+
rescue AttrRequired::AttrMissing => e
|
22
|
+
invalid_request!(e.message, :state => @state, :redirect_uri => @redirect_uri)
|
32
23
|
end
|
24
|
+
alias_method_chain :attr_missing!, :error_handling
|
33
25
|
|
34
26
|
end
|
35
27
|
end
|
@@ -3,26 +3,14 @@ module Rack
|
|
3
3
|
module Server
|
4
4
|
module Abstract
|
5
5
|
class Response < Rack::Response
|
6
|
+
include AttrRequired, AttrOptional
|
7
|
+
|
6
8
|
def initialize(request)
|
7
9
|
super([], 200, {})
|
8
10
|
end
|
9
11
|
|
10
|
-
def required_params
|
11
|
-
[]
|
12
|
-
end
|
13
|
-
|
14
|
-
def verify_required_params!
|
15
|
-
missing_params = []
|
16
|
-
required_params.each do |key|
|
17
|
-
missing_params << key unless self.send(key)
|
18
|
-
end
|
19
|
-
unless missing_params.blank?
|
20
|
-
raise "Setup '#{missing_params.join('\', \'')}' first!"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
12
|
def finish
|
25
|
-
|
13
|
+
attr_missing!
|
26
14
|
super
|
27
15
|
end
|
28
16
|
end
|
@@ -12,26 +12,25 @@ module Rack
|
|
12
12
|
|
13
13
|
class Request < Abstract::Request
|
14
14
|
include Error::Authorize
|
15
|
-
|
15
|
+
attr_required :response_type
|
16
|
+
attr_optional :redirect_uri, :state
|
16
17
|
|
17
18
|
def initialize(env)
|
18
19
|
super
|
19
|
-
@state = params['state']
|
20
20
|
@redirect_uri = Util.parse_uri(params['redirect_uri']) if params['redirect_uri']
|
21
|
-
|
22
|
-
|
23
|
-
def required_params
|
24
|
-
super + [:response_type]
|
21
|
+
@state = params['state']
|
25
22
|
end
|
26
23
|
|
27
24
|
def profile
|
28
|
-
case params['response_type']
|
25
|
+
case params['response_type'].to_s
|
29
26
|
when 'code'
|
30
27
|
Code
|
31
28
|
when 'token'
|
32
29
|
Token
|
33
30
|
when 'code_and_token'
|
34
31
|
CodeAndToken
|
32
|
+
when ''
|
33
|
+
attr_missing!
|
35
34
|
else
|
36
35
|
unsupported_response_type!("'#{params['response_type']}' isn't supported.")
|
37
36
|
end
|
@@ -40,7 +39,8 @@ module Rack
|
|
40
39
|
end
|
41
40
|
|
42
41
|
class Response < Abstract::Response
|
43
|
-
|
42
|
+
attr_required :redirect_uri
|
43
|
+
attr_optional :state, :approved
|
44
44
|
|
45
45
|
def initialize(request)
|
46
46
|
@state = request.state
|
@@ -14,15 +14,12 @@ module Rack
|
|
14
14
|
def initialize(env)
|
15
15
|
super
|
16
16
|
@response_type = :code
|
17
|
+
attr_missing!
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
20
21
|
class Response < Authorize::Response
|
21
|
-
|
22
|
-
|
23
|
-
def required_params
|
24
|
-
super + [:code]
|
25
|
-
end
|
22
|
+
attr_required :code
|
26
23
|
|
27
24
|
def finish
|
28
25
|
if approved?
|
@@ -14,15 +14,13 @@ module Rack
|
|
14
14
|
def initialize(env)
|
15
15
|
super
|
16
16
|
@response_type = :code_and_token
|
17
|
+
attr_missing!
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
20
21
|
class Response < Authorize::Response
|
21
|
-
|
22
|
-
|
23
|
-
def required_params
|
24
|
-
super + [:code, :access_token]
|
25
|
-
end
|
22
|
+
attr_required :code, :access_token
|
23
|
+
attr_optional :expires_in, :scope
|
26
24
|
|
27
25
|
def finish
|
28
26
|
if approved?
|
@@ -14,15 +14,13 @@ module Rack
|
|
14
14
|
def initialize(env)
|
15
15
|
super
|
16
16
|
@response_type = :token
|
17
|
+
attr_missing!
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
20
21
|
class Response < Authorize::Response
|
21
|
-
|
22
|
-
|
23
|
-
def required_params
|
24
|
-
super + [:access_token]
|
25
|
-
end
|
22
|
+
attr_required :access_token
|
23
|
+
attr_optional :expires_in, :scope
|
26
24
|
|
27
25
|
def finish
|
28
26
|
if approved?
|
@@ -15,7 +15,9 @@ module Rack
|
|
15
15
|
class Request < Abstract::Request
|
16
16
|
include Error::Token
|
17
17
|
|
18
|
-
|
18
|
+
attr_required :grant_type
|
19
|
+
attr_optional :client_secret
|
20
|
+
attr_accessor :via_authorization_header
|
19
21
|
|
20
22
|
def initialize(env)
|
21
23
|
auth = Rack::Auth::Basic::Request.new(env)
|
@@ -30,12 +32,8 @@ module Rack
|
|
30
32
|
@grant_type = params['grant_type']
|
31
33
|
end
|
32
34
|
|
33
|
-
def required_params
|
34
|
-
super + [:grant_type]
|
35
|
-
end
|
36
|
-
|
37
35
|
def profile(allow_no_profile = false)
|
38
|
-
case params['grant_type']
|
36
|
+
case params['grant_type'].to_s
|
39
37
|
when 'authorization_code'
|
40
38
|
AuthorizationCode
|
41
39
|
when 'password'
|
@@ -44,6 +42,8 @@ module Rack
|
|
44
42
|
Assertion
|
45
43
|
when 'refresh_token'
|
46
44
|
RefreshToken
|
45
|
+
when ''
|
46
|
+
attr_missing!
|
47
47
|
else
|
48
48
|
unsupported_grant_type!("'#{params['grant_type']}' isn't supported.")
|
49
49
|
end
|
@@ -52,11 +52,8 @@ module Rack
|
|
52
52
|
end
|
53
53
|
|
54
54
|
class Response < Abstract::Response
|
55
|
-
|
56
|
-
|
57
|
-
def required_params
|
58
|
-
super + [:access_token]
|
59
|
-
end
|
55
|
+
attr_required :access_token
|
56
|
+
attr_optional :expires_in, :refresh_token, :scope
|
60
57
|
|
61
58
|
def finish
|
62
59
|
params = {
|
@@ -11,17 +11,14 @@ module Rack
|
|
11
11
|
end
|
12
12
|
|
13
13
|
class Request < Token::Request
|
14
|
-
|
14
|
+
attr_required :assertion_type, :assertion
|
15
15
|
|
16
16
|
def initialize(env)
|
17
17
|
super
|
18
18
|
@grant_type = 'assertion'
|
19
19
|
@assertion_type = params['assertion_type']
|
20
20
|
@assertion = params['assertion']
|
21
|
-
|
22
|
-
|
23
|
-
def required_params
|
24
|
-
super + [:assertion_type, :assertion]
|
21
|
+
attr_missing!
|
25
22
|
end
|
26
23
|
end
|
27
24
|
|
@@ -11,16 +11,13 @@ module Rack
|
|
11
11
|
end
|
12
12
|
|
13
13
|
class Request < Token::Request
|
14
|
-
|
14
|
+
attr_required :code
|
15
15
|
|
16
16
|
def initialize(env)
|
17
17
|
super
|
18
18
|
@grant_type = :authorization_code
|
19
19
|
@code = params['code']
|
20
|
-
|
21
|
-
|
22
|
-
def required_params
|
23
|
-
super + [:code]
|
20
|
+
attr_missing!
|
24
21
|
end
|
25
22
|
end
|
26
23
|
|
@@ -11,17 +11,14 @@ module Rack
|
|
11
11
|
end
|
12
12
|
|
13
13
|
class Request < Token::Request
|
14
|
-
|
14
|
+
attr_required :username, :password
|
15
15
|
|
16
16
|
def initialize(env)
|
17
17
|
super
|
18
18
|
@grant_type = :password
|
19
19
|
@username = params['username']
|
20
20
|
@password = params['password']
|
21
|
-
|
22
|
-
|
23
|
-
def required_params
|
24
|
-
super + [:username, :password]
|
21
|
+
attr_missing!
|
25
22
|
end
|
26
23
|
end
|
27
24
|
|
@@ -11,16 +11,13 @@ module Rack
|
|
11
11
|
end
|
12
12
|
|
13
13
|
class Request < Token::Request
|
14
|
-
|
14
|
+
attr_required :refresh_token
|
15
15
|
|
16
16
|
def initialize(env)
|
17
17
|
super
|
18
18
|
@grant_type = 'refresh_token'
|
19
19
|
@refresh_token = params['refresh_token']
|
20
|
-
|
21
|
-
|
22
|
-
def required_params
|
23
|
-
super + [:refresh_token]
|
20
|
+
attr_missing!
|
24
21
|
end
|
25
22
|
end
|
26
23
|
|
data/rack-oauth2.gemspec
CHANGED
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.add_runtime_dependency "json", ">= 1.4.3"
|
18
18
|
s.add_runtime_dependency "activesupport", ">= 2.3"
|
19
19
|
s.add_runtime_dependency "i18n"
|
20
|
+
s.add_runtime_dependency "attr_required", ">= 0.0.2"
|
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"
|
@@ -12,6 +12,7 @@ describe Rack::OAuth2::Server::Authorize::Request do
|
|
12
12
|
before do
|
13
13
|
@app = Rack::OAuth2::Server::Authorize.new(simple_app) do |request, response|
|
14
14
|
response.code = "authorization_code"
|
15
|
+
response.redirect_uri ||= "http://client.example.com/callback/pre-registered"
|
15
16
|
end
|
16
17
|
@request = Rack::MockRequest.new @app
|
17
18
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-oauth2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 17
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 2
|
8
|
-
-
|
9
|
-
|
10
|
-
version: 0.2.2.1
|
9
|
+
- 3
|
10
|
+
version: 0.2.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- nov matake
|
@@ -15,16 +15,18 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2010-12-05 00:00:00 +09:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: rack
|
23
23
|
prerelease: false
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
25
26
|
requirements:
|
26
27
|
- - ">="
|
27
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 13
|
28
30
|
segments:
|
29
31
|
- 1
|
30
32
|
- 1
|
@@ -35,9 +37,11 @@ dependencies:
|
|
35
37
|
name: json
|
36
38
|
prerelease: false
|
37
39
|
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
38
41
|
requirements:
|
39
42
|
- - ">="
|
40
43
|
- !ruby/object:Gem::Version
|
44
|
+
hash: 1
|
41
45
|
segments:
|
42
46
|
- 1
|
43
47
|
- 4
|
@@ -49,9 +53,11 @@ dependencies:
|
|
49
53
|
name: activesupport
|
50
54
|
prerelease: false
|
51
55
|
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
52
57
|
requirements:
|
53
58
|
- - ">="
|
54
59
|
- !ruby/object:Gem::Version
|
60
|
+
hash: 5
|
55
61
|
segments:
|
56
62
|
- 2
|
57
63
|
- 3
|
@@ -62,52 +68,76 @@ dependencies:
|
|
62
68
|
name: i18n
|
63
69
|
prerelease: false
|
64
70
|
requirement: &id004 !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
65
72
|
requirements:
|
66
73
|
- - ">="
|
67
74
|
- !ruby/object:Gem::Version
|
75
|
+
hash: 3
|
68
76
|
segments:
|
69
77
|
- 0
|
70
78
|
version: "0"
|
71
79
|
type: :runtime
|
72
80
|
version_requirements: *id004
|
73
81
|
- !ruby/object:Gem::Dependency
|
74
|
-
name:
|
82
|
+
name: attr_required
|
75
83
|
prerelease: false
|
76
84
|
requirement: &id005 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
77
86
|
requirements:
|
78
87
|
- - ">="
|
79
88
|
- !ruby/object:Gem::Version
|
89
|
+
hash: 27
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
- 0
|
93
|
+
- 2
|
94
|
+
version: 0.0.2
|
95
|
+
type: :runtime
|
96
|
+
version_requirements: *id005
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
prerelease: false
|
100
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
hash: 27
|
80
106
|
segments:
|
81
107
|
- 0
|
82
108
|
- 8
|
83
109
|
version: "0.8"
|
84
110
|
type: :development
|
85
|
-
version_requirements: *
|
111
|
+
version_requirements: *id006
|
86
112
|
- !ruby/object:Gem::Dependency
|
87
113
|
name: rcov
|
88
114
|
prerelease: false
|
89
|
-
requirement: &
|
115
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
90
117
|
requirements:
|
91
118
|
- - ">="
|
92
119
|
- !ruby/object:Gem::Version
|
120
|
+
hash: 25
|
93
121
|
segments:
|
94
122
|
- 0
|
95
123
|
- 9
|
96
124
|
version: "0.9"
|
97
125
|
type: :development
|
98
|
-
version_requirements: *
|
126
|
+
version_requirements: *id007
|
99
127
|
- !ruby/object:Gem::Dependency
|
100
128
|
name: rspec
|
101
129
|
prerelease: false
|
102
|
-
requirement: &
|
130
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
131
|
+
none: false
|
103
132
|
requirements:
|
104
133
|
- - ">="
|
105
134
|
- !ruby/object:Gem::Version
|
135
|
+
hash: 7
|
106
136
|
segments:
|
107
137
|
- 2
|
108
138
|
version: "2"
|
109
139
|
type: :development
|
110
|
-
version_requirements: *
|
140
|
+
version_requirements: *id008
|
111
141
|
description: Rack Middleware for OAuth2 server
|
112
142
|
email: nov@matake.jp
|
113
143
|
executables: []
|
@@ -122,7 +152,6 @@ files:
|
|
122
152
|
- .gitignore
|
123
153
|
- .rspec
|
124
154
|
- Gemfile
|
125
|
-
- Gemfile.lock
|
126
155
|
- LICENSE
|
127
156
|
- README.rdoc
|
128
157
|
- Rakefile
|
@@ -175,16 +204,20 @@ rdoc_options:
|
|
175
204
|
require_paths:
|
176
205
|
- lib
|
177
206
|
required_ruby_version: !ruby/object:Gem::Requirement
|
207
|
+
none: false
|
178
208
|
requirements:
|
179
209
|
- - ">="
|
180
210
|
- !ruby/object:Gem::Version
|
211
|
+
hash: 3
|
181
212
|
segments:
|
182
213
|
- 0
|
183
214
|
version: "0"
|
184
215
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
216
|
+
none: false
|
185
217
|
requirements:
|
186
218
|
- - ">="
|
187
219
|
- !ruby/object:Gem::Version
|
220
|
+
hash: 23
|
188
221
|
segments:
|
189
222
|
- 1
|
190
223
|
- 3
|
@@ -193,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
193
226
|
requirements: []
|
194
227
|
|
195
228
|
rubyforge_project:
|
196
|
-
rubygems_version: 1.3.
|
229
|
+
rubygems_version: 1.3.7
|
197
230
|
signing_key:
|
198
231
|
specification_version: 3
|
199
232
|
summary: Rack Middleware for OAuth2 server
|
data/Gemfile.lock
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
rack-oauth2 (0.2.1)
|
5
|
-
activesupport (>= 2.3)
|
6
|
-
i18n
|
7
|
-
json (= 1.4.3)
|
8
|
-
rack (= 1.1)
|
9
|
-
|
10
|
-
GEM
|
11
|
-
specs:
|
12
|
-
activesupport (3.0.1)
|
13
|
-
diff-lcs (1.1.2)
|
14
|
-
i18n (0.4.2)
|
15
|
-
json (1.4.3)
|
16
|
-
rack (1.1.0)
|
17
|
-
rake (0.8.7)
|
18
|
-
rcov (0.9.9)
|
19
|
-
rspec (2.0.0)
|
20
|
-
rspec-core (= 2.0.0)
|
21
|
-
rspec-expectations (= 2.0.0)
|
22
|
-
rspec-mocks (= 2.0.0)
|
23
|
-
rspec-core (2.0.0)
|
24
|
-
rspec-expectations (2.0.0)
|
25
|
-
diff-lcs (>= 1.1.2)
|
26
|
-
rspec-mocks (2.0.0)
|
27
|
-
rspec-core (= 2.0.0)
|
28
|
-
rspec-expectations (= 2.0.0)
|
29
|
-
|
30
|
-
PLATFORMS
|
31
|
-
ruby
|
32
|
-
|
33
|
-
DEPENDENCIES
|
34
|
-
activesupport (>= 2.3)
|
35
|
-
i18n
|
36
|
-
json (= 1.4.3)
|
37
|
-
rack (= 1.1)
|
38
|
-
rack-oauth2!
|
39
|
-
rake (>= 0.8)
|
40
|
-
rcov (>= 0.9)
|
41
|
-
rspec (>= 2.0)
|