doorkeeper 5.2.0.rc1 → 5.2.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 (69) hide show
  1. checksums.yaml +4 -4
  2. data/Appraisals +1 -1
  3. data/CHANGELOG.md +33 -2
  4. data/CONTRIBUTING.md +7 -0
  5. data/Dangerfile +1 -1
  6. data/Dockerfile +29 -0
  7. data/Gemfile +1 -1
  8. data/README.md +9 -1
  9. data/app/controllers/doorkeeper/application_controller.rb +1 -1
  10. data/app/controllers/doorkeeper/application_metal_controller.rb +2 -1
  11. data/app/controllers/doorkeeper/authorizations_controller.rb +14 -7
  12. data/app/controllers/doorkeeper/tokens_controller.rb +14 -1
  13. data/config/locales/en.yml +5 -1
  14. data/doorkeeper.gemspec +8 -0
  15. data/gemfiles/rails_6_0.gemfile +1 -1
  16. data/lib/doorkeeper/config.rb +64 -9
  17. data/lib/doorkeeper/errors.rb +13 -18
  18. data/lib/doorkeeper/helpers/controller.rb +6 -2
  19. data/lib/doorkeeper/models/access_token_mixin.rb +43 -2
  20. data/lib/doorkeeper/oauth/authorization/code.rb +1 -5
  21. data/lib/doorkeeper/oauth/authorization_code_request.rb +18 -9
  22. data/lib/doorkeeper/oauth/base_request.rb +2 -0
  23. data/lib/doorkeeper/oauth/client_credentials/creator.rb +14 -0
  24. data/lib/doorkeeper/oauth/client_credentials/validation.rb +8 -0
  25. data/lib/doorkeeper/oauth/code_request.rb +5 -11
  26. data/lib/doorkeeper/oauth/invalid_request_response.rb +43 -0
  27. data/lib/doorkeeper/oauth/password_access_token_request.rb +7 -2
  28. data/lib/doorkeeper/oauth/pre_authorization.rb +70 -37
  29. data/lib/doorkeeper/oauth/refresh_token_request.rb +5 -2
  30. data/lib/doorkeeper/oauth/token_introspection.rb +16 -7
  31. data/lib/doorkeeper/oauth/token_request.rb +4 -18
  32. data/lib/doorkeeper/orm/active_record/application.rb +1 -1
  33. data/lib/doorkeeper/orm/active_record/redirect_uri_validator.rb +61 -0
  34. data/lib/doorkeeper/orm/active_record.rb +2 -2
  35. data/lib/doorkeeper/request/authorization_code.rb +2 -0
  36. data/lib/doorkeeper/request.rb +6 -11
  37. data/lib/doorkeeper/server.rb +2 -6
  38. data/lib/doorkeeper/version.rb +1 -1
  39. data/lib/doorkeeper.rb +1 -0
  40. data/lib/generators/doorkeeper/templates/initializer.rb +88 -43
  41. data/lib/generators/doorkeeper/templates/migration.rb.erb +1 -1
  42. data/spec/controllers/authorizations_controller_spec.rb +140 -61
  43. data/spec/controllers/protected_resources_controller_spec.rb +3 -3
  44. data/spec/controllers/tokens_controller_spec.rb +140 -40
  45. data/spec/dummy/config/initializers/doorkeeper.rb +47 -20
  46. data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +1 -1
  47. data/spec/lib/config_spec.rb +32 -1
  48. data/spec/lib/oauth/authorization_code_request_spec.rb +11 -1
  49. data/spec/lib/oauth/base_request_spec.rb +33 -16
  50. data/spec/lib/oauth/client_credentials/creator_spec.rb +3 -0
  51. data/spec/lib/oauth/code_request_spec.rb +27 -28
  52. data/spec/lib/oauth/invalid_request_response_spec.rb +75 -0
  53. data/spec/lib/oauth/pre_authorization_spec.rb +80 -55
  54. data/spec/lib/oauth/refresh_token_request_spec.rb +1 -0
  55. data/spec/lib/oauth/token_request_spec.rb +20 -17
  56. data/spec/lib/server_spec.rb +0 -12
  57. data/spec/requests/endpoints/authorization_spec.rb +21 -5
  58. data/spec/requests/endpoints/token_spec.rb +1 -1
  59. data/spec/requests/flows/authorization_code_errors_spec.rb +1 -0
  60. data/spec/requests/flows/authorization_code_spec.rb +77 -23
  61. data/spec/requests/flows/client_credentials_spec.rb +38 -0
  62. data/spec/requests/flows/implicit_grant_errors_spec.rb +22 -10
  63. data/spec/requests/flows/implicit_grant_spec.rb +9 -8
  64. data/spec/requests/flows/password_spec.rb +37 -0
  65. data/spec/requests/flows/refresh_token_spec.rb +1 -1
  66. data/spec/support/helpers/request_spec_helper.rb +14 -2
  67. data/spec/validators/redirect_uri_validator_spec.rb +1 -1
  68. metadata +15 -6
  69. data/app/validators/redirect_uri_validator.rb +0 -60
