doorkeeper 5.0.0 → 5.1.0.rc1

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.
Files changed (160) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +12 -3
  3. data/Dangerfile +67 -0
  4. data/Gemfile +3 -1
  5. data/NEWS.md +49 -5
  6. data/README.md +19 -4
  7. data/app/controllers/doorkeeper/application_controller.rb +2 -0
  8. data/app/controllers/doorkeeper/application_metal_controller.rb +2 -0
  9. data/app/controllers/doorkeeper/applications_controller.rb +4 -2
  10. data/app/controllers/doorkeeper/authorizations_controller.rb +3 -3
  11. data/app/controllers/doorkeeper/authorized_applications_controller.rb +2 -0
  12. data/app/controllers/doorkeeper/token_info_controller.rb +2 -0
  13. data/app/controllers/doorkeeper/tokens_controller.rb +8 -6
  14. data/app/helpers/doorkeeper/dashboard_helper.rb +2 -0
  15. data/app/validators/redirect_uri_validator.rb +2 -0
  16. data/app/views/doorkeeper/applications/show.html.erb +1 -1
  17. data/app/views/layouts/doorkeeper/admin.html.erb +5 -3
  18. data/bin/console +15 -0
  19. data/doorkeeper.gemspec +23 -22
  20. data/gemfiles/rails_4_2.gemfile +1 -0
  21. data/gemfiles/rails_5_0.gemfile +1 -0
  22. data/gemfiles/rails_5_1.gemfile +1 -0
  23. data/gemfiles/rails_5_2.gemfile +2 -1
  24. data/gemfiles/rails_master.gemfile +1 -0
  25. data/lib/doorkeeper/config.rb +80 -8
  26. data/lib/doorkeeper/engine.rb +2 -0
  27. data/lib/doorkeeper/errors.rb +17 -0
  28. data/lib/doorkeeper/grape/authorization_decorator.rb +2 -0
  29. data/lib/doorkeeper/grape/helpers.rb +2 -0
  30. data/lib/doorkeeper/helpers/controller.rb +5 -2
  31. data/lib/doorkeeper/models/access_grant_mixin.rb +13 -4
  32. data/lib/doorkeeper/models/access_token_mixin.rb +45 -12
  33. data/lib/doorkeeper/models/application_mixin.rb +54 -1
  34. data/lib/doorkeeper/models/concerns/accessible.rb +2 -0
  35. data/lib/doorkeeper/models/concerns/expirable.rb +2 -0
  36. data/lib/doorkeeper/models/concerns/hashable.rb +137 -0
  37. data/lib/doorkeeper/models/concerns/orderable.rb +2 -0
  38. data/lib/doorkeeper/models/concerns/ownership.rb +2 -0
  39. data/lib/doorkeeper/models/concerns/revocable.rb +2 -0
  40. data/lib/doorkeeper/models/concerns/scopes.rb +3 -1
  41. data/lib/doorkeeper/oauth/authorization/code.rb +3 -1
  42. data/lib/doorkeeper/oauth/authorization/context.rb +2 -0
  43. data/lib/doorkeeper/oauth/authorization/token.rb +3 -1
  44. data/lib/doorkeeper/oauth/authorization/uri_builder.rb +2 -0
  45. data/lib/doorkeeper/oauth/authorization_code_request.rb +3 -1
  46. data/lib/doorkeeper/oauth/base_request.rb +2 -0
  47. data/lib/doorkeeper/oauth/base_response.rb +2 -0
  48. data/lib/doorkeeper/oauth/client/credentials.rb +2 -0
  49. data/lib/doorkeeper/oauth/client.rb +3 -1
  50. data/lib/doorkeeper/oauth/client_credentials/creator.rb +2 -0
  51. data/lib/doorkeeper/oauth/client_credentials/issuer.rb +2 -0
  52. data/lib/doorkeeper/oauth/client_credentials/validation.rb +6 -3
  53. data/lib/doorkeeper/oauth/client_credentials_request.rb +2 -0
  54. data/lib/doorkeeper/oauth/code_request.rb +2 -0
  55. data/lib/doorkeeper/oauth/code_response.rb +4 -2
  56. data/lib/doorkeeper/oauth/error.rb +2 -0
  57. data/lib/doorkeeper/oauth/error_response.rb +10 -0
  58. data/lib/doorkeeper/oauth/forbidden_token_response.rb +9 -2
  59. data/lib/doorkeeper/oauth/helpers/scope_checker.rb +25 -8
  60. data/lib/doorkeeper/oauth/helpers/unique_token.rb +2 -0
  61. data/lib/doorkeeper/oauth/helpers/uri_checker.rb +37 -2
  62. data/lib/doorkeeper/oauth/invalid_token_response.rb +18 -0
  63. data/lib/doorkeeper/oauth/password_access_token_request.rb +9 -2
  64. data/lib/doorkeeper/oauth/pre_authorization.rb +10 -3
  65. data/lib/doorkeeper/oauth/refresh_token_request.rb +14 -3
  66. data/lib/doorkeeper/oauth/scopes.rb +2 -0
  67. data/lib/doorkeeper/oauth/token.rb +2 -0
  68. data/lib/doorkeeper/oauth/token_introspection.rb +2 -0
  69. data/lib/doorkeeper/oauth/token_request.rb +2 -0
  70. data/lib/doorkeeper/oauth/token_response.rb +4 -2
  71. data/lib/doorkeeper/orm/active_record/access_grant.rb +22 -2
  72. data/lib/doorkeeper/orm/active_record/application.rb +16 -2
  73. data/lib/doorkeeper/orm/active_record.rb +2 -0
  74. data/lib/doorkeeper/rails/helpers.rb +4 -0
  75. data/lib/doorkeeper/rails/routes/mapper.rb +2 -0
  76. data/lib/doorkeeper/rails/routes/mapping.rb +2 -0
  77. data/lib/doorkeeper/rails/routes.rb +9 -2
  78. data/lib/doorkeeper/rake/db.rake +4 -4
  79. data/lib/doorkeeper/request/authorization_code.rb +2 -0
  80. data/lib/doorkeeper/request/client_credentials.rb +2 -0
  81. data/lib/doorkeeper/request/code.rb +2 -0
  82. data/lib/doorkeeper/request/password.rb +2 -0
  83. data/lib/doorkeeper/request/refresh_token.rb +2 -0
  84. data/lib/doorkeeper/request/strategy.rb +2 -0
  85. data/lib/doorkeeper/request/token.rb +2 -0
  86. data/lib/doorkeeper/request.rb +2 -0
  87. data/lib/doorkeeper/server.rb +2 -0
  88. data/lib/doorkeeper/stale_records_cleaner.rb +20 -0
  89. data/lib/doorkeeper/validations.rb +2 -0
  90. data/lib/doorkeeper/version.rb +4 -2
  91. data/lib/doorkeeper.rb +2 -0
  92. data/lib/generators/doorkeeper/templates/initializer.rb +61 -3
  93. data/lib/generators/doorkeeper/templates/migration.rb.erb +2 -3
  94. data/spec/controllers/application_metal_controller_spec.rb +18 -4
  95. data/spec/controllers/applications_controller_spec.rb +37 -41
  96. data/spec/controllers/authorizations_controller_spec.rb +71 -18
  97. data/spec/controllers/protected_resources_controller_spec.rb +44 -2
  98. data/spec/controllers/tokens_controller_spec.rb +11 -16
  99. data/spec/dummy/Rakefile +1 -1
  100. data/spec/dummy/app/controllers/application_controller.rb +1 -1
  101. data/spec/dummy/app/controllers/custom_authorizations_controller.rb +1 -1
  102. data/spec/dummy/app/controllers/home_controller.rb +1 -2
  103. data/spec/dummy/config/application.rb +1 -1
  104. data/spec/dummy/config/boot.rb +2 -4
  105. data/spec/dummy/config/environment.rb +1 -1
  106. data/spec/dummy/config/environments/test.rb +1 -1
  107. data/spec/dummy/config/initializers/doorkeeper.rb +2 -1
  108. data/spec/dummy/config/initializers/new_framework_defaults.rb +1 -3
  109. data/spec/dummy/config/initializers/secret_token.rb +1 -1
  110. data/spec/dummy/config.ru +1 -1
  111. data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +4 -4
  112. data/spec/dummy/db/migrate/20151223200000_add_owner_to_application.rb +1 -1
  113. data/spec/dummy/script/rails +4 -3
  114. data/spec/factories.rb +9 -9
  115. data/spec/generators/install_generator_spec.rb +4 -1
  116. data/spec/generators/templates/routes.rb +0 -1
  117. data/spec/generators/views_generator_spec.rb +1 -1
  118. data/spec/grape/grape_integration_spec.rb +1 -1
  119. data/spec/lib/config_spec.rb +109 -8
  120. data/spec/lib/doorkeeper_spec.rb +5 -5
  121. data/spec/lib/models/hashable_spec.rb +183 -0
  122. data/spec/lib/oauth/authorization_code_request_spec.rb +9 -6
  123. data/spec/lib/oauth/base_request_spec.rb +10 -10
  124. data/spec/lib/oauth/client/credentials_spec.rb +2 -2
  125. data/spec/lib/oauth/client_credentials/issuer_spec.rb +0 -2
  126. data/spec/lib/oauth/client_credentials/validation_spec.rb +5 -1
  127. data/spec/lib/oauth/client_credentials_integration_spec.rb +1 -1
  128. data/spec/lib/oauth/code_request_spec.rb +2 -2
  129. data/spec/lib/oauth/code_response_spec.rb +1 -1
  130. data/spec/lib/oauth/helpers/scope_checker_spec.rb +52 -17
  131. data/spec/lib/oauth/helpers/uri_checker_spec.rb +37 -8
  132. data/spec/lib/oauth/password_access_token_request_spec.rb +48 -15
  133. data/spec/lib/oauth/pre_authorization_spec.rb +24 -0
  134. data/spec/lib/oauth/refresh_token_request_spec.rb +11 -7
  135. data/spec/lib/oauth/token_request_spec.rb +5 -5
  136. data/spec/lib/oauth/token_response_spec.rb +13 -13
  137. data/spec/lib/oauth/token_spec.rb +18 -1
  138. data/spec/lib/server_spec.rb +6 -6
  139. data/spec/lib/{orm/active_record/stale_records_cleaner_spec.rb → stale_records_cleaner_spec.rb} +14 -4
  140. data/spec/models/doorkeeper/access_grant_spec.rb +61 -0
  141. data/spec/models/doorkeeper/access_token_spec.rb +137 -10
  142. data/spec/models/doorkeeper/application_spec.rb +41 -4
  143. data/spec/requests/applications/applications_request_spec.rb +2 -2
  144. data/spec/requests/endpoints/authorization_spec.rb +2 -2
  145. data/spec/requests/flows/authorization_code_errors_spec.rb +1 -1
  146. data/spec/requests/flows/authorization_code_spec.rb +115 -15
  147. data/spec/requests/flows/implicit_grant_errors_spec.rb +2 -2
  148. data/spec/requests/flows/password_spec.rb +10 -4
  149. data/spec/requests/flows/refresh_token_spec.rb +57 -0
  150. data/spec/requests/flows/revoke_token_spec.rb +23 -39
  151. data/spec/requests/protected_resources/private_api_spec.rb +2 -2
  152. data/spec/spec_helper.rb +2 -1
  153. data/spec/support/doorkeeper_rspec.rb +2 -1
  154. data/spec/support/helpers/model_helper.rb +8 -4
  155. data/spec/support/helpers/url_helper.rb +11 -11
  156. data/spec/support/ruby_2_6_rails_4_2_patch.rb +14 -0
  157. data/spec/support/shared/controllers_shared_context.rb +56 -0
  158. data/spec/support/shared/hashing_shared_context.rb +29 -0
  159. data/spec/validators/redirect_uri_validator_spec.rb +2 -2
  160. metadata +31 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: db3333346ca1b82cd7aa332bb1e43f8d979534c0
