doorkeeper 2.0.1 → 2.1.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.

Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -3
  3. data/CHANGELOG.md +19 -0
  4. data/README.md +6 -0
  5. data/app/views/doorkeeper/applications/_delete_form.html.erb +1 -1
  6. data/app/views/doorkeeper/applications/_form.html.erb +5 -6
  7. data/app/views/doorkeeper/applications/edit.html.erb +1 -1
  8. data/app/views/doorkeeper/applications/index.html.erb +5 -5
  9. data/app/views/doorkeeper/applications/new.html.erb +1 -1
  10. data/app/views/doorkeeper/applications/show.html.erb +7 -7
  11. data/app/views/doorkeeper/authorizations/error.html.erb +1 -1
  12. data/app/views/doorkeeper/authorizations/new.html.erb +5 -5
  13. data/app/views/doorkeeper/authorizations/show.html.erb +1 -1
  14. data/app/views/doorkeeper/authorized_applications/_delete_form.html.erb +1 -1
  15. data/app/views/doorkeeper/authorized_applications/index.html.erb +4 -4
  16. data/app/views/layouts/doorkeeper/admin.html.erb +2 -2
  17. data/app/views/layouts/doorkeeper/application.html.erb +1 -1
  18. data/config/locales/en.yml +77 -0
  19. data/gemfiles/Gemfile.common.rb +1 -1
  20. data/lib/doorkeeper/config.rb +4 -6
  21. data/lib/doorkeeper/models/access_token_mixin.rb +16 -4
  22. data/lib/doorkeeper/oauth/client.rb +1 -1
  23. data/lib/doorkeeper/oauth/client_credentials/validation.rb +15 -3
  24. data/lib/doorkeeper/oauth/helpers/scope_checker.rb +9 -8
  25. data/lib/doorkeeper/oauth/password_access_token_request.rb +1 -1
  26. data/lib/doorkeeper/oauth/pre_authorization.rb +5 -5
  27. data/lib/doorkeeper/oauth/refresh_token_request.rb +9 -1
  28. data/lib/doorkeeper/oauth/token_response.rb +2 -1
  29. data/lib/doorkeeper/version.rb +1 -1
  30. data/lib/generators/doorkeeper/templates/initializer.rb +8 -2
  31. data/spec/controllers/authorizations_controller_spec.rb +3 -0
  32. data/spec/dummy/config/environments/test.rb +0 -1
  33. data/spec/dummy/config/initializers/doorkeeper.rb +62 -18
  34. data/spec/lib/config_spec.rb +2 -6
  35. data/spec/lib/oauth/client_credentials/validation_spec.rb +26 -3
  36. data/spec/lib/oauth/helpers/scope_checker_spec.rb +25 -35
  37. data/spec/lib/oauth/password_access_token_request_spec.rb +8 -1
  38. data/spec/lib/oauth/pre_authorization_spec.rb +2 -0
  39. data/spec/lib/oauth/refresh_token_request_spec.rb +1 -1
  40. data/spec/lib/oauth/token_request_spec.rb +5 -1
  41. data/spec/lib/oauth/token_response_spec.rb +15 -9
  42. data/spec/models/doorkeeper/access_token_spec.rb +23 -8
  43. data/spec/requests/endpoints/authorization_spec.rb +6 -12
  44. data/spec/requests/flows/implicit_grant_errors_spec.rb +1 -0
  45. data/spec/requests/flows/implicit_grant_spec.rb +1 -0
  46. data/spec/requests/flows/password_spec.rb +1 -1
  47. data/spec/requests/flows/refresh_token_spec.rb +3 -4
  48. data/spec/spec_helper_integration.rb +1 -1
  49. data/spec/support/helpers/authorization_request_helper.rb +9 -0
  50. metadata +3 -4
@@ -2,7 +2,14 @@ require 'spec_helper_integration'
2
2
 
3
3
  module Doorkeeper::OAuth
4
4
  describe PasswordAccessTokenRequest do
5
- let(:server) { double :server, default_scopes: Doorkeeper::OAuth::Scopes.new, access_token_expires_in: 2.hours, refresh_token_enabled?: false }
5
+ let(:server) do
6
+ double(
7
+ :server,
8
+ default_scopes: Doorkeeper::OAuth::Scopes.new,
9
+ access_token_expires_in: 2.hours,
10
+ refresh_token_enabled?: false
11
+ )
12
+ end
6
13
  let(:credentials) { Client::Credentials.new(client.uid, client.secret) }