@@ -4,6 +4,7 @@ require "spec_helper"
4
4
 
5
5
  feature "Implicit Grant Flow Errors" do
6
6
  background do
7
+ default_scopes_exist :default
7
8
  config_is_set(:authenticate_resource_owner) { User.first || redirect_to("/sign_in") }
8
9
  config_is_set(:grant_flows, ["implicit"])
9
10
  client_exists
@@ -15,20 +16,31 @@ feature "Implicit Grant Flow Errors" do
15
16
  access_token_should_not_exist
16
17
  end
17
18
 
18
- [
19
- %i[client_id invalid_client],
20
- %i[redirect_uri invalid_redirect_uri],
21
- ].each do |error|
22
- scenario "displays #{error.last} error for invalid #{error.first}" do
23
- visit authorization_endpoint_url(client: @client, error.first => "invalid", response_type: "token")
19
+ context "when validate client_id param" do
20
+ scenario "displays invalid_client error for invalid client_id" do
21
+ visit authorization_endpoint_url(client_id: "invalid", response_type: "token")
24
22
  i_should_not_see "Authorize"
25
- i_should_see_translated_error_message error.last
23
+ i_should_see_translated_error_message :invalid_client
26
24
  end
27
25
 
28
- scenario "displays #{error.last} error when #{error.first} is missing" do
29
- visit authorization_endpoint_url(client: @client, error.first => "", response_type: "token")
26
+ scenario "displays invalid_request error when client_id is missing" do
27
+ visit authorization_endpoint_url(client_id: "", response_type: "token")
30
28
  i_should_not_see "Authorize"
31
- i_should_see_translated_error_message error.last
29
+ i_should_see_translated_invalid_request_error_message :missing_param, :client_id
30
+ end
31
+ end
32
+
33
+ context "when validate redirect_uri param" do
34
+ scenario "displays invalid_redirect_uri error for invalid redirect_uri" do
35
+ visit authorization_endpoint_url(client: @client, redirect_uri: "invalid", response_type: "token")
36
+ i_should_not_see "Authorize"
37
+ i_should_see_translated_error_message :invalid_redirect_uri
38
+ end
39
+
40
+ scenario "displays invalid_redirect_uri error when redirect_uri is missing" do
41
+ visit authorization_endpoint_url(client: @client, redirect_uri: "", response_type: "token")
42
+ i_should_not_see "Authorize"
43
+ i_should_see_translated_error_message :invalid_redirect_uri
32
44
  end
33
45
  end
34
46
  end
@@ -4,6 +4,7 @@ require "spec_helper"
4
4
 
5
5
  feature "Implicit Grant Flow (feature spec)" do
6
6
  background do
7
+ default_scopes_exist :default
7
8
  config_is_set(:authenticate_resource_owner) { User.first || redirect_to("/sign_in") }
8
9
  config_is_set(:grant_flows, ["implicit"])
9
10
  client_exists
@@ -25,16 +26,15 @@ feature "Implicit Grant Flow (feature spec)" do
25
26
  @client.update(scopes: "public write read")
26
27
  end
27
28
 
28
- scenario "access token has no scopes" do
29
+ scenario "scope is invalid because default scope is different from application scope" do
29
30
  default_scopes_exist :admin