4
- data.tar.gz: 12511ea5d14b0bba28fef47893cc925c9e45ebcd
2
+ SHA256:
3
+ metadata.gz: 5773ab2b97881fdf1bb6fa66a4e176299d58c536f354ea9e9f4f7bb6dc0dcdea
4
+ data.tar.gz: 69ac6937d7eb7786a8c9ac331f540ef5aa1321b7c0624a0778c7437151764569
5
5
  SHA512:
6
- metadata.gz: a5265ed62b206c4f9f117c3cbc8e6d905840636297a342ea952e5dfced01f7ce4bd6b59fc7efd6a4f0e6558475c566bf59ba4a793ef3f87942cf8935dde061ba
7
- data.tar.gz: 18d2b90ae8e5f2e6e80f518fe0a251c49ba3187fda34c9213f14c0152f301dfd149d11db14dcd94a69bb8048352f8a945107c572cfb3fa03aeabc6d6383b706c
6
+ metadata.gz: 5e4b8470847ab8e642d50d27972838c0b5181b3c97c4a25afca18861b3878e513346f7b72d5c5d6c31b5d8513d90c1e6426e0cfcfce51a06b1e04e563ae09ab0
7
+ data.tar.gz: 79c4363faf9a3f41bc639ee6e6ec756efbd99a96e4670e788bc4201b6f69eb992ffc95f2f56e3efbcd5645f2ed76e2c8d29f6e9807ffb6841becd31d868c6963
data/.travis.yml CHANGED
@@ -1,5 +1,5 @@
1
- cache: bundler
2
1
  language: ruby