7
14
  let(:client) { FactoryGirl.create(:application) }
8
15
  let(:owner) { double :owner, id: 99 }
@@ -41,6 +41,7 @@ module Doorkeeper::OAuth
41
41
  end
42
42
 
43
43
  it 'accepts token as response type' do
44
+ server.stub(:grant_flows) { ['implicit'] }
44
45
  subject.response_type = 'token'
45
46
  expect(subject).to be_authorizable
46
47
  end
@@ -52,6 +53,7 @@ module Doorkeeper::OAuth
52
53
  end
53
54
 
54
55
  it 'accepts "token" as response type' do
56
+ server.stub(:grant_flows) { ['implicit'] }
55
57
  subject.response_type = 'token'
56
58
  expect(subject).to be_authorizable
57
59
  end
@@ -40,7 +40,7 @@ module Doorkeeper::OAuth
40
40
  it 'rejects revoked tokens' do
41
41
  refresh_token.revoke
42
42
  subject.validate
43
- expect(subject.error).to eq(:invalid_request)
43
+ expect(subject.error).to eq(:invalid_grant)
44
44
  end
45
45
 
46
46
  it 'accepts expired tokens' do
@@ -2,10 +2,14 @@ require 'spec_helper_integration'
2
2
 
3
3
  module Doorkeeper::OAuth
4
4
  describe TokenRequest do
5
+ let :application do
6
+ scopes = double(all: ['public'])
7
+ double(:application, id: 9990, scopes: scopes)
8
+ end
5
9
  let :pre_auth do