30
31
  visit authorization_endpoint_url(client: @client, response_type: "token")
31
- click_on "Authorize"
32
- access_token_should_exist_for @client, @resource_owner
33
- token = Doorkeeper::AccessToken.first
34
- expect(token.scopes).to be_empty
32
+ response_status_should_be 200
33
+ i_should_not_see "Authorize"
34
+ i_should_see_translated_error_message :invalid_scope
35
35
  end
36
36
 
37
- scenario "access token has scopes which are common in application scopees and default scopes" do
37
+ scenario "access token has scopes which are common in application scopes and default scopes" do
38
38
  default_scopes_exist :public, :write
39
39
  visit authorization_endpoint_url(client: @client, response_type: "token")
40
40
  click_on "Authorize"
@@ -46,6 +46,7 @@ end
46
46
 
47
47
  describe "Implicit Grant Flow (request spec)" do
48
48
  before do
49
+ default_scopes_exist :default
49
50
  config_is_set(:authenticate_resource_owner) { User.first || redirect_to("/sign_in") }
50
51
  config_is_set(:grant_flows, ["implicit"])
51
52
  client_exists
@@ -56,7 +57,7 @@ describe "Implicit Grant Flow (request spec)" do
56
57
  it "should return a new token each request" do
57
58
  allow(Doorkeeper.configuration).to receive(:reuse_access_token).and_return(false)
58
59
 
59
- token = client_is_authorized(@client, @resource_owner)
60
+ token = client_is_authorized(@client, @resource_owner, scopes: "default")
60
61
 
61
62
  post "/oauth/authorize",