2
+ cache: bundler
3
3
  sudo: false
4
4
 
5
5
  rvm:
@@ -8,10 +8,12 @@ rvm:
8
8
  - 2.3
9
9
  - 2.4
10
10
  - 2.5
11
- - ruby-2.6.0-preview1
11
+ - 2.6
12
+ - ruby-head
12
13
 
13
14
  before_install:
14
- - gem update --system # Need for Ruby 2.5.0. https://github.com/travis-ci/travis-ci/issues/8978
15
+ - "find /home/travis/.rvm/rubies -wholename '*default/bundler-*.gemspec' -delete"
16
+ - rvm @global do gem uninstall bundler -a -x -I || true
15
17
  - gem install bundler -v '~> 1.10'
16
18
 
17
19
  gemfile:
@@ -23,6 +25,11 @@ gemfile:
23
25
 
24
26
  matrix:
25
27
  fast_finish: true
28
+ # Run Danger only once
29
+ include:
30
+ - rvm: 2.5
31
+ gemfile: gemfiles/rails_5_2.gemfile
32
+ script: bundle exec danger
26
33
  exclude:
27
34
  - gemfile: gemfiles/rails_5_0.gemfile
28
35
  rvm: 2.1
@@ -36,5 +43,7 @@ matrix:
36
43
  rvm: 2.2
