rack-oauth2 0.3.0.alpha → 0.3.0
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/VERSION +1 -1
- data/lib/rack/oauth2/server/authorize.rb +12 -1
- data/lib/rack/oauth2/server/authorize/token.rb +2 -2
- data/lib/rack/oauth2/server/token.rb +2 -1
- data/spec/rack/oauth2/server/authorize/code_spec.rb +2 -12
- data/spec/rack/oauth2/server/authorize/token_spec.rb +1 -1
- data/spec/rack/oauth2/server/authorize_spec.rb +29 -1
- data/spec/rack/oauth2/server/token/authorization_code_spec.rb +3 -1
- data/spec/rack/oauth2/server/token/password_spec.rb +3 -1
- data/spec/rack/oauth2/server/token/refresh_token_spec.rb +3 -1
- data/spec/rack/oauth2/server/token_spec.rb +1 -0
- metadata +4 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.0
|
1
|
+
0.3.0
|
@@ -15,6 +15,8 @@ module Rack
|
|
15
15
|
|
16
16
|
def initialize(env)
|
17
17
|
super
|
18
|
+
# NOTE: Raise before redirect_uri is saved not to redirect back to unverified redirect_uri.
|
19
|
+
bad_request! if client_id.blank?
|
18
20
|
@redirect_uri = Util.parse_uri(params['redirect_uri']) if params['redirect_uri']
|
19
21
|
@state = params['state']
|
20
22
|
end
|
@@ -28,9 +30,18 @@ module Rack
|
|
28
30
|
when ''
|
29
31
|
attr_missing!
|
30
32
|
else
|
31
|
-
unsupported_response_type!
|
33
|
+
unsupported_response_type!
|
32
34
|
end
|
33
35
|
end
|
36
|
+
|
37
|
+
def varified_redirect_uri(pre_registered)
|
38
|
+
verified = if redirect_uri.present? && Util.verify_redirect_uri(pre_registered, redirect_uri)
|
39
|
+
redirect_uri
|
40
|
+
else
|
41
|
+
self.redirect_uri = pre_registered
|
42
|
+
end
|
43
|
+
verified.to_s
|
44
|
+
end
|
34
45
|
end
|
35
46
|
|
36
47
|
class Response < Abstract::Response
|
@@ -19,13 +19,13 @@ module Rack
|
|
19
19
|
|
20
20
|
class Response < Authorize::Response
|
21
21
|
attr_required :access_token, :token_type
|
22
|
-
attr_optional :
|
22
|
+
attr_optional :expires_in, :scope
|
23
23
|
|
24
24
|
def protocol_params
|
25
25
|
super.merge(
|
26
26
|
:access_token => access_token,
|
27
|
+
:token_type => token_type,
|
27
28
|
:expires_in => expires_in,
|
28
|
-
:refresh_token => refresh_token,
|
29
29
|
:scope => Array(scope).join(' ')
|
30
30
|
)
|
31
31
|
end
|
@@ -44,12 +44,13 @@ module Rack
|
|
44
44
|
end
|
45
45
|
|
46
46
|
class Response < Abstract::Response
|
47
|
-
attr_required :access_token
|
47
|
+
attr_required :access_token, :token_type
|
48
48
|
attr_optional :expires_in, :refresh_token, :scope
|
49
49
|
|
50
50
|
def protocol_params
|
51
51
|
{
|
52
52
|
:access_token => access_token,
|
53
|
+
:token_type => token_type,
|
53
54
|
:expires_in => expires_in,
|
54
55
|
:scope => Array(scope).join(' ')
|
55
56
|
}
|
@@ -24,24 +24,14 @@ describe Rack::OAuth2::Server::Authorize::Code do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
context 'when redirect_uri is missing' do
|
27
|
-
let
|
28
|
-
Rack::OAuth2::Server::Authorize.new do |request, response|
|
29
|
-
response.code = authorization_code
|
30
|
-
response.approve!
|
31
|
-
end
|
32
|
-
end
|
27
|
+
let(:redirect_uri) { nil }
|
33
28
|
it do
|
34
29
|
expect { response }.should raise_error AttrRequired::AttrMissing
|
35
30
|
end
|
36
31
|
end
|
37
32
|
|
38
33
|
context 'when code is missing' do
|
39
|
-
let
|
40
|
-
Rack::OAuth2::Server::Authorize.new do |request, response|
|
41
|
-
response.redirect_uri = redirect_uri
|
42
|
-
response.approve!
|
43
|
-
end
|
44
|
-
end
|
34
|
+
let(:authorization_code) { nil }
|
45
35
|
it do
|
46
36
|
expect { response }.should raise_error AttrRequired::AttrMissing
|
47
37
|
end
|
@@ -19,7 +19,7 @@ describe Rack::OAuth2::Server::Authorize::Token do
|
|
19
19
|
|
20
20
|
it 'should redirect with authorization code in fragment' do
|
21
21
|
response.status.should == 302
|
22
|
-
response.location.should == "#{redirect_uri}#access_token=#{access_token}"
|
22
|
+
response.location.should == "#{redirect_uri}#access_token=#{access_token}&token_type=#{token_type}"
|
23
23
|
end
|
24
24
|
|
25
25
|
context 'when redirect_uri is missing' do
|
@@ -41,4 +41,32 @@ describe Rack::OAuth2::Server::Authorize do
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
|
+
describe Rack::OAuth2::Server::Authorize::Request do
|
46
|
+
let(:env) { Rack::MockRequest.env_for("/authorize?client_id=client&redirect_uri=#{redirect_uri}") }
|
47
|
+
let(:request) { Rack::OAuth2::Server::Authorize::Request.new env }
|
48
|
+
let(:pre_registered) { 'http://client.example.com' }
|
49
|
+
|
50
|
+
describe '#varified_redirect_uri' do
|
51
|
+
context 'when valid redirect_uri is given' do
|
52
|
+
it 'should use given redirect_uri' do
|
53
|
+
request.varified_redirect_uri(pre_registered).should == redirect_uri
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'when invalid redirect_uri is given' do
|
58
|
+
let(:pre_registered) { 'http://client2.example.com' }
|
59
|
+
it 'should use pre-registered redirect_uri' do
|
60
|
+
request.varified_redirect_uri(pre_registered).should == pre_registered
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'when redirect_uri is missing' do
|
65
|
+
let(:env) { Rack::MockRequest.env_for("/authorize?client_id=client") }
|
66
|
+
it 'should use pre-registered redirect_uri' do
|
67
|
+
request.varified_redirect_uri(pre_registered).should == pre_registered
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -5,6 +5,7 @@ describe Rack::OAuth2::Server::Token::AuthorizationCode do
|
|
5
5
|
let(:app) do
|
6
6
|
Rack::OAuth2::Server::Token.new do |request, response|
|
7
7
|
response.access_token = 'access_token'
|
8
|
+
response.token_type = :bearer
|
8
9
|
end
|
9
10
|
end
|
10
11
|
let(:params) do
|
@@ -19,7 +20,8 @@ describe Rack::OAuth2::Server::Token::AuthorizationCode do
|
|
19
20
|
|
20
21
|
its(:status) { should == 200 }
|
21
22
|
its(:content_type) { should == 'application/json' }
|
22
|
-
its(:body) { should
|
23
|
+
its(:body) { should include '"access_token":"access_token"' }
|
24
|
+
its(:body) { should include '"token_type":"bearer"' }
|
23
25
|
|
24
26
|
[:code, :redirect_uri].each do |required|
|
25
27
|
context "when #{required} is missing" do
|
@@ -5,6 +5,7 @@ describe Rack::OAuth2::Server::Token::Password do
|
|
5
5
|
let(:app) do
|
6
6
|
Rack::OAuth2::Server::Token.new do |request, response|
|
7
7
|
response.access_token = 'access_token'
|
8
|
+
response.token_type = :bearer
|
8
9
|
end
|
9
10
|
end
|
10
11
|
let(:params) do
|
@@ -19,7 +20,8 @@ describe Rack::OAuth2::Server::Token::Password do
|
|
19
20
|
|
20
21
|
its(:status) { should == 200 }
|
21
22
|
its(:content_type) { should == 'application/json' }
|
22
|
-
its(:body) { should
|
23
|
+
its(:body) { should include '"access_token":"access_token"' }
|
24
|
+
its(:body) { should include '"token_type":"bearer"' }
|
23
25
|
|
24
26
|
[:username, :password].each do |required|
|
25
27
|
context "when #{required} is missing" do
|
@@ -5,6 +5,7 @@ describe Rack::OAuth2::Server::Token::RefreshToken do
|
|
5
5
|
let(:app) do
|
6
6
|
Rack::OAuth2::Server::Token.new do |request, response|
|
7
7
|
response.access_token = 'access_token'
|
8
|
+
response.token_type = :bearer
|
8
9
|
end
|
9
10
|
end
|
10
11
|
let(:params) do
|
@@ -18,7 +19,8 @@ describe Rack::OAuth2::Server::Token::RefreshToken do
|
|
18
19
|
|
19
20
|
its(:status) { should == 200 }
|
20
21
|
its(:content_type) { should == 'application/json' }
|
21
|
-
its(:body) { should
|
22
|
+
its(:body) { should include '"access_token":"access_token"' }
|
23
|
+
its(:body) { should include '"token_type":"bearer"' }
|
22
24
|
|
23
25
|
context 'when refresh_token is missing' do
|
24
26
|
before do
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-oauth2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 19
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
9
|
- 0
|
10
|
-
|
11
|
-
version: 0.3.0.alpha
|
10
|
+
version: 0.3.0
|
12
11
|
platform: ruby
|
13
12
|
authors:
|
14
13
|
- nov matake
|
@@ -16,7 +15,7 @@ autorequire:
|
|
16
15
|
bindir: bin
|
17
16
|
cert_chain: []
|
18
17
|
|
19
|
-
date: 2011-03-
|
18
|
+
date: 2011-03-06 00:00:00 +09:00
|
20
19
|
default_executable:
|
21
20
|
dependencies:
|
22
21
|
- !ruby/object:Gem::Dependency
|