62
63
  params: {
@@ -73,7 +74,7 @@ describe "Implicit Grant Flow (request spec)" do
73
74
  it "should return the same token if it is still accessible" do
74
75
  allow(Doorkeeper.configuration).to receive(:reuse_access_token).and_return(true)
75
76
 
76
- token = client_is_authorized(@client, @resource_owner)
77
+ token = client_is_authorized(@client, @resource_owner, scopes: "default")
77
78
 
78
79
  post "/oauth/authorize",
79
80
  params: {
@@ -31,6 +31,43 @@ describe "Resource Owner Password Credentials Flow" do
31
31
  context "with non-confidential/public client" do
32
32
  let(:client_attributes) { { confidential: false } }
33
33
 
34
+ context "when configured to check application supported grant flow" do
35
+ before do
36
+ Doorkeeper.configuration.instance_variable_set(
37
+ :@allow_grant_flow_for_client,
38
+ ->(_grant_flow, client) { client.name == "admin" }
39
+ )
40
+ end
41
+
42
+ scenario "forbids the request when doesn't satisfy condition" do
43
+ @client.update(name: "sample app")
44
+
45
+ expect do
46
+ post password_token_endpoint_url(
47
+ client_id: @client.uid,
48
+ client_secret: "foobar",
49
+ resource_owner: @resource_owner
50
+ )
51
+ end.not_to(change { Doorkeeper::AccessToken.count })
52
+
53
+ expect(response.status).to eq(401)
54
+ should_have_json "error", "invalid_client"
55
+ end
56
+
57
+ scenario "allows the request when satisfies condition" do
58
+ @client.update(name: "admin")
59
+
60
+ expect do
61
+ post password_token_endpoint_url(client_id: @client.uid, resource_owner: @resource_owner)
62
+ end.to change { Doorkeeper::AccessToken.count }.by(1)
63
+
64
+ token = Doorkeeper::AccessToken.first
65
+
66
+ expect(token.application_id).to eq @client.id
67
+ should_have_json "access_token", token.token
68
+ end
69
+ end
70
+
34
71
  context "when client_secret absent" do
35
72
  it "should issue new token" do
36
73
  expect do
@@ -172,7 +172,7 @@ describe "Refresh Token Flow" do
172
172
  post refresh_token_endpoint_url(client: @client, refresh_token: @token.refresh_token)
173
173
 
174
174
  should_not_have_json "refresh_token"
175
- should_have_json "error", "invalid_request"
175
+ should_have_json "error", "invalid_grant"
176
176
  end
177
177
  end
178
178
 
@@ -54,7 +54,7 @@ module RequestSpecHelper
54
54
  end
55
55
 
56
56
  def with_header(header, value)
57
- page.driver.header header, value
57
+ page.driver.header(header, value)
58
58
  end
59
59
 
60
60
  def basic_auth_header_for_client(client)
@@ -86,8 +86,20 @@ module RequestSpecHelper
86
86
  i_should_see translated_error_message(key)
87
87
  end
88
88
 
89
+ def i_should_not_see_translated_error_message(key)
90
+ i_should_not_see translated_error_message(key)
91
+ end
92
+
89
93
  def translated_error_message(key)
90
- I18n.translate key, scope: %i[doorkeeper errors messages]
94
+ I18n.translate(key, scope: %i[doorkeeper errors messages])
95
+ end
96
+
97
+ def i_should_see_translated_invalid_request_error_message(key, value)
98
+ i_should_see translated_invalid_request_error_message(key, value)
99
+ end
100
+
101
+ def translated_invalid_request_error_message(key, value)
102
+ I18n.translate key, scope: %i[doorkeeper errors messages invalid_request], value: value
91
103
  end
92
104
 
93
105
  def response_status_should_be(status)
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- describe RedirectUriValidator do
5
+ describe Doorkeeper::RedirectUriValidator do
6
6
  subject do
7
7
  FactoryBot.create(:application)
8
8
  end
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: 5.2.0.rc1
4
+ version: 5.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felipe Elias Philipp
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2019-05-23 00:00:00.000000000 Z
14
+ date: 2019-09-16 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: railties
@@ -179,6 +179,7 @@ files:
179
179
  - CODE_OF_CONDUCT.md
180
180
  - CONTRIBUTING.md
181
181
  - Dangerfile
182
+ - Dockerfile
182
183
  - Gemfile
183
184
  - MIT-LICENSE
184
185
  - NEWS.md
@@ -197,7 +198,6 @@ files:
197
198
  - app/controllers/doorkeeper/token_info_controller.rb
198
199
  - app/controllers/doorkeeper/tokens_controller.rb
199
200
  - app/helpers/doorkeeper/dashboard_helper.rb
200
- - app/validators/redirect_uri_validator.rb
201
201
  - app/views/doorkeeper/applications/_delete_form.html.erb
202
202
  - app/views/doorkeeper/applications/_form.html.erb
203
203
  - app/views/doorkeeper/applications/edit.html.erb
@@ -260,6 +260,7 @@ files:
260
260
  - lib/doorkeeper/oauth/helpers/scope_checker.rb
261
261
  - lib/doorkeeper/oauth/helpers/unique_token.rb
262
262
  - lib/doorkeeper/oauth/helpers/uri_checker.rb
263
+ - lib/doorkeeper/oauth/invalid_request_response.rb
263
264
  - lib/doorkeeper/oauth/invalid_token_response.rb
264
265
  - lib/doorkeeper/oauth/nonstandard.rb
265
266
  - lib/doorkeeper/oauth/password_access_token_request.rb
@@ -274,6 +275,7 @@ files:
274
275
  - lib/doorkeeper/orm/active_record/access_grant.rb
275
276
  - lib/doorkeeper/orm/active_record/access_token.rb
276
277
  - lib/doorkeeper/orm/active_record/application.rb
278
+ - lib/doorkeeper/orm/active_record/redirect_uri_validator.rb
277
279
  - lib/doorkeeper/orm/active_record/stale_records_cleaner.rb
278
280
  - lib/doorkeeper/rails/helpers.rb
279
281
  - lib/doorkeeper/rails/routes.rb
@@ -395,6 +397,7 @@ files:
395
397
  - spec/lib/oauth/helpers/scope_checker_spec.rb
396
398
  - spec/lib/oauth/helpers/unique_token_spec.rb
397
399
  - spec/lib/oauth/helpers/uri_checker_spec.rb
400
+ - spec/lib/oauth/invalid_request_response_spec.rb
398
401
  - spec/lib/oauth/invalid_token_response_spec.rb
399
402
  - spec/lib/oauth/password_access_token_request_spec.rb
400
403
  - spec/lib/oauth/pre_authorization_spec.rb
@@ -452,7 +455,12 @@ files:
452
455
  homepage: https://github.com/doorkeeper-gem/doorkeeper
453
456
  licenses:
454
457
  - MIT
455
- metadata: {}
458
+ metadata:
459
+ homepage_uri: https://github.com/doorkeeper-gem/doorkeeper
460
+ changelog_uri: https://github.com/doorkeeper-gem/doorkeeper/blob/master/CHANGELOG.md
461
+ source_code_uri: https://github.com/doorkeeper-gem/doorkeeper
462
+ bug_tracker_uri: https://github.com/doorkeeper-gem/doorkeeper/issues
463
+ documentation_uri: https://doorkeeper.gitbook.io/guides/
456
464
  post_install_message:
457
465
  rdoc_options: []
458
466
  require_paths:
@@ -464,9 +472,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
464
472
  version: '2.4'
465
473
  required_rubygems_version: !ruby/object:Gem::Requirement
466
474
  requirements:
467
- - - ">"
475
+ - - ">="
468
476
  - !ruby/object:Gem::Version
469
- version: 1.3.1
477
+ version: '0'
470
478
  requirements: []
471
479
  rubygems_version: 3.0.2
472
480
  signing_key:
@@ -556,6 +564,7 @@ test_files:
556
564
  - spec/lib/oauth/helpers/scope_checker_spec.rb
557
565
  - spec/lib/oauth/helpers/unique_token_spec.rb
558
566
  - spec/lib/oauth/helpers/uri_checker_spec.rb
567
+ - spec/lib/oauth/invalid_request_response_spec.rb
559
568
  - spec/lib/oauth/invalid_token_response_spec.rb
560
569
  - spec/lib/oauth/password_access_token_request_spec.rb
561
570
  - spec/lib/oauth/pre_authorization_spec.rb
@@ -1,60 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "uri"
4
-
5
- # ActiveModel validator for redirect URI validation in according
6
- # to OAuth standards and Doorkeeper configuration.
7
- #
8
- class RedirectUriValidator < ActiveModel::EachValidator
9
- def validate_each(record, attribute, value)
10
- if value.blank?
11
- return if Doorkeeper.configuration.allow_blank_redirect_uri?(record)
12
-
13
- record.errors.add(attribute, :blank)
14
- else
15
- value.split.each do |val|
16
- next if oob_redirect_uri?(val)
17
-
18
- uri = ::URI.parse(val)
19
- record.errors.add(attribute, :forbidden_uri) if forbidden_uri?(uri)
20
- record.errors.add(attribute, :fragment_present) unless uri.fragment.nil?
21
- record.errors.add(attribute, :unspecified_scheme) if unspecified_scheme?(uri)
22
- record.errors.add(attribute, :relative_uri) if relative_uri?(uri)
23
- record.errors.add(attribute, :secured_uri) if invalid_ssl_uri?(uri)
24
- end
25
- end
26
- rescue URI::InvalidURIError
27
- record.errors.add(attribute, :invalid_uri)
28
- end
29
-
30
- private
31
-
32
- def oob_redirect_uri?(uri)
33
- Doorkeeper::OAuth::NonStandard::IETF_WG_OAUTH2_OOB_METHODS.include?(uri)
34
- end
35
-
36
- def forbidden_uri?(uri)
37
- Doorkeeper.configuration.forbid_redirect_uri.call(uri)
38
- end
39
-
40
- def unspecified_scheme?(uri)
41
- return true if uri.opaque.present?
42
-
43
- %w[localhost].include?(uri.try(:scheme))
44
- end
45
-
46
- def relative_uri?(uri)
47
- uri.scheme.nil? && uri.host.nil?
48
- end
49
-
50
- def invalid_ssl_uri?(uri)
51
- forces_ssl = Doorkeeper.configuration.force_ssl_in_redirect_uri
52
- non_https = uri.try(:scheme) == "http"
53
-
54
- if forces_ssl.respond_to?(:call)
55
- forces_ssl.call(uri) && non_https
56
- else
57
- forces_ssl && non_https
58
- end
59
- end
60
- end