37
44
  - gemfile: gemfiles/rails_master.gemfile
38
45
  rvm: 2.3
46
+ - gemfile: gemfiles/rails_master.gemfile
47
+ rvm: 2.4
39
48
  allow_failures:
40
49
  - gemfile: gemfiles/rails_master.gemfile
data/Dangerfile ADDED
@@ -0,0 +1,67 @@
1
+ CHANGELOG_FILE = 'NEWS.md'
2
+ GITHUB_REPO = 'https://github.com/doorkeeper-gem/doorkeeper'
3
+
4
+ def changelog_changed?
5
+ git.modified_files.include?(CHANGELOG_FILE) || git.added_files.include?(CHANGELOG_FILE)
6
+ end
7
+
8
+ def changelog_entry_example
9
+ pr_number = github.pr_json['number']
10
+ pr_title = github.pr_title
11
+ .sub(/[?.!,;]?$/, '')
12
+ .capitalize
13
+
14
+ "- [##{pr_number}]: #{pr_title}."
15
+ end
16
+
17
+ # --------------------------------------------------------------------------------------------------------------------
18
+ # Has any changes happened inside the actual library code?
19
+ # --------------------------------------------------------------------------------------------------------------------
20
+ has_app_changes = !git.modified_files.grep(/lib|app/).empty?
21
+ has_spec_changes = !git.modified_files.grep(/spec/).empty?
22
+
23
+ # --------------------------------------------------------------------------------------------------------------------
24
+ # You've made changes to lib, but didn't write any tests?
25
+ # --------------------------------------------------------------------------------------------------------------------
26
+ if has_app_changes && !has_spec_changes
27
+ warn("There're library changes, but not tests. That's OK as long as you're refactoring existing code.", sticky: false)
28
+ end
29
+
30
+ # --------------------------------------------------------------------------------------------------------------------
31
+ # You've made changes to specs, but no library code has changed?
32
+ # --------------------------------------------------------------------------------------------------------------------
33
+ if !has_app_changes && has_spec_changes
34
+ message('We really appreciate pull requests that demonstrate issues, even without a fix. That said, the next step is to try and fix the failing tests!', sticky: false)
35
+ end
36
+
37
+ # Mainly to encourage writing up some reasoning about the PR, rather than
38
+ # just leaving a title
39
+ if github.pr_body.length < 10
40
+ fail "Please provide a summary in the Pull Request description"
41
+ end
42
+
43
+ # --------------------------------------------------------------------------------------------------------------------
44
+ # Have you updated CHANGELOG.md?
45
+ # --------------------------------------------------------------------------------------------------------------------
46
+ # Add a CHANGELOG entry for app changes
47
+ if has_app_changes && !changelog_changed?
48
+ markdown <<-MARKDOWN
49
+ Here's an example of a #{CHANGELOG_FILE} entry:
50
+ ```markdown
51
+ #{changelog_entry_example}
52
+ ```
53
+ MARKDOWN
54
+
55
+ warn(
56
+ "Please include a changelog entry. \nYou can find it at [#{CHANGELOG_FILE}](#{GITHUB_REPO}/blob/master/#{CHANGELOG_FILE})." +
57
+ "You can skip this warning only if you made some typo fix or other small changes that didn't affect the API."
58
+ )
59
+ end
60
+
61
+ if git.commits.any? { |commit| commit.message =~ /^Merge branch '#{github.branch_for_base}'/ }
62
+ warn('Please rebase to get rid of the merge commits in this PR')
63
+ end
64
+
65
+ if git.commits.length > 1
66
+ warn('Please squash all your commits to a single one')
67
+ end
data/Gemfile CHANGED
@@ -1,9 +1,11 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem "rails", "~> 5.2"
3
+ gem "rails", ">= 5.2.1.1", "< 6.0"
4
4
 