6
10
  double(
7
11
  :pre_auth,
8
- client: double(:application, id: 9990),
12
+ client: application,
9
13
  redirect_uri: 'http://tst.com/cb',
10
14
  state: nil,
11
15
  scopes: Scopes.from_string('public'),
@@ -18,12 +18,13 @@ module Doorkeeper::OAuth
18
18
  describe '.body' do
19
19
  let(:access_token) do
20
20
  double :access_token,
21
- token: 'some-token',
22
- expires_in: '3600',
21
+ token: 'some-token',
22
+ expires_in: '3600',
23
23
  expires_in_seconds: '300',
24
- scopes_string: 'two scopes',
25
- refresh_token: 'some-refresh-token',
26
- token_type: 'bearer'
24
+ scopes_string: 'two scopes',
25
+ refresh_token: 'some-refresh-token',
26
+ token_type: 'bearer',
27
+ created_at: 0
27
28
  end
28
29
 
29
30
  subject { TokenResponse.new(access_token).body }
@@ -49,16 +50,21 @@ module Doorkeeper::OAuth
49
50
  it 'includes :refresh_token' do
50
51
  expect(subject['refresh_token']).to eq('some-refresh-token')
51
52
  end
53
+
54
+ it 'includes :created_at' do
55
+ expect(subject['created_at']).to eq(0)
56
+ end
52
57
  end
53
58
 
54
59
  describe '.body filters out empty values' do
55
60
  let(:access_token) do
56
61
  double :access_token,
57
- token: 'some-token',
62
+ token: 'some-token',
58
63
  expires_in_seconds: '',
59
- scopes_string: '',
60
- refresh_token: '',
61
- token_type: 'bearer'
64
+ scopes_string: '',
65
+ refresh_token: '',
66
+ token_type: 'bearer',
67
+ created_at: 0
62
68
  end
63
69
 
64
70
  subject { TokenResponse.new(access_token).body }
@@ -156,9 +156,13 @@ module Doorkeeper
156
156
  describe '.matching_token_for' do
157
157
  let(:resource_owner_id) { 100 }
158
158
  let(:application) { FactoryGirl.create :application }
159
- let(:scopes) { Doorkeeper::OAuth::Scopes.from_string('public write') }
159
+ let(:scopes) { Doorkeeper::OAuth::Scopes.from_string('public write') }
160
160
  let(:default_attributes) do
161
- { application: application, resource_owner_id: resource_owner_id, scopes: scopes.to_s }
161
+ {
162
+ application: application,
163
+ resource_owner_id: resource_owner_id,
164
+ scopes: scopes.to_s
165
+ }
162
166
  end
163
167
 
164
168
  it 'returns only one token' do
@@ -187,7 +191,7 @@ module Doorkeeper
187
191
  end
188
192
 
189
193
  it 'matches the application' do
190
- token = FactoryGirl.create :access_token, default_attributes.merge(application: FactoryGirl.create(:application))
194
+ FactoryGirl.create :access_token, default_attributes.merge(application: FactoryGirl.create(:application))
191
195
  last_token = AccessToken.matching_token_for(application, resource_owner_id, scopes)
192
196
  expect(last_token).to be_nil
193
197
  end
@@ -204,6 +208,15 @@ module Doorkeeper
204
208
  expect(last_token).to be_nil
205
209
  end
206
210
 
211
+ it 'matches application scopes' do
212
+ application = FactoryGirl.create :application, scopes: "private read"
213
+ FactoryGirl.create :access_token, default_attributes.merge(
214
+ application: application
215
+ )
216
+ last_token = AccessToken.matching_token_for(application, resource_owner_id, scopes)
217
+ expect(last_token).to be_nil
218
+ end
219
+
207
220
  it 'returns the last created token' do
208
221
  FactoryGirl.create :access_token, default_attributes.merge(created_at: 1.day.ago)
209
222
  token = FactoryGirl.create :access_token, default_attributes
@@ -211,12 +224,14 @@ module Doorkeeper
211
224
  expect(last_token).to eq(token)
212
225
  end
213
226
 
214
- it 'returns as_json hash' do
227
+ it 'returns as_json hash' do
215
228
  token = FactoryGirl.create :access_token, default_attributes
216
- token_hash = { resource_owner_id: token.resource_owner_id,
217
- scopes: token.scopes,
218
- expires_in_seconds: token.expires_in_seconds,
219
- application: { uid: token.application.uid }
229
+ token_hash = {
230
+ resource_owner_id: token.resource_owner_id,
231
+ scopes: token.scopes,
232
+ expires_in_seconds: token.expires_in_seconds,
233
+ application: { uid: token.application.uid },
234
+ created_at: token.created_at.to_i,
220
235
  }
221
236
  expect(token.as_json).to eq token_hash
222
237
  end
@@ -53,14 +53,6 @@ feature 'Authorization endpoint' do
53
53
  end
54
54
 
55
55
  context 'forgery protection enabled' do
56
- before do
57
- ActionController::Base.allow_forgery_protection = true
58
- end
59
-
60
- after do
61
- ActionController::Base.allow_forgery_protection = false
62
- end
63
-
64
56
  background do
65
57
  create_resource_owner
66
58
  sign_in
@@ -68,10 +60,12 @@ feature 'Authorization endpoint' do
68
60
 
69
61
  scenario 'raises exception on forged requests' do
70
62
  ActionController::Base.any_instance.should_receive(:handle_unverified_request)
71
- post "/oauth/authorize",
72
- client_id: @client.uid,
73
- redirect_uri: @client.redirect_uri,
74
- response_type: 'code'
63
+ allowing_forgery_protection do
64
+ post "/oauth/authorize",
65
+ client_id: @client.uid,
66
+ redirect_uri: @client.redirect_uri,
67
+ response_type: 'code'
68
+ end
75
69
  end
76
70
  end
77
71
  end
@@ -3,6 +3,7 @@ require 'spec_helper_integration'
3
3
  feature 'Implicit Grant Flow Errors' do
4
4
  background do
5
5
  config_is_set(:authenticate_resource_owner) { User.first || redirect_to('/sign_in') }
6
+ config_is_set(:grant_flows, ["implicit"])
6
7
  client_exists
7
8
  create_resource_owner
8
9
  sign_in
@@ -3,6 +3,7 @@ require 'spec_helper_integration'
3
3
  feature 'Implicit Grant Flow' do
4
4
  background do
5
5
  config_is_set(:authenticate_resource_owner) { User.first || redirect_to('/sign_in') }
6
+ config_is_set(:grant_flows, ["implicit"])
6
7
  client_exists
7
8
  create_resource_owner
8
9
  sign_in
@@ -23,6 +23,7 @@ end
23
23
 
24
24
  feature 'Resource Owner Password Credentials Flow' do
25
25
  background do
26
+ config_is_set(:grant_flows, ["password"])
26
27
  config_is_set(:resource_owner_from_credentials) { User.authenticate! params[:username], params[:password] }
27
28
  client_exists
28
29
  create_resource_owner
@@ -67,7 +68,6 @@ feature 'Resource Owner Password Credentials Flow' do
67
68
  post password_token_endpoint_url(client: @client, resource_owner: @resource_owner)
68
69
 
69
70
  Doorkeeper::AccessToken.count.should be(1)
70
-
71
71
  should_have_json 'access_token', Doorkeeper::AccessToken.first.token
72
72
  end
73
73
  end
@@ -53,25 +53,24 @@ feature 'Refresh Token Flow' do
53
53
  expect(@token.reload).to be_revoked
54
54
  end
55
55
 
56
- # TODO: verify proper error code for this (previously was invalid_grant)
57
56
  scenario 'client gets an error for invalid refresh token' do
58
57
  post refresh_token_endpoint_url(client: @client, refresh_token: 'invalid')
59
58
  should_not_have_json 'refresh_token'
60
- should_have_json 'error', 'invalid_request'
59
+ should_have_json 'error', 'invalid_grant'
61
60
  end
62
61
 
63
- # TODO: verify proper error code for this (previously was invalid_grant)
64
62
  scenario 'client gets an error for revoked acccess token' do
65
63
  @token.revoke
66
64
  post refresh_token_endpoint_url(client: @client, refresh_token: @token.refresh_token)
67
65
  should_not_have_json 'refresh_token'
68
- should_have_json 'error', 'invalid_request'
66
+ should_have_json 'error', 'invalid_grant'
69
67
  end
70
68
  end
71
69
 
72
70
  context 'refreshing the token with multiple sessions (devices)' do
73
71
  before do
74
72
  # enable password auth to simulate other devices
73
+ config_is_set(:grant_flows, ["password"])
75
74
  config_is_set(:resource_owner_from_credentials) { User.authenticate! params[:username], params[:password] }
76
75
  create_resource_owner
77
76
  _another_token = post password_token_endpoint_url(client: @client, resource_owner: @resource_owner)
@@ -2,7 +2,7 @@ ENV['RAILS_ENV'] ||= 'test'
2
2
  TABLE_NAME_PREFIX = ENV['table_name_prefix'] || nil
3
3
  TABLE_NAME_SUFFIX = ENV['table_name_suffix'] || nil
4
4
 
5
- orm = ENV['BUNDLE_GEMFILE'].match(/Gemfile\.(.+)\.rb/)
5
+ orm = (ENV['BUNDLE_GEMFILE'] || '').match(/Gemfile\.(.+)\.rb/)
6
6
  DOORKEEPER_ORM = (orm && orm[1] || :active_record).to_sym
7
7
 
8
8
  $LOAD_PATH.unshift File.dirname(__FILE__)
@@ -27,6 +27,15 @@ module AuthorizationRequestHelper
27
27
  def i_should_be_on_client_callback(client)
28
28
  expect(client.redirect_uri).to eq("#{current_uri.scheme}://#{current_uri.host}#{current_uri.path}")
29
29
  end
30
+
31
+ def allowing_forgery_protection(&block)
32
+ _original_value = ActionController::Base.allow_forgery_protection
33
+ ActionController::Base.allow_forgery_protection = true
34
+
35
+ block.call
36
+ ensure
37
+ ActionController::Base.allow_forgery_protection = _original_value
38
+ end
30
39
  end
31
40
 
32
41
  RSpec.configuration.send :include, AuthorizationRequestHelper, type: :request
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doorkeeper
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felipe Elias Philipp
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-12-17 00:00:00.000000000 Z
12
+ date: 2015-01-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
@@ -338,7 +338,6 @@ files:
338
338
  - spec/dummy/config/mongoid3.yml
339
339
  - spec/dummy/config/mongoid4.yml
340
340
  - spec/dummy/config/routes.rb
341
- - spec/dummy/db/development.sqlite3
342
341
  - spec/dummy/db/migrate/20111122132257_create_users.rb
343
342
  - spec/dummy/db/migrate/20120312140401_add_password_to_users.rb
344
343
  - spec/dummy/db/migrate/20130902165751_create_doorkeeper_tables.rb
@@ -444,7 +443,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
444
443
  version: '0'
445
444
  requirements: []
446
445
  rubyforge_project:
447
- rubygems_version: 2.2.2
446
+ rubygems_version: 2.4.5
448
447
  signing_key:
449
448
  specification_version: 4
450
449
  summary: Doorkeeper is an OAuth 2 provider for Rails.