doorkeeper 0.3.4 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of doorkeeper might be problematic. Click here for more details.
- data/CHANGELOG.md +13 -0
- data/README.md +32 -5
- data/app/controllers/doorkeeper/application_controller.rb +4 -11
- data/app/controllers/doorkeeper/authorizations_controller.rb +11 -2
- data/app/controllers/doorkeeper/tokens_controller.rb +19 -5
- data/app/models/doorkeeper/access_grant.rb +1 -8
- data/app/models/doorkeeper/access_token.rb +2 -10
- data/app/models/doorkeeper/application.rb +4 -0
- data/app/views/doorkeeper/authorizations/error.html.erb +1 -1
- data/app/views/doorkeeper/authorizations/new.html.erb +1 -1
- data/config/locales/en.yml +3 -0
- data/doorkeeper.gemspec +2 -1
- data/lib/doorkeeper.rb +23 -3
- data/lib/doorkeeper/config.rb +73 -12
- data/lib/doorkeeper/doorkeeper_for.rb +1 -1
- data/lib/doorkeeper/engine.rb +28 -0
- data/lib/doorkeeper/models/scopes.rb +13 -0
- data/lib/doorkeeper/oauth/access_token_request.rb +5 -16
- data/lib/doorkeeper/oauth/authorization/code.rb +1 -1
- data/lib/doorkeeper/oauth/authorization/token.rb +1 -1
- data/lib/doorkeeper/oauth/authorization_request.rb +18 -23
- data/lib/doorkeeper/oauth/client.rb +27 -0
- data/lib/doorkeeper/oauth/client/credentials.rb +21 -0
- data/lib/doorkeeper/oauth/client/methods.rb +18 -0
- data/lib/doorkeeper/oauth/client_credentials/creator.rb +29 -0
- data/lib/doorkeeper/oauth/client_credentials/issuer.rb +35 -0
- data/lib/doorkeeper/oauth/client_credentials/response.rb +42 -0
- data/lib/doorkeeper/oauth/client_credentials/validation.rb +33 -0
- data/lib/doorkeeper/oauth/client_credentials_request.rb +46 -0
- data/lib/doorkeeper/oauth/error.rb +9 -0
- data/lib/doorkeeper/oauth/error_response.rb +30 -0
- data/lib/doorkeeper/oauth/helpers/scope_checker.rb +2 -2
- data/lib/doorkeeper/oauth/password_access_token_request.rb +130 -0
- data/lib/doorkeeper/oauth/scopes.rb +60 -0
- data/lib/doorkeeper/version.rb +1 -1
- data/lib/generators/doorkeeper/templates/initializer.rb +10 -5
- data/lib/generators/doorkeeper/templates/migration.rb +1 -1
- data/script/run_all +11 -0
- data/spec/controllers/authorizations_controller_spec.rb +3 -3
- data/spec/controllers/protected_resources_controller_spec.rb +7 -0
- data/spec/controllers/tokens_controller_spec.rb +1 -1
- data/spec/dummy/app/controllers/home_controller.rb +1 -1
- data/spec/dummy/app/models/user.rb +9 -0
- data/spec/dummy/config/application.rb +2 -0
- data/spec/dummy/config/initializers/doorkeeper.rb +12 -5
- data/spec/dummy/config/locales/doorkeeper.en.yml +5 -0
- data/spec/dummy/db/migrate/20120312140401_add_password_to_users.rb +5 -0
- data/spec/dummy/db/migrate/{20111206151426_create_doorkeeper_tables.rb → 20120524202412_create_doorkeeper_tables.rb} +10 -1
- data/spec/dummy/db/schema.rb +15 -6
- data/spec/lib/config_spec.rb +29 -13
- data/spec/lib/models/scopes_spec.rb +32 -0
- data/spec/lib/oauth/access_token_request_spec.rb +15 -29
- data/spec/lib/oauth/authorization_request_spec.rb +22 -72
- data/spec/lib/oauth/client/credentials_spec.rb +47 -0
- data/spec/lib/oauth/client/methods_spec.rb +54 -0
- data/spec/lib/oauth/client_credentials/creator_spec.rb +47 -0
- data/spec/lib/oauth/client_credentials/issuer_spec.rb +57 -0
- data/spec/lib/oauth/client_credentials/response_spec.rb +58 -0
- data/spec/lib/oauth/client_credentials/validation_spec.rb +29 -0
- data/spec/lib/oauth/client_credentials_integration_spec.rb +27 -0
- data/spec/lib/oauth/client_credentials_request_spec.rb +60 -0
- data/spec/lib/oauth/client_spec.rb +42 -0
- data/spec/lib/oauth/error_response_spec.rb +40 -0
- data/spec/lib/oauth/error_spec.rb +19 -0
- data/spec/lib/oauth/helpers/scope_checker_spec.rb +15 -10
- data/spec/lib/oauth/password_access_token_request_spec.rb +152 -0
- data/spec/lib/oauth/scopes_spec.rb +115 -0
- data/spec/models/doorkeeper/access_grant_spec.rb +0 -15
- data/spec/models/doorkeeper/access_token_spec.rb +11 -4
- data/spec/requests/applications/authorized_applications_spec.rb +2 -2
- data/spec/requests/endpoints/authorization_spec.rb +2 -2
- data/spec/requests/endpoints/token_spec.rb +7 -0
- data/spec/requests/flows/authorization_code_errors_spec.rb +1 -1
- data/spec/requests/flows/authorization_code_spec.rb +8 -2
- data/spec/requests/flows/client_credentials_spec.rb +56 -0
- data/spec/requests/flows/password_spec.rb +52 -0
- data/spec/requests/flows/skip_authorization_spec.rb +2 -2
- data/spec/requests/protected_resources/private_api_spec.rb +9 -2
- data/spec/spec_helper_integration.rb +3 -0
- data/spec/support/helpers/authorization_request_helper.rb +7 -5
- data/spec/support/helpers/model_helper.rb +3 -3
- data/spec/support/helpers/request_spec_helper.rb +1 -1
- data/spec/support/helpers/url_helper.rb +12 -0
- metadata +65 -30
- data/lib/doorkeeper/config/scope.rb +0 -11
- data/lib/doorkeeper/config/scopes.rb +0 -61
- data/lib/doorkeeper/config/scopes_builder.rb +0 -18
- data/spec/dummy/config/initializers/inflections.rb +0 -10
- data/spec/dummy/config/initializers/mime_types.rb +0 -5
- data/spec/lib/config/scope_spec.rb +0 -45
- data/spec/lib/config/scopes_builder_spec.rb +0 -27
- data/spec/lib/config/scopes_spec.rb +0 -180
@@ -8,6 +8,8 @@ class CreateDoorkeeperTables < ActiveRecord::Migration
|
|
8
8
|
t.timestamps
|
9
9
|
end
|
10
10
|
|
11
|
+
add_index :oauth_applications, :uid, :unique => true
|
12
|
+
|
11
13
|
create_table :oauth_access_grants do |t|
|
12
14
|
t.integer :resource_owner_id, :null => false
|
13
15
|
t.integer :application_id, :null => false
|
@@ -19,8 +21,10 @@ class CreateDoorkeeperTables < ActiveRecord::Migration
|
|
19
21
|
t.string :scopes
|
20
22
|
end
|
21
23
|
|
24
|
+
add_index :oauth_access_grants, :token, :unique => true
|
25
|
+
|
22
26
|
create_table :oauth_access_tokens do |t|
|
23
|
-
t.integer :resource_owner_id
|
27
|
+
t.integer :resource_owner_id
|
24
28
|
t.integer :application_id, :null => false
|
25
29
|
t.string :token, :null => false
|
26
30
|
t.string :refresh_token
|
@@ -29,5 +33,10 @@ class CreateDoorkeeperTables < ActiveRecord::Migration
|
|
29
33
|
t.datetime :created_at, :null => false
|
30
34
|
t.string :scopes
|
31
35
|
end
|
36
|
+
|
37
|
+
add_index :oauth_access_tokens, :token, :unique => true
|
38
|
+
add_index :oauth_access_tokens, :resource_owner_id
|
39
|
+
add_index :oauth_access_tokens, :refresh_token, :unique => true
|
40
|
+
|
32
41
|
end
|
33
42
|
end
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended to check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(:version =>
|
14
|
+
ActiveRecord::Schema.define(:version => 20120524202412) do
|
15
15
|
|
16
16
|
create_table "oauth_access_grants", :force => true do |t|
|
17
17
|
t.integer "resource_owner_id", :null => false
|
@@ -24,8 +24,10 @@ ActiveRecord::Schema.define(:version => 20111206151426) do
|
|
24
24
|
t.string "scopes"
|
25
25
|
end
|
26
26
|
|
27
|
+
add_index "oauth_access_grants", ["token"], :name => "index_oauth_access_grants_on_token", :unique => true
|
28
|
+
|
27
29
|
create_table "oauth_access_tokens", :force => true do |t|
|
28
|
-
t.integer "resource_owner_id"
|
30
|
+
t.integer "resource_owner_id"
|
29
31
|
t.integer "application_id", :null => false
|
30
32
|
t.string "token", :null => false
|
31
33
|
t.string "refresh_token"
|
@@ -35,19 +37,26 @@ ActiveRecord::Schema.define(:version => 20111206151426) do
|
|
35
37
|
t.string "scopes"
|
36
38
|
end
|
37
39
|
|
40
|
+
add_index "oauth_access_tokens", ["refresh_token"], :name => "index_oauth_access_tokens_on_refresh_token", :unique => true
|
41
|
+
add_index "oauth_access_tokens", ["resource_owner_id"], :name => "index_oauth_access_tokens_on_resource_owner_id"
|
42
|
+
add_index "oauth_access_tokens", ["token"], :name => "index_oauth_access_tokens_on_token", :unique => true
|
43
|
+
|
38
44
|
create_table "oauth_applications", :force => true do |t|
|
39
45
|
t.string "name", :null => false
|
40
46
|
t.string "uid", :null => false
|
41
47
|
t.string "secret", :null => false
|
42
48
|
t.string "redirect_uri", :null => false
|
43
|
-
t.datetime "created_at"
|
44
|
-
t.datetime "updated_at"
|
49
|
+
t.datetime "created_at", :null => false
|
50
|
+
t.datetime "updated_at", :null => false
|
45
51
|
end
|
46
52
|
|
53
|
+
add_index "oauth_applications", ["uid"], :name => "index_oauth_applications_on_uid", :unique => true
|
54
|
+
|
47
55
|
create_table "users", :force => true do |t|
|
48
56
|
t.string "name"
|
49
|
-
t.datetime "created_at"
|
50
|
-
t.datetime "updated_at"
|
57
|
+
t.datetime "created_at", :null => false
|
58
|
+
t.datetime "updated_at", :null => false
|
59
|
+
t.string "password_digest"
|
51
60
|
end
|
52
61
|
|
53
62
|
end
|
data/spec/lib/config_spec.rb
CHANGED
@@ -34,27 +34,32 @@ describe Doorkeeper, "configuration" do
|
|
34
34
|
end
|
35
35
|
subject.access_token_expires_in.should == 4.hours
|
36
36
|
end
|
37
|
-
end
|
38
37
|
|
39
|
-
|
40
|
-
it "can be set with authorization_scopes method in DSL" do
|
38
|
+
it "can be set to nil" do
|
41
39
|
Doorkeeper.configure do
|
42
|
-
|
43
|
-
scope :public, :default => true, :description => "Public"
|
44
|
-
end
|
40
|
+
access_token_expires_in nil
|
45
41
|
end
|
42
|
+
subject.access_token_expires_in.should be_nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "scopes" do
|
47
|
+
it "has default scopes" do
|
48
|
+
Doorkeeper.configure { default_scopes :public }
|
49
|
+
subject.default_scopes.should include(:public)
|
50
|
+
end
|
46
51
|
|
47
|
-
|
48
|
-
|
49
|
-
subject.
|
52
|
+
it 'has optional scopes' do
|
53
|
+
Doorkeeper.configure { optional_scopes :write, :update }
|
54
|
+
subject.optional_scopes.should include(:write, :update)
|
50
55
|
end
|
51
56
|
|
52
|
-
it
|
57
|
+
it 'has all scopes' do
|
53
58
|
Doorkeeper.configure do
|
59
|
+
default_scopes :normal
|
60
|
+
optional_scopes :admin
|
54
61
|
end
|
55
|
-
|
56
|
-
subject.scopes.should be_a(Doorkeeper::Scopes)
|
57
|
-
subject.scopes.all.should == []
|
62
|
+
subject.scopes.should include(:normal, :admin)
|
58
63
|
end
|
59
64
|
end
|
60
65
|
|
@@ -68,4 +73,15 @@ describe Doorkeeper, "configuration" do
|
|
68
73
|
subject.refresh_token_enabled?.should be_true
|
69
74
|
end
|
70
75
|
end
|
76
|
+
|
77
|
+
describe 'client_credentials' do
|
78
|
+
it 'has defaults order' do
|
79
|
+
subject.client_credentials_methods.should == [:from_basic, :from_params]
|
80
|
+
end
|
81
|
+
|
82
|
+
it "can change the value" do
|
83
|
+
Doorkeeper.configure { client_credentials :from_digest, :from_params }
|
84
|
+
subject.client_credentials_methods.should == [:from_digest, :from_params]
|
85
|
+
end
|
86
|
+
end
|
71
87
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'active_support/core_ext/module/delegation'
|
3
|
+
require 'doorkeeper/oauth/scopes'
|
4
|
+
require 'doorkeeper/models/scopes'
|
5
|
+
|
6
|
+
describe 'Doorkeeper::Models::Scopes' do
|
7
|
+
subject do
|
8
|
+
Class.new(Hash) do
|
9
|
+
include Doorkeeper::Models::Scopes
|
10
|
+
end.new
|
11
|
+
end
|
12
|
+
|
13
|
+
before do
|
14
|
+
subject[:scopes] = 'public admin'
|
15
|
+
end
|
16
|
+
|
17
|
+
describe :scopes do
|
18
|
+
it 'is a `Scopes` class' do
|
19
|
+
subject.scopes.should be_a(Doorkeeper::OAuth::Scopes)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'includes scopes' do
|
23
|
+
subject.scopes.should include(:public)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe :scopes_string do
|
28
|
+
it 'is a `Scopes` class' do
|
29
|
+
subject.scopes_string.should == 'public admin'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -6,8 +6,6 @@ module Doorkeeper::OAuth
|
|
6
6
|
let(:grant) { FactoryGirl.create(:access_grant, :application => client) }
|
7
7
|
let(:params) {
|
8
8
|
{
|
9
|
-
:client_id => client.uid,
|
10
|
-
:client_secret => client.secret,
|
11
9
|
:code => grant.token,
|
12
10
|
:grant_type => "authorization_code",
|
13
11
|
:redirect_uri => client.redirect_uri
|
@@ -15,7 +13,7 @@ module Doorkeeper::OAuth
|
|
15
13
|
}
|
16
14
|
|
17
15
|
describe "with a valid authorization code and client" do
|
18
|
-
subject { AccessTokenRequest.new(params) }
|
16
|
+
subject { AccessTokenRequest.new(client, params) }
|
19
17
|
|
20
18
|
before { subject.authorize }
|
21
19
|
|
@@ -30,7 +28,7 @@ module Doorkeeper::OAuth
|
|
30
28
|
end
|
31
29
|
|
32
30
|
describe "creating the access token" do
|
33
|
-
subject { AccessTokenRequest.new(params) }
|
31
|
+
subject { AccessTokenRequest.new(client, params) }
|
34
32
|
|
35
33
|
it "creates with correct params" do
|
36
34
|
Doorkeeper::AccessToken.should_receive(:create!).with({
|
@@ -45,7 +43,7 @@ module Doorkeeper::OAuth
|
|
45
43
|
end
|
46
44
|
|
47
45
|
describe "with a valid authorization code, client and existing valid access token" do
|
48
|
-
subject { AccessTokenRequest.new(params) }
|
46
|
+
subject { AccessTokenRequest.new(client, params) }
|
49
47
|
|
50
48
|
before { subject.authorize }
|
51
49
|
it { should be_valid }
|
@@ -58,7 +56,7 @@ module Doorkeeper::OAuth
|
|
58
56
|
end
|
59
57
|
|
60
58
|
describe "with a valid authorization code, client and existing expired access token" do
|
61
|
-
subject { AccessTokenRequest.new(params) }
|
59
|
+
subject { AccessTokenRequest.new(client, params) }
|
62
60
|
|
63
61
|
it "will create a new token" do
|
64
62
|
subject.authorize
|
@@ -72,7 +70,7 @@ module Doorkeeper::OAuth
|
|
72
70
|
end
|
73
71
|
|
74
72
|
describe "finding the current access token" do
|
75
|
-
subject { AccessTokenRequest.new(params) }
|
73
|
+
subject { AccessTokenRequest.new(client, params) }
|
76
74
|
it { should be_valid }
|
77
75
|
its(:error) { should be_nil }
|
78
76
|
|
@@ -86,7 +84,7 @@ module Doorkeeper::OAuth
|
|
86
84
|
end
|
87
85
|
|
88
86
|
describe "creating the first access_token" do
|
89
|
-
subject { AccessTokenRequest.new(params) }
|
87
|
+
subject { AccessTokenRequest.new(client, params) }
|
90
88
|
it { should be_valid }
|
91
89
|
its(:error) { should be_nil }
|
92
90
|
|
@@ -98,12 +96,12 @@ module Doorkeeper::OAuth
|
|
98
96
|
|
99
97
|
describe "with errors" do
|
100
98
|
def token(params)
|
101
|
-
AccessTokenRequest.new(params)
|
99
|
+
AccessTokenRequest.new(client, params)
|
102
100
|
end
|
103
101
|
|
104
102
|
it "includes the error in the response" do
|
105
103
|
access_token = token(params.except(:grant_type))
|
106
|
-
access_token.error_response
|
104
|
+
access_token.error_response.name.should == :invalid_request
|
107
105
|
end
|
108
106
|
|
109
107
|
[:grant_type, :code, :redirect_uri].each do |param|
|
@@ -113,13 +111,8 @@ module Doorkeeper::OAuth
|
|
113
111
|
end
|
114
112
|
end
|
115
113
|
|
116
|
-
describe "when
|
117
|
-
subject {
|
118
|
-
its(:error) { should == :invalid_client }
|
119
|
-
end
|
120
|
-
|
121
|
-
describe "when :client_secret does not match" do
|
122
|
-
subject { token(params.merge(:client_secret => "inexistent")) }
|
114
|
+
describe "when client is not present" do
|
115
|
+
subject { AccessTokenRequest.new(nil, params) }
|
123
116
|
its(:error) { should == :invalid_client }
|
124
117
|
end
|
125
118
|
|
@@ -166,8 +159,6 @@ module Doorkeeper::OAuth
|
|
166
159
|
let(:access) { FactoryGirl.create(:access_token, :application => client, :use_refresh_token => true) }
|
167
160
|
let(:params) {
|
168
161
|
{
|
169
|
-
:client_id => client.uid,
|
170
|
-
:client_secret => client.secret,
|
171
162
|
:refresh_token => access.refresh_token,
|
172
163
|
:grant_type => "refresh_token",
|
173
164
|
}
|
@@ -178,7 +169,7 @@ module Doorkeeper::OAuth
|
|
178
169
|
end
|
179
170
|
|
180
171
|
describe "with a valid authorization code and client" do
|
181
|
-
subject { AccessTokenRequest.new(params) }
|
172
|
+
subject { AccessTokenRequest.new(client, params) }
|
182
173
|
|
183
174
|
before do
|
184
175
|
subject.authorize
|
@@ -196,12 +187,12 @@ module Doorkeeper::OAuth
|
|
196
187
|
|
197
188
|
describe "with errors" do
|
198
189
|
def token(params)
|
199
|
-
AccessTokenRequest.new(params)
|
190
|
+
AccessTokenRequest.new(client, params)
|
200
191
|
end
|
201
192
|
|
202
193
|
it "includes the error in the response" do
|
203
194
|
access_token = token(params.except(:grant_type))
|
204
|
-
access_token.error_response
|
195
|
+
access_token.error_response.name.should == :invalid_request
|
205
196
|
end
|
206
197
|
|
207
198
|
[:grant_type, :refresh_token].each do |param|
|
@@ -211,13 +202,8 @@ module Doorkeeper::OAuth
|
|
211
202
|
end
|
212
203
|
end
|
213
204
|
|
214
|
-
describe "when
|
215
|
-
subject {
|
216
|
-
its(:error) { should == :invalid_client }
|
217
|
-
end
|
218
|
-
|
219
|
-
describe "when :client_secret does not match" do
|
220
|
-
subject { token(params.merge(:client_secret => "inexistent")) }
|
205
|
+
describe "when client is not present" do
|
206
|
+
subject { AccessTokenRequest.new(nil, params) }
|
221
207
|
its(:error) { should == :invalid_client }
|
222
208
|
end
|
223
209
|
|
@@ -6,7 +6,6 @@ module Doorkeeper::OAuth
|
|
6
6
|
let(:client) { FactoryGirl.create(:application) }
|
7
7
|
let(:base_attributes) do
|
8
8
|
{
|
9
|
-
:client_id => client.uid,
|
10
9
|
:redirect_uri => client.redirect_uri,
|
11
10
|
:scope => "public write",
|
12
11
|
:state => "return-this"
|
@@ -14,15 +13,14 @@ module Doorkeeper::OAuth
|
|
14
13
|
end
|
15
14
|
|
16
15
|
before :each do
|
17
|
-
Doorkeeper
|
18
|
-
Doorkeeper.stub_chain(:configuration, :scopes, :all).and_return([Doorkeeper::Scope.new(:public)])
|
16
|
+
Doorkeeper.configuration.stub(:default_scopes).and_return(Doorkeeper::OAuth::Scopes.from_string('public write'))
|
19
17
|
end
|
20
18
|
|
21
19
|
describe "with a code response_type" do
|
22
20
|
let(:attributes) { base_attributes.merge!(:response_type => "code") }
|
23
21
|
|
24
22
|
describe "with valid attributes" do
|
25
|
-
subject { AuthorizationRequest.new(resource_owner, attributes) }
|
23
|
+
subject { AuthorizationRequest.new(client, resource_owner, attributes) }
|
26
24
|
|
27
25
|
describe "after authorization" do
|
28
26
|
before { subject.authorize }
|
@@ -46,16 +44,8 @@ module Doorkeeper::OAuth
|
|
46
44
|
end
|
47
45
|
end
|
48
46
|
|
49
|
-
describe :scopes do
|
50
|
-
it "returns scopes objects returned by Doorkeeper::Scopes with names specified by scopes" do
|
51
|
-
scopes_object = double(Doorkeeper::Scopes)
|
52
|
-
Doorkeeper.stub_chain(:configuration, :scopes, :with_names).with("public", "write").and_return(scopes_object)
|
53
|
-
subject.scopes.should == scopes_object
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
47
|
describe :authorize do
|
58
|
-
let(:authorization_request) { AuthorizationRequest.new(resource_owner, attributes) }
|
48
|
+
let(:authorization_request) { AuthorizationRequest.new(client, resource_owner, attributes) }
|
59
49
|
subject { authorization_request.authorize }
|
60
50
|
|
61
51
|
it "returns Doorkeeper::AccessGrant object" do
|
@@ -70,7 +60,6 @@ module Doorkeeper::OAuth
|
|
70
60
|
subject.scopes == authorization_request.scope
|
71
61
|
end
|
72
62
|
end
|
73
|
-
|
74
63
|
end
|
75
64
|
|
76
65
|
describe "with a redirect_uri with query params" do
|
@@ -81,7 +70,7 @@ module Doorkeeper::OAuth
|
|
81
70
|
attributes[:redirect_uri] = u.to_s
|
82
71
|
attributes
|
83
72
|
}
|
84
|
-
subject { AuthorizationRequest.new(resource_owner, attributes_with_query_params) }
|
73
|
+
subject { AuthorizationRequest.new(client, resource_owner, attributes_with_query_params) }
|
85
74
|
|
86
75
|
it "preservers the original query when error"
|
87
76
|
|
@@ -103,31 +92,25 @@ module Doorkeeper::OAuth
|
|
103
92
|
query.should =~ /abc=123/
|
104
93
|
query.should =~ /def=456/
|
105
94
|
end
|
106
|
-
|
107
95
|
end
|
108
|
-
|
109
96
|
end
|
110
97
|
end
|
111
98
|
|
112
99
|
describe "if no scope given" do
|
113
100
|
it "sets the scope to the default one" do
|
114
|
-
|
115
|
-
request
|
116
|
-
request.scope.should == "public email"
|
101
|
+
request = AuthorizationRequest.new(client, resource_owner, attributes.except(:scope))
|
102
|
+
request.scopes.to_s.should == "public write"
|
117
103
|
end
|
118
104
|
end
|
119
105
|
|
120
106
|
describe "with errors" do
|
121
107
|
before do
|
122
108
|
Doorkeeper::AccessGrant.should_not_receive(:create)
|
123
|
-
Doorkeeper.stub_chain(:configuration, :scopes, :all).and_return([Doorkeeper::Scope.new(:public)])
|
124
109
|
end
|
125
110
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
its(:error) { should == :invalid_request }
|
130
|
-
end
|
111
|
+
describe "when :response_type is missing" do
|
112
|
+
subject { auth(attributes.except(:response_type)) }
|
113
|
+
its(:error) { should == :invalid_request }
|
131
114
|
end
|
132
115
|
|
133
116
|
describe "when :redirect_uri is missing" do
|
@@ -135,13 +118,8 @@ module Doorkeeper::OAuth
|
|
135
118
|
its(:error) { should == :invalid_redirect_uri }
|
136
119
|
end
|
137
120
|
|
138
|
-
describe "when
|
139
|
-
subject {
|
140
|
-
its(:error) { should == :invalid_client }
|
141
|
-
end
|
142
|
-
|
143
|
-
describe "when :client_id does not match" do
|
144
|
-
subject { auth(attributes.merge(:client_id => "invalid")) }
|
121
|
+
describe "when client is not present" do
|
122
|
+
subject { AuthorizationRequest.new(nil, resource_owner, attributes) }
|
145
123
|
its(:error) { should == :invalid_client }
|
146
124
|
end
|
147
125
|
|
@@ -166,10 +144,6 @@ module Doorkeeper::OAuth
|
|
166
144
|
end
|
167
145
|
|
168
146
|
describe "when :scope contains scopes that are note registered in the provider" do
|
169
|
-
before do
|
170
|
-
Doorkeeper::OAuth::Helpers::ScopeChecker.stub(:valid?).and_return(false)
|
171
|
-
end
|
172
|
-
|
173
147
|
subject { auth(attributes.merge(:scope => "public strange")) }
|
174
148
|
its(:error) { should == :invalid_scope }
|
175
149
|
end
|
@@ -178,19 +152,18 @@ module Doorkeeper::OAuth
|
|
178
152
|
|
179
153
|
describe "with a token response_type" do
|
180
154
|
before do
|
181
|
-
Doorkeeper.
|
155
|
+
Doorkeeper.configuration.stub(:access_token_expires_in).and_return(7200)
|
182
156
|
end
|
183
157
|
|
184
158
|
let(:attributes) { base_attributes.merge!(:response_type => "token") }
|
185
159
|
|
186
160
|
describe "with valid attributes" do
|
187
|
-
subject { AuthorizationRequest.new(resource_owner, attributes) }
|
161
|
+
subject { AuthorizationRequest.new(client, resource_owner, attributes) }
|
188
162
|
|
189
163
|
describe "after authorization" do
|
190
164
|
before { subject.authorize }
|
191
165
|
|
192
166
|
its(:response_type) { should == "token" }
|
193
|
-
its(:client_id) { should == client.uid }
|
194
167
|
its(:scope) { should == "public write" }
|
195
168
|
its(:state) { should == "return-this" }
|
196
169
|
its(:error) { should be_nil }
|
@@ -224,16 +197,8 @@ module Doorkeeper::OAuth
|
|
224
197
|
end
|
225
198
|
end
|
226
199
|
|
227
|
-
describe :scopes do
|
228
|
-
it "returns scopes objects returned by Doorkeeper::Scopes with names specified by scopes" do
|
229
|
-
scopes_object = double(Doorkeeper::Scopes)
|
230
|
-
Doorkeeper.stub_chain(:configuration, :scopes, :with_names).with("public", "write").and_return(scopes_object)
|
231
|
-
subject.scopes.should == scopes_object
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
200
|
describe :authorize do
|
236
|
-
let(:authorization_request) { AuthorizationRequest.new(resource_owner, attributes) }
|
201
|
+
let(:authorization_request) { AuthorizationRequest.new(client, resource_owner, attributes) }
|
237
202
|
subject { authorization_request.authorize }
|
238
203
|
|
239
204
|
it "returns Doorkeeper::AccessGrant object" do
|
@@ -248,28 +213,23 @@ module Doorkeeper::OAuth
|
|
248
213
|
subject.scopes == authorization_request.scope
|
249
214
|
end
|
250
215
|
end
|
251
|
-
|
252
216
|
end
|
253
217
|
|
254
218
|
describe "if no scope given" do
|
255
219
|
it "sets the scope to the default one" do
|
256
|
-
|
257
|
-
request
|
258
|
-
request.scope.should == "public email"
|
220
|
+
request = AuthorizationRequest.new(client, resource_owner, attributes.except(:scope))
|
221
|
+
request.scopes.to_s.should == "public write"
|
259
222
|
end
|
260
223
|
end
|
261
224
|
|
262
225
|
describe "with errors" do
|
263
226
|
before do
|
264
227
|
Doorkeeper::AccessGrant.should_not_receive(:create)
|
265
|
-
Doorkeeper.stub_chain(:configuration, :scopes, :all).and_return([Doorkeeper::Scope.new(:public)])
|
266
228
|
end
|
267
229
|
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
its(:error) { should == :invalid_request }
|
272
|
-
end
|
230
|
+
describe "when :response_type is missing" do
|
231
|
+
subject { auth(attributes.except(:response_type)) }
|
232
|
+
its(:error) { should == :invalid_request }
|
273
233
|
end
|
274
234
|
|
275
235
|
describe "when :redirect_uri is missing" do
|
@@ -277,13 +237,8 @@ module Doorkeeper::OAuth
|
|
277
237
|
its(:error) { should == :invalid_redirect_uri }
|
278
238
|
end
|
279
239
|
|
280
|
-
describe "when
|
281
|
-
subject {
|
282
|
-
its(:error) { should == :invalid_client }
|
283
|
-
end
|
284
|
-
|
285
|
-
describe "when :client_id does not match" do
|
286
|
-
subject { auth(attributes.merge(:client_id => "invalid")) }
|
240
|
+
describe "when client is not present" do
|
241
|
+
subject { AuthorizationRequest.new(nil, resource_owner, attributes) }
|
287
242
|
its(:error) { should == :invalid_client }
|
288
243
|
end
|
289
244
|
|
@@ -318,19 +273,14 @@ module Doorkeeper::OAuth
|
|
318
273
|
end
|
319
274
|
|
320
275
|
describe "when :scope contains scopes that are note registered in the provider" do
|
321
|
-
before do
|
322
|
-
Doorkeeper::OAuth::Helpers::ScopeChecker.stub(:valid?).and_return(false)
|
323
|
-
end
|
324
|
-
|
325
276
|
subject { auth(attributes.merge(:scope => "public strange")) }
|
326
277
|
its(:error) { should == :invalid_scope }
|
327
278
|
end
|
328
279
|
end
|
329
|
-
|
330
280
|
end
|
331
281
|
|
332
282
|
def auth(attributes)
|
333
|
-
AuthorizationRequest.new(resource_owner, attributes)
|
283
|
+
AuthorizationRequest.new(client, resource_owner, attributes)
|
334
284
|
end
|
335
285
|
end
|
336
286
|
end
|