5
5
  gem "appraisal"
6
6
 
7
+ gem "bcrypt", "~> 3.1"
8
+
7
9
  gem "activerecord-jdbcsqlite3-adapter", platform: :jruby
8
10
  gem "sqlite3", platform: [:ruby, :mswin, :mingw, :x64_mingw]
9
11
  gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw]
data/NEWS.md CHANGED
@@ -7,7 +7,30 @@ User-visible changes worth mentioning.
7
7
 
8
8
  ## master
9
9
 
10
- - [#PR ID] Add PR description.
10
+ - [#1188] Use `params` instead of `request.POST` in tokens controller (fixes #1183).
11
+ - [#1179] Authorization Code Grant Flow without client id returns invalid_client error.
12
+ - [#1182] Fix loopback IP redirect URIs to conform with RFC8252, p. 7.3 (fixes #1170).
13
+ - [#1177] Allow to limit `scopes` for certain `grant_types`
14
+ - [#1162] Fix `enforce_content_type` for requests without body.
15
+ - [#1164] Fix error when `root_path` is not defined.
16
+ - [#1175] Internal refactor: use `scopes_string` inside `scopes`.
17
+ - [#1176] Fix test factory support for `factory_bot_rails`
18
+ - [#1168]: Allow optional hashing of tokens and secrets.
19
+
20
+ ## 5.0.2
21
+
22
+ - [#1158] Fix initializer template: change `handle_auth_errors` option
23
+ - [#1157] Remove redundant index from migration template.
24
+
25
+ ## 5.0.1
26
+
27
+ - [#1140] Allow rendering custom errors from exceptions (issue #844). Originally opened as [#944].
28
+ - [#1138] Revert regression bug (check for token expiration in Authorizations controller so authorization
29
+ triggers every time)
30
+ - [#1149] Fix for `URIChecker#valid_for_authorization?` false negative when query is blank, but `?` present.
31
+ - [#1151] Fix Refresh Token strategy: add proper validation of client credentials both for Public & Private clients.
32
+ - [#1152] Fix migration template: change resource owner data type from integer to Rails generic `references`
33
+ - [#1154] Refactor `StaleRecordsCleaner` to be ORM agnostic.
11
34
 
12
35
  ## 5.0.0
13
36
 
@@ -43,6 +66,12 @@ User-visible changes worth mentioning.
43
66
  `Doorkeeper#installed?` method
44
67
  - [#1031] Allow public clients to authenticate without `client_secret`. Define an app as
45
68
  either public or private/confidential
69
+
70
+ **[IMPORTANT]**: all the applications (clients) now are considered as private by default.
71
+ You need to manually change `confidential` column to `false` if you are using public clients,
72
+ in other case your mobile (or other) applications will not be able to authorize.
73
+ See [#1142](https://github.com/doorkeeper-gem/doorkeeper/issues/1142) for more details.
74
+
46
75
  - [#1010] Add configuration to enforce configured scopes (`default_scopes` and
47
76
  `optional_scopes`) for applications
48
77
  - [#1060] Ensure that the native redirect_uri parameter matches with redirect_uri of the client
@@ -60,20 +89,31 @@ User-visible changes worth mentioning.
60
89
  - [#1076] Add config to enforce content type to application/x-www-form-urlencoded
61
90
  - Fix bug with `force_ssl_in_redirect_uri` when it breaks existing applications with an
62
91
  SSL redirect_uri.
63
-
92
+
93
+ ## 4.4.3
94
+
95
+ - [#1143] Adds a config option `opt_out_native_route_change` to opt out of the breaking api
96
+ changed introduced in https://github.com/doorkeeper-gem/doorkeeper/pull/1003
97
+
98
+
64
99
  ## 4.4.2
65
100
 
66
101
  - [#1130] Backport fix for native redirect_uri from 5.x.
67
-
102
+
68
103
  ## 4.4.1
69
104
 
70
105
  - [#1127] Backport token type to comply with the RFC6750 specification.
71
106
  - [#1125] Backport Quote surround I18n yes/no keys
72
-
107
+
73
108
  ## 4.4.0
74
-
109
+
75
110
  - [#1120] Backport security fix from 5.x for token revocation when using public clients
76
111
 
112
+ **[IMPORTANT]**: all the applications (clients) now are considered as private by default.
113
+ You need to manually change `confidential` column to `false` if you are using public clients,
114
+ in other case your mobile (or other) applications will not be able to authorize.
115
+ See [#1142](https://github.com/doorkeeper-gem/doorkeeper/issues/1142) for more details.
116
+
77
117
  ## 4.3.2
78
118
 
79
119
  - [#1053] Support authorizing with query params in the request `redirect_uri` if explicitly present in app's `Application#redirect_uri`
@@ -101,6 +141,10 @@ User-visible changes worth mentioning.
101
141
  - [#985] Generate valid migration files for Rails >= 5
102
142
  - [#972] Replace Struct subclassing with block-form initialization
103
143
  - [#1003] Use URL query param to pass through native redirect auth code so automated apps can find it.
144
+
145
+ **[IMPORTANT]**: Previously authorization code response route was `/oauth/authorize/<code>`,
146
+ now it is `oauth/authorize/native?code=<code>` (in order to help applications to automatically find the code value).
147
+
104
148
  - [#868] `Scopes#&` and `Scopes#+` now take an array or any other enumerable
105
149
  object.
106
150
  - [#1019] Remove translation not in use: `invalid_resource_owner`.
data/README.md CHANGED
@@ -23,6 +23,9 @@ Supported features:
23
23
  - [OAuth 2.0 Token Revocation](http://tools.ietf.org/html/rfc7009)
24
24
  - [OAuth 2.0 Token Introspection](https://tools.ietf.org/html/rfc7662)
25
25
 
26
+ See [list of tutorials](https://github.com/doorkeeper-gem/doorkeeper/wiki#how-tos--tutorials) in order to
27
+ learn how to use the gem or integrate it with other solutions / gems.
28
+
26
29
  ## Documentation valid for `master` branch
27
30
 
28
31
  Please check the documentation for the version of doorkeeper you are using in:
@@ -50,6 +53,7 @@ https://github.com/doorkeeper-gem/doorkeeper/releases
50
53
  - [Routes](#routes)
51
54
  - [Authenticating](#authenticating)
52
55
  - [Internationalization (I18n)](#internationalization-i18n)
56
+ - [Customizing errors](#customizing-errors)
53
57
  - [Rake Tasks](#rake-tasks)
54
58
  - [Protecting resources with OAuth (a.k.a your API endpoint)](#protecting-resources-with-oauth-aka-your-api-endpoint)
55
59
  - [Ruby on Rails controllers](#ruby-on-rails-controllers)
@@ -113,7 +117,7 @@ migration:
113
117
  [PKCE flow]: https://tools.ietf.org/html/rfc7636
114
118
 
115
119
  ```sh
116
- rails generate doorkeeper:pkce
120
+ rails generate doorkeeper:pkce
117
121
  ```
118
122
 
119
123
  Then run migrations:
@@ -237,6 +241,14 @@ You may want to check other ways of authentication
237
241
  Doorkeeper support multiple languages. See language files in
238
242
  [the I18n repository](https://github.com/doorkeeper-gem/doorkeeper-i18n).
239
243
 
244
+ ### Customizing errors
245
+
246
+ If you don't want to use default Doorkeeper error responses you can raise and rescue it's
247
+ exceptions. All you need is to set configuration option `handle_auth_errors` to `:raise`.
248
+ In this case Doorkeeper will raise `Doorkeeper::Errors::TokenForbidden`,
249
+ `Doorkeeper::Errors::TokenExpired`, `Doorkeeper::Errors::TokenRevoked` or other exceptions
250
+ that you need to care about.
251
+
240
252
  ### Rake Tasks
241
253
 
242
254
  If you are using `rake`, you can load rake tasks provided by this gem, by adding
@@ -372,7 +384,7 @@ end
372
384
  Please note that there is a logical OR between multiple required scopes. In the
373
385
  above example, `doorkeeper_authorize! :admin, :write` means that the access
374
386
  token is required to have either `:admin` scope or `:write` scope, but does not
375
- need have both of them.
387
+ need to have both of them.
376
388
 
377
389
  If you want to require the access token to have multiple scopes at the same
378
390
  time, use multiple `doorkeeper_authorize!`, for example:
@@ -448,8 +460,11 @@ token owner.
448
460
 
449
461
  ### Applications list
450
462
 
451
- By default, the applications list (`/oauth/applications`) is publicly available.
452
- To protect the endpoint you should uncomment these lines:
463
+ By default, the applications list (`/oauth/applications`) is publicly available (before 5.0 release).
464
+ Starting from Doorkeeper 5.0 it returns 403 Forbidden if `admin_authenticator` option is not configured
465
+ by developers.
466
+
467
+ To change the protection rules of this endpoint you should uncomment these lines:
453
468
 
454
469
  ```ruby
455
470
  # config/initializers/doorkeeper.rb
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  class ApplicationController <
3
5
  Doorkeeper.configuration.base_controller.constantize
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  class ApplicationMetalController < ActionController::Metal
3
5
  MODULES = [
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  class ApplicationsController < Doorkeeper::ApplicationController
3
5
  layout 'doorkeeper/admin' unless Doorkeeper.configuration.api_only
@@ -77,8 +79,8 @@ module Doorkeeper
77
79
  end
78
80
 
79
81
  def application_params
80
- params.require(:doorkeeper_application).
81
- permit(:name, :redirect_uri, :scopes, :confidential)
82
+ params.require(:doorkeeper_application)
83
+ .permit(:name, :redirect_uri, :scopes, :confidential)
82
84
  end
83
85
  end
84
86
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  class AuthorizationsController < Doorkeeper::ApplicationController
3
5
  before_action :authenticate_resource_owner!
@@ -41,13 +43,11 @@ module Doorkeeper
41
43
  end
42
44
 
43
45
  def matching_token?
44
- token = AccessToken.matching_token_for(
46
+ AccessToken.matching_token_for(
45
47
  pre_auth.client,
46
48
  current_resource_owner.id,
47
49
  pre_auth.scopes
48
50
  )
49
-
50
- token && token.accessible?
51
51
  end
52
52
 
53
53
  def redirect_or_render(auth)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  class AuthorizedApplicationsController < Doorkeeper::ApplicationController
3
5
  before_action :authenticate_resource_owner!
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  class TokenInfoController < Doorkeeper::ApplicationMetalController
3
5
  def show
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  class TokensController < Doorkeeper::ApplicationMetalController
3
5
  def create
4
6
  response = authorize_response
5
- headers.merge! response.headers
7
+ headers.merge!(response.headers)
6
8
  self.response_body = response.body.to_json
7
9
  self.status = response.status
8
- rescue Errors::DoorkeeperError => e
9
- handle_token_exception e
10
+ rescue Errors::DoorkeeperError => error
11
+ handle_token_exception(error)
10
12
  end
11
13
 
12
14
  # OAuth 2.0 Token Revocation - http://tools.ietf.org/html/rfc7009
@@ -73,12 +75,12 @@ module Doorkeeper
73
75
  end
74
76
 
75
77
  def token
76
- @token ||= AccessToken.by_token(request.POST['token']) ||
77
- AccessToken.by_refresh_token(request.POST['token'])
78
+ @token ||= AccessToken.by_token(params['token']) ||
79
+ AccessToken.by_refresh_token(params['token'])
78
80
  end
79
81
 
80
82
  def strategy
81
- @strategy ||= server.token_request params[:grant_type]
83
+ @strategy ||= server.token_request(params[:grant_type])
82
84
  end
83
85
 
84
86
  def authorize_response
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  module DashboardHelper
3
5
  def doorkeeper_errors_for(object, method)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'uri'
2
4
 
3
5
  class RedirectUriValidator < ActiveModel::EachValidator
@@ -8,7 +8,7 @@
8
8
  <p><code class="bg-light" id="application_id"><%= @application.uid %></code></p>
9
9
 
10
10
  <h4><%= t('.secret') %>:</h4>
11
- <p><code class="bg-light" id="secret"><%= @application.secret %></code></p>
11
+ <p><code class="bg-light" id="secret"><%= @application.plaintext_secret %></code></p>
12
12
 
13
13
  <h4><%= t('.scopes') %>:</h4>
14
14
  <p><code class="bg-light" id="scopes"><%= @application.scopes.presence || raw('&nbsp;') %></code></p>
@@ -17,9 +17,11 @@
17
17
  <li class="nav-item <%= 'active' if request.path == oauth_applications_path %>">
18
18
  <%= link_to t('doorkeeper.layouts.admin.nav.applications'), oauth_applications_path, class: 'nav-link' %>
19
19
  </li>
20
- <li class="nav-item">
21
- <%= link_to t('doorkeeper.layouts.admin.nav.home'), root_path, class: 'nav-link' %>
22
- </li>
20
+ <% if respond_to?(:root_path) %>
21
+ <li class="nav-item">
22
+ <%= link_to t('doorkeeper.layouts.admin.nav.home'), root_path, class: 'nav-link' %>
23
+ </li>
24
+ <% end %>
23
25
  </ul>
24
26
  </div>
25
27
  </nav>
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'rails/all'
5
+ require 'doorkeeper'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/doorkeeper.gemspec CHANGED
@@ -2,29 +2,30 @@ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
2
2
 
3
3
  require 'doorkeeper/version'
4
4
 
5
- Gem::Specification.new do |s|
6
- s.name = 'doorkeeper'
7
- s.version = Doorkeeper.gem_version
8
- s.authors = ['Felipe Elias Philipp', 'Tute Costa', 'Jon Moss', 'Nikita Bulai']
9
- s.email = %w(bulaj.nikita@gmail.com)
10
- s.homepage = 'https://github.com/doorkeeper-gem/doorkeeper'
11
- s.summary = 'OAuth 2 provider for Rails and Grape'
12
- s.description = 'Doorkeeper is an OAuth 2 provider for Rails and Grape.'
13
- s.license = 'MIT'
5
+ Gem::Specification.new do |gem|
6
+ gem.name = 'doorkeeper'
7
+ gem.version = Doorkeeper.gem_version
8
+ gem.authors = ['Felipe Elias Philipp', 'Tute Costa', 'Jon Moss', 'Nikita Bulai']
9
+ gem.email = %w(bulaj.nikita@gmail.com)
10
+ gem.homepage = 'https://github.com/doorkeeper-gem/doorkeeper'
11
+ gem.summary = 'OAuth 2 provider for Rails and Grape'
12
+ gem.description = 'Doorkeeper is an OAuth 2 provider for Rails and Grape.'
13
+ gem.license = 'MIT'
14
14
 
15
- s.files = `git ls-files`.split("\n")
16
- s.test_files = `git ls-files -- spec/*`.split("\n")
17
- s.require_paths = ['lib']
15
+ gem.files = `git ls-files`.split("\n")
16
+ gem.test_files = `git ls-files -- spec/*`.split("\n")
17
+ gem.require_paths = ['lib']
18
18
 
19
- s.add_dependency 'railties', '>= 4.2'
20
- s.required_ruby_version = '>= 2.1'
19
+ gem.add_dependency 'railties', '>= 4.2'
20
+ gem.required_ruby_version = '>= 2.1'
21
21
 
22
- s.add_development_dependency 'capybara', '~> 2.18'
23
- s.add_development_dependency 'coveralls'
24
- s.add_development_dependency 'grape'
25
- s.add_development_dependency 'database_cleaner', '~> 1.6'
26
- s.add_development_dependency 'factory_bot', '~> 4.8'
27
- s.add_development_dependency 'generator_spec', '~> 0.9.3'
28
- s.add_development_dependency 'rake', '>= 11.3.0'
29
- s.add_development_dependency 'rspec-rails'
22
+ gem.add_development_dependency 'capybara', '~> 2.18'
23
+ gem.add_development_dependency 'coveralls'
24
+ gem.add_development_dependency 'danger', '~> 5.0'
25
+ gem.add_development_dependency 'grape'
26
+ gem.add_development_dependency 'database_cleaner', '~> 1.6'
27
+ gem.add_development_dependency 'factory_bot', '~> 4.8'
28
+ gem.add_development_dependency 'generator_spec', '~> 0.9.3'
29
+ gem.add_development_dependency 'rake', '>= 11.3.0'
30
+ gem.add_development_dependency 'rspec-rails'
30
31
  end
@@ -3,6 +3,7 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 4.2.0"
6
+ gem "bcrypt", "~> 3.1"
6
7
  gem "appraisal"
7
8
  gem "activerecord-jdbcsqlite3-adapter", platform: :jruby
8
9
  gem "sqlite3", platform: [:ruby, :mswin, :mingw, :x64_mingw]
@@ -3,6 +3,7 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 5.0.0"
6
+ gem "bcrypt", "~> 3.1"
6
7
  gem "appraisal"
7
8
  gem "activerecord-jdbcsqlite3-adapter", platforms: :jruby
8
9
  gem "sqlite3", platforms: [:ruby, :mswin, :mingw, :x64_mingw]
@@ -3,6 +3,7 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 5.1.0"
6
+ gem "bcrypt", "~> 3.1"
6
7
  gem "appraisal"
7
8
  gem "activerecord-jdbcsqlite3-adapter", platforms: :jruby
8
9
  gem "sqlite3", platforms: [:ruby, :mswin, :mingw, :x64_mingw]
@@ -2,7 +2,8 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "5.2.0"
5
+ gem "rails", "~> 5.2.0"
6
+ gem "bcrypt", "~> 3.1"
6
7
  gem "appraisal"
7
8
  gem "activerecord-jdbcsqlite3-adapter", platforms: :jruby
8
9
  gem "sqlite3", platforms: [:ruby, :mswin, :mingw, :x64_mingw]
@@ -6,6 +6,7 @@ gem "rails", git: 'https://github.com/rails/rails'
6
6
  gem "arel", git: 'https://github.com/rails/arel'
7
7
 
8
8
  gem "appraisal"
9
+ gem "bcrypt", "~> 3.1"
9
10
  gem "activerecord-jdbcsqlite3-adapter", platform: :jruby
10
11
  gem "sqlite3", platform: [:ruby, :mswin, :mingw, :x64_mingw]
11
12
  gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw]