doorkeeper 5.5.4 → 5.8.1

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 (56) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +111 -8
  3. data/README.md +5 -9
  4. data/app/controllers/doorkeeper/authorizations_controller.rb +34 -11
  5. data/app/controllers/doorkeeper/tokens_controller.rb +28 -6
  6. data/app/views/doorkeeper/authorizations/error.html.erb +3 -1
  7. data/app/views/doorkeeper/authorizations/form_post.html.erb +1 -1
  8. data/app/views/doorkeeper/authorizations/new.html.erb +16 -16
  9. data/config/locales/en.yml +4 -1
  10. data/lib/doorkeeper/config/abstract_builder.rb +1 -1
  11. data/lib/doorkeeper/config/validations.rb +15 -3
  12. data/lib/doorkeeper/config.rb +95 -55
  13. data/lib/doorkeeper/engine.rb +10 -3
  14. data/lib/doorkeeper/errors.rb +32 -0
  15. data/lib/doorkeeper/helpers/controller.rb +1 -1
  16. data/lib/doorkeeper/models/access_token_mixin.rb +71 -9
  17. data/lib/doorkeeper/models/concerns/expiration_time_sql_math.rb +88 -0
  18. data/lib/doorkeeper/models/concerns/polymorphic_resource_owner.rb +30 -0
  19. data/lib/doorkeeper/oauth/authorization/code.rb +7 -1
  20. data/lib/doorkeeper/oauth/authorization/token.rb +7 -1
  21. data/lib/doorkeeper/oauth/authorization_code_request.rb +36 -12
  22. data/lib/doorkeeper/oauth/base_request.rb +14 -12
  23. data/lib/doorkeeper/oauth/client.rb +1 -1
  24. data/lib/doorkeeper/oauth/client_credentials/creator.rb +13 -13
  25. data/lib/doorkeeper/oauth/client_credentials/issuer.rb +5 -4
  26. data/lib/doorkeeper/oauth/client_credentials/validator.rb +4 -5
  27. data/lib/doorkeeper/oauth/client_credentials_request.rb +10 -2
  28. data/lib/doorkeeper/oauth/code_request.rb +1 -1
  29. data/lib/doorkeeper/oauth/error.rb +4 -3
  30. data/lib/doorkeeper/oauth/error_response.rb +19 -4
  31. data/lib/doorkeeper/oauth/helpers/uri_checker.rb +4 -4
  32. data/lib/doorkeeper/oauth/invalid_request_response.rb +4 -0
  33. data/lib/doorkeeper/oauth/password_access_token_request.rb +6 -6
  34. data/lib/doorkeeper/oauth/pre_authorization.rb +31 -23
  35. data/lib/doorkeeper/oauth/refresh_token_request.rb +17 -9
  36. data/lib/doorkeeper/oauth/scopes.rb +55 -1
  37. data/lib/doorkeeper/oauth/token_introspection.rb +34 -20
  38. data/lib/doorkeeper/oauth/token_request.rb +1 -1
  39. data/lib/doorkeeper/oauth/token_response.rb +5 -3
  40. data/lib/doorkeeper/orm/active_record/mixins/access_grant.rb +0 -6
  41. data/lib/doorkeeper/orm/active_record/mixins/access_token.rb +21 -4
  42. data/lib/doorkeeper/orm/active_record/mixins/application.rb +22 -4
  43. data/lib/doorkeeper/orm/active_record/redirect_uri_validator.rb +2 -2
  44. data/lib/doorkeeper/orm/active_record/stale_records_cleaner.rb +5 -2
  45. data/lib/doorkeeper/orm/active_record.rb +30 -37
  46. data/lib/doorkeeper/rails/routes.rb +12 -3
  47. data/lib/doorkeeper/rake/setup.rake +0 -5
  48. data/lib/doorkeeper/revocable_tokens/revocable_access_token.rb +21 -0
  49. data/lib/doorkeeper/revocable_tokens/revocable_refresh_token.rb +21 -0
  50. data/lib/doorkeeper/version.rb +2 -2
  51. data/lib/doorkeeper.rb +78 -5
  52. data/lib/generators/doorkeeper/remove_applications_secret_not_null_constraint_generator.rb +33 -0
  53. data/lib/generators/doorkeeper/templates/initializer.rb +44 -6
  54. data/lib/generators/doorkeeper/templates/migration.rb.erb +15 -4
  55. data/lib/generators/doorkeeper/templates/remove_applications_secret_not_null_constraint.rb.erb +7 -0
  56. metadata +28 -21
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 55c17555b9591b1a06b8164b0508ab733df8dca59e4b555e1dac3b3cc7a1112e
4
- data.tar.gz: 56fd2b8475c97f0bc755086cc22ee1aa14d2ac47263f0e218f3cf4f9f80d5b38
3
+ metadata.gz: 8364fc5d75f9cbe96cc3ef67c8010dde471eb51ced0cf328f9ca84705553976f
4
+ data.tar.gz: db817023f41b070185ae9d6fae32b9d9b0eb0fc7abf8bdd99961c80e8bece1dd
5
5
  SHA512:
6
- metadata.gz: b21d497b70266436f0446eec977f9ff074f646c0cdf417e08c8806529474ea91d112f0f1357a614f9e136b0dd042d665f7ea7325740254770ff01469df595390
7
- data.tar.gz: eb23ac65993cf89d82b66e5616b231d58fd0ac928486354a2bc36fdf7173fb3ba807f434f85a45f4ea6d1600847b46bdd5ad76ea9d317c16908a114b18fdb94a
6
+ metadata.gz: 940f6253760d9117390495e97fa270aa0337a7379d2070d2be5ce2a44cf8148f451ffe7a3ba0451ab88d1cbb5bd4242f6d4a7de90204cf2749a57bdeaa4005ed
7
+ data.tar.gz: 728ea65c1e37f7f77183e5528c441cf7b9c8a4493428bbafbfe7815dec4b227d8bd033e05c4ee2dde50b9cc252cad7241b5d287d2df28e6631f9ccada5c7afc5
data/CHANGELOG.md CHANGED
@@ -7,7 +7,110 @@ User-visible changes worth mentioning.
7
7
 
8
8
  ## main
9
9
 
10
- - [#ID] Add your PR description here.
10
+ Add your entry here.
11
+
12
+ ## 5.8.1
13
+
14
+ - [#1752] Bump the range of supported Ruby and Rails versions
15
+ - [#1747] Fix unknown pkce method error when configured
16
+ - [#1744] Allow for expired refresh tokens to be revoked
17
+ - [#1754] Fix refresh tokens with dynamic scopes
18
+
19
+ ## 5.8.0
20
+
21
+ - [#1739] Add support for dynamic scopes
22
+ - [#1715] Fix token introspection invalid request reason
23
+ - [#1714] Fix `Doorkeeper::AccessToken.find_or_create_for` with empty scopes which raises NoMethodError
24
+ - [#1712] Add `Pragma: no-cache` to token response
25
+ - [#1726] Refactor token introspection class.
26
+ - [#1727] Allow to set null secret value for Applications if they are public.
27
+ - [#1735] Add `pkce_code_challenge_methods` config option.
28
+
29
+ ## 5.7.1
30
+
31
+ - [#1705] Add `force_pkce` option that requires non-confidential clients to use PKCE when requesting an access_token using an authorization code
32
+
33
+ ## 5.7.0
34
+
35
+ - [#1696] Add missing `#issued_token` method to `OAuth::TokenResponse`
36
+ - [#1697] Allow a TokenResponse body to be customized (memoize response body).
37
+ - [#1702] Fix bugs for error response in the form_post and error view
38
+ - [#1660] Custom access token attributes are now considered when finding matching tokens (fixes #1665).
39
+ Introduce `revoke_previous_client_credentials_token` configuration option.
40
+
41
+ ## 5.6.9
42
+
43
+ - [#1691] Make new Doorkeeper errors backward compatible with older extensions.
44
+
45
+ ## 5.6.8
46
+
47
+ - [#1680] Fix handle_auth_errors :raise NotImplementedError
48
+
49
+ ## 5.6.7
50
+
51
+ - [#1662] Specify uri_redirect validation class explicitly.
52
+ - [#1652] Add custom attributes support to token generator.
53
+ - [#1667] Pass `client` instead of `grant.application` to `find_or_create_access_token`.
54
+ - [#1673] Honor `custom_access_token_attributes` in client credentials grant flow.
55
+ - [#1676] Improve AuthorizationsController error response handling
56
+ - [#1677] Fix URIHelper.valid_for_authorization? breaking for non url URIs.
57
+
58
+ ## 5.6.6
59
+
60
+ - [#1644] Update HTTP headers.
61
+ - [#1646] Block public clients automatic authorization skip.
62
+ - [#1648] Add custom token attributes to Refresh Token Request.
63
+ - [#1649] Fixed custom_access_token_attributes related errors.
64
+
65
+ ## 5.6.5
66
+
67
+ - [#1602] Allow custom data to be stored inside access grants/tokens.
68
+ - [#1634] Code refactoring for custom token attributes.
69
+ - [#1639] Add grant type validation to avoid Internal Server Error for DELETE /oauth/authorize endpoint.
70
+
71
+ ## 5.6.4
72
+
73
+ - [#1633] Apply ORM configuration in #to_prepare block to avoid autoloading errors.
74
+
75
+ ## 5.6.3
76
+
77
+ - [#1622] Drop support for Rubies 2.5 and 2.6
78
+ - [#1605] Fix URI validation for Ruby 3.2+.
79
+ - [#1625] Exclude endless access tokens from `StaleRecordsCleaner`.
80
+ - [#1626] Remove deprecated `active_record_options` config option.
81
+ - [#1631] Fix regression with redirect behavior after token lookup optimizations (redirect to app URI when found).
82
+ - [#1630] Special case unique index creation for refresh_token on SQL Server.
83
+ - [#1627] Lazy evaluate Doorkeeper config when loading files and executing initializers.
84
+
85
+ ## 5.6.2
86
+
87
+ - [#1604] Fix fetching of the application when custom application_class defined.
88
+
89
+ ## 5.6.1
90
+
91
+ - [#1593] Add support for Trilogy ActiveRecord adapter.
92
+ - [#1597] Add optional support to use the url path for the native authorization code flow. Ports forward [#1143] from 4.4.3
93
+ - [#1599] Remove unnecessarily re-fetch of application object when creating an access token.
94
+
95
+ ## 5.6.0
96
+
97
+ - [#1581] Consider `token_type_hint` when searching for access token in TokensController to avoid extra database calls.
98
+
99
+ ## 5.6.0.rc2
100
+
101
+ - [#1558] Fixed bug: able to obtain a token with default scopes even if they are not present in the
102
+ application scopes when using client credentials.
103
+ - [#1567] Only filter `code` parameter if authorization_code grant flow is enabled.
104
+
105
+ ## 5.6.0.rc1
106
+
107
+ - [#1551] Change lazy loading for ORM to be Ruby standard autoload.
108
+ - [#1552] Remove duplicate IDs on Auth form to improve accessibility.
109
+ - [#1542] Improve performance of `Doorkeeper::AccessToken#matching_token_for` using database specific SQL time math.
110
+
111
+ **[IMPORTANT]**: API of the `Doorkeeper::AccessToken#matching_token_for` method has changed and now it returns
112
+ only **active** access tokens (previously they were just not revoked). Please remember that the idea of the
113
+ `reuse_access_token` option is to check for existing _active_ token (see configuration option description).
11
114
 
12
115
  ## 5.5.4
13
116
 
@@ -25,12 +128,12 @@ User-visible changes worth mentioning.
25
128
  - [#1502] Drop support for Ruby 2.4 because of EOL.
26
129
  - [#1504] Updated the url fragment in the comment for code documentation.
27
130
  - [#1512] Fix form behavior when response mode is form_post.
28
- - [#1511] Fix that authorization code is returned by fragment if response_mode is fragament.
131
+ - [#1511] Fix that authorization code is returned by fragment if response_mode is fragment.
29
132
 
30
133
  ## 5.5.1
31
134
 
32
135
  - [#1496] Revoke `old_refresh_token` if `previous_refresh_token` is present.
33
- - [#1495] Fix `respond_to` undefined in API-only mode
136
+ - [#1495] Fix `respond_to` undefined in API-only mode
34
137
  - [#1488] Verify client authentication for Resource Owner Password Grant when
35
138
  `config.skip_client_authentication_for_password_grant` is set and the client credentials
36
139
  are sent in a HTTP Basic auth header.
@@ -44,10 +147,10 @@ User-visible changes worth mentioning.
44
147
  ## 5.5.0.rc2
45
148
 
46
149
  - [#1473] Enable `Applications` and `AuthorizedApplications` controllers in API mode.
47
-
48
- **[IMPORTANT]** you can still skip these controllers using `skip_controllers` in
150
+
151
+ **[IMPORTANT]** you can still skip these controllers using `skip_controllers` in
49
152
  `use_doorkeeper` inside `routes.rb`. Please do it in case you don't need them.
50
-
153
+
51
154
  - [#1472] Fix `establish_connection` configuration for custom defined models.
52
155
  - [#1471] Add support for Ruby 3.0.
53
156
  - [#1469] Check if `redirect_uri` exists.
@@ -254,7 +357,7 @@ User-visible changes worth mentioning.
254
357
  - [#1237] Allow to set blank redirect URI if Doorkeeper configured to use redirect URI-less grant flows.
255
358
  - [#1234] Fix `StaleRecordsCleaner` to properly work with big amount of records.
256
359
  - [#1228] Allow to explicitly set non-expiring tokens in `custom_access_token_expires_in` configuration
257
- option using `Float::INIFINITY` return value.
360
+ option using `Float::INFINITY` return value.
258
361
  - [#1224] Do not try to store token if not found by fallback hashing strategy.
259
362
  - [#1223] Update Hound/Rubocop rules, correct Doorkeeper codebase to follow style-guides.
260
363
  - [#1220] Drop Rails 4.2 & Ruby < 2.4 support.
@@ -339,7 +442,7 @@ User-visible changes worth mentioning.
339
442
  - [#1116] `AccessGrant`s will now be revoked along with `AccessToken`s when
340
443
  hitting the `AuthorizedApplicationController#destroy` route.
341
444
  - [#1114] Make token info endpoint's attributes consistent with token creation
342
- - [#1108] Simple formating of callback URLs when listing oauth applications
445
+ - [#1108] Simple formatting of callback URLs when listing oauth applications
343
446
  - [#1106] Restrict access to AdminController with 'Forbidden 403' if admin_authenticator is not
344
447
  configured by developers.
345
448
 
data/README.md CHANGED
@@ -1,10 +1,9 @@
1
1
  # Doorkeeper — awesome OAuth 2 provider for your Rails / Grape app.
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/doorkeeper.svg)](https://rubygems.org/gems/doorkeeper)
4
- [![Build Status](https://app.travis-ci.com/doorkeeper-gem/doorkeeper.svg?branch=main)](https://app.travis-ci.com/doorkeeper-gem/doorkeeper)
4
+ [![CI](https://github.com/doorkeeper-gem/doorkeeper/actions/workflows/ci.yml/badge.svg)](https://github.com/doorkeeper-gem/doorkeeper/actions/workflows/ci.yml)
5
5
  [![Code Climate](https://codeclimate.com/github/doorkeeper-gem/doorkeeper.svg)](https://codeclimate.com/github/doorkeeper-gem/doorkeeper)
6
6
  [![Coverage Status](https://coveralls.io/repos/github/doorkeeper-gem/doorkeeper/badge.svg?branch=main)](https://coveralls.io/github/doorkeeper-gem/doorkeeper?branch=main)
7
- [![Security](https://hakiri.io/github/doorkeeper-gem/doorkeeper/main.svg)](https://hakiri.io/github/doorkeeper-gem/doorkeeper/main)
8
7
  [![Reviewed by Hound](https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg)](https://houndci.com)
9
8
  [![GuardRails badge](https://badges.guardrails.io/doorkeeper-gem/doorkeeper.svg?token=66768ce8f6995814df81f65a2cff40f739f688492704f973e62809e15599bb62)](https://dashboard.guardrails.io/default/gh/doorkeeper-gem/doorkeeper)
10
9
  [![Dependabot](https://img.shields.io/badge/dependabot-enabled-success.svg)](https://dependabot.com)
@@ -40,7 +39,6 @@ Supported features:
40
39
  - [ORMs](#orms)
41
40
  - [Extensions](#extensions)
42
41
  - [Example Applications](#example-applications)
43
- - [Tutorials](#tutorials)
44
42
  - [Sponsors](#sponsors)
45
43
  - [Development](#development)
46
44
  - [Contributing](#contributing)
@@ -57,7 +55,7 @@ https://github.com/doorkeeper-gem/doorkeeper/releases.
57
55
  Additionally, other resources can be found on:
58
56
 
59
57
  - [Guides](https://doorkeeper.gitbook.io/guides/) with how-to get started and configuration documentation
60
- - See the [Wiki](https://github.com/doorkeeper-gem/doorkeeper/wiki) with articles and other documentation
58
+ - See the [Wiki](https://github.com/doorkeeper-gem/doorkeeper/wiki) for articles on how to integrate with other solutions
61
59
  - Screencast from [railscasts.com](http://railscasts.com/): [#353
62
60
  OAuth with
63
61
  Doorkeeper](http://railscasts.com/episodes/353-oauth-with-doorkeeper)
@@ -106,6 +104,8 @@ Extensions that are not included by default and can be installed separately.
106
104
  | JWT Token support | [doorkeeper-gem/doorkeeper-jwt](https://github.com/doorkeeper-gem/doorkeeper-jwt) |
107
105
  | Assertion grant extension | [doorkeeper-gem/doorkeeper-grants\_assertion](https://github.com/doorkeeper-gem/doorkeeper-grants_assertion) |
108
106
  | I18n translations | [doorkeeper-gem/doorkeeper-i18n](https://github.com/doorkeeper-gem/doorkeeper-i18n) |
107
+ | CIBA - Client Initiated Backchannel Authentication Flow extension | [doorkeeper-ciba](https://github.com/autoseg/doorkeeper-ciba) |
108
+ | Device Authorization Grant | [doorkeeper-device_authorization_grant](https://github.com/exop-group/doorkeeper-device_authorization_grant) |
109
109
 
110
110
  ## Example Applications
111
111
 
@@ -123,10 +123,6 @@ examples](https://github.com/doorkeeper-gem/doorkeeper/wiki/Example-Applications
123
123
  in our wiki or follow this [tutorial
124
124
  here](https://github.com/doorkeeper-gem/doorkeeper/wiki/Testing-your-provider-with-OAuth2-gem).
125
125
 
126
- ## Tutorials
127
-
128
- See [list of tutorials](https://github.com/doorkeeper-gem/doorkeeper/wiki#how-tos--tutorials) in order to learn how to use the gem or integrate it with other solutions / gems.
129
-
130
126
  ## Sponsors
131
127
 
132
128
  [![OpenCollective](https://opencollective.com/doorkeeper-gem/backers/badge.svg)](#backers)
@@ -188,4 +184,4 @@ contributors](https://github.com/doorkeeper-gem/doorkeeper/graphs/contributors)!
188
184
 
189
185
  ## License
190
186
 
191
- MIT License. Copyright 2011 Applicake.
187
+ MIT License. Created in Applicake. Maintained by the community.
@@ -13,18 +13,26 @@ module Doorkeeper
13
13
  end
14
14
 
15
15
  def create
16
- redirect_or_render authorize_response
16
+ redirect_or_render(authorize_response)
17
17
  end
18
18
 
19
19
  def destroy
20
- redirect_or_render authorization.deny
20
+ redirect_or_render(authorization.deny)
21
+ rescue Doorkeeper::Errors::InvalidTokenStrategy => e
22
+ error_response = get_error_response_from_exception(e)
23
+
24
+ if Doorkeeper.configuration.api_only
25
+ render json: error_response.body, status: :bad_request
26
+ else
27
+ render :error, locals: { error_response: error_response }
28
+ end
21
29
  end
22
30
 
23
31
  private
24
32
 
25
33
  def render_success
26
- if skip_authorization? || matching_token?
27
- redirect_or_render authorize_response
34
+ if skip_authorization? || can_authorize_response?
35
+ redirect_or_render(authorize_response)
28
36
  elsif Doorkeeper.configuration.api_only
29
37
  render json: pre_auth
30
38
  else
@@ -33,16 +41,27 @@ module Doorkeeper
33
41
  end
34
42
 
35
43
  def render_error
36
- if Doorkeeper.configuration.api_only
37
- render json: pre_auth.error_response.body,
38
- status: :bad_request
44
+ pre_auth.error_response.raise_exception! if Doorkeeper.config.raise_on_errors?
45
+
46
+ if Doorkeeper.configuration.redirect_on_errors? && pre_auth.error_response.redirectable?
47
+ redirect_or_render(pre_auth.error_response)
48
+ elsif Doorkeeper.configuration.api_only
49
+ render json: pre_auth.error_response.body, status: pre_auth.error_response.status
39
50
  else
40
- render :error
51
+ render :error, locals: { error_response: pre_auth.error_response }, status: pre_auth.error_response.status
41
52
  end
42
53
  end
43
54
 
55
+ def can_authorize_response?
56
+ Doorkeeper.config.custom_access_token_attributes.empty? && pre_auth.client.application.confidential? && matching_token?
57
+ end
58
+
59
+ # Active access token issued for the same client and resource owner with
60
+ # the same set of the scopes exists?
44
61
  def matching_token?
45
- Doorkeeper.config.access_token_model.matching_token_for(
62
+ # We don't match tokens on the custom attributes here - we're in the pre-auth here,
63
+ # so they haven't been supplied yet (there are no custom attributes to match on yet)
64
+ @matching_token ||= Doorkeeper.config.access_token_model.matching_token_for(
46
65
  pre_auth.client,
47
66
  current_resource_owner,
48
67
  pre_auth.scopes,
@@ -64,7 +83,7 @@ module Doorkeeper
64
83
  )
65
84
  end
66
85
  elsif pre_auth.form_post_response?
67
- render :form_post
86
+ render :form_post, locals: { auth: auth }
68
87
  else
69
88
  redirect_to auth.redirect_uri, allow_other_host: true
70
89
  end
@@ -86,7 +105,7 @@ module Doorkeeper
86
105
  end
87
106
 
88
107
  def pre_auth_param_fields
89
- %i[
108
+ custom_access_token_attributes + %i[
90
109
  client_id
91
110
  code_challenge
92
111
  code_challenge_method
@@ -98,6 +117,10 @@ module Doorkeeper
98
117
  ]
99
118
  end
100
119
 
120
+ def custom_access_token_attributes
121
+ Doorkeeper.config.custom_access_token_attributes.map(&:to_sym)
122
+ end
123
+
101
124
  def authorization
102
125
  @authorization ||= strategy.request
103
126
  end
@@ -30,6 +30,7 @@ module Doorkeeper
30
30
  end
31
31
  end
32
32
 
33
+ # OAuth 2.0 Token Introspection - https://datatracker.ietf.org/doc/html/rfc7662
33
34
  def introspect
34
35
  introspection = OAuth::TokenIntrospection.new(server, token)
35
36
 
@@ -112,15 +113,36 @@ module Doorkeeper
112
113
  # The authorization server responds with HTTP status code 200 if the token
113
114
  # has been revoked successfully or if the client submitted an invalid
114
115
  # token
115
- token.revoke if token&.accessible?
116
+ revocable_token.revoke if revocable_token.revocable?
116
117
  end
117
118
 
118
- # Doorkeeper does not use the token_type_hint logic described in the
119
- # RFC 7009 due to the refresh token implementation that is a field in
120
- # the access token model.
121
119
  def token
122
- @token ||= Doorkeeper.config.access_token_model.by_token(params["token"]) ||
123
- Doorkeeper.config.access_token_model.by_refresh_token(params["token"])
120
+ revocable_token&.token
121
+ end
122
+
123
+ def revocable_token
124
+ return @revocable_token if defined? @revocable_token
125
+
126
+ @revocable_token =
127
+ if params[:token_type_hint] == "refresh_token"
128
+ refresh_token
129
+ else
130
+ access_token || refresh_token
131
+ end
132
+ end
133
+
134
+ def refresh_token
135
+ token = Doorkeeper.config.access_token_model.by_refresh_token(params["token"])
136
+ return unless token
137
+
138
+ RevocableTokens::RevocableRefreshToken.new(token)
139
+ end
140
+
141
+ def access_token
142
+ token = Doorkeeper.config.access_token_model.by_token(params["token"])
143
+ return unless token
144
+
145
+ RevocableTokens::RevocableAccessToken.new(token)
124
146
  end
125
147
 
126
148
  def strategy
@@ -3,5 +3,7 @@
3
3
  </div>
4
4
 
5
5
  <main role="main">
6
- <pre><%= @pre_auth.error_response.body[:error_description] %></pre>
6
+ <pre>
7
+ <%= (local_assigns[:error_response] ? error_response : @pre_auth.error_response).body[:error_description] %>
8
+ </pre>
7
9
  </main>
@@ -3,7 +3,7 @@
3
3
  </header>
4
4
 
5
5
  <%= form_tag @pre_auth.redirect_uri, method: :post, name: :redirect_form, authenticity_token: false do %>
6
- <% @authorize_response.body.compact.each do |key, value| %>
6
+ <% auth.body.compact.each do |key, value| %>
7
7
  <%= hidden_field_tag key, value %>
8
8
  <% end %>
9
9
  <% end %>
@@ -21,25 +21,25 @@
21
21
 
22
22
  <div class="actions">
23
23
  <%= form_tag oauth_authorization_path, method: :post do %>
24
- <%= hidden_field_tag :client_id, @pre_auth.client.uid %>
25
- <%= hidden_field_tag :redirect_uri, @pre_auth.redirect_uri %>
26
- <%= hidden_field_tag :state, @pre_auth.state %>
27
- <%= hidden_field_tag :response_type, @pre_auth.response_type %>
28
- <%= hidden_field_tag :response_mode, @pre_auth.response_mode %>
29
- <%= hidden_field_tag :scope, @pre_auth.scope %>
30
- <%= hidden_field_tag :code_challenge, @pre_auth.code_challenge %>
31
- <%= hidden_field_tag :code_challenge_method, @pre_auth.code_challenge_method %>
24
+ <%= hidden_field_tag :client_id, @pre_auth.client.uid, id: nil %>
25
+ <%= hidden_field_tag :redirect_uri, @pre_auth.redirect_uri, id: nil %>
26
+ <%= hidden_field_tag :state, @pre_auth.state, id: nil %>
27
+ <%= hidden_field_tag :response_type, @pre_auth.response_type, id: nil %>
28
+ <%= hidden_field_tag :response_mode, @pre_auth.response_mode, id: nil %>
29
+ <%= hidden_field_tag :scope, @pre_auth.scope, id: nil %>
30
+ <%= hidden_field_tag :code_challenge, @pre_auth.code_challenge, id: nil %>
31
+ <%= hidden_field_tag :code_challenge_method, @pre_auth.code_challenge_method, id: nil %>
32
32
  <%= submit_tag t('doorkeeper.authorizations.buttons.authorize'), class: "btn btn-success btn-lg btn-block" %>
33
33
  <% end %>
34
34
  <%= form_tag oauth_authorization_path, method: :delete do %>
35
- <%= hidden_field_tag :client_id, @pre_auth.client.uid %>
36
- <%= hidden_field_tag :redirect_uri, @pre_auth.redirect_uri %>
37
- <%= hidden_field_tag :state, @pre_auth.state %>
38
- <%= hidden_field_tag :response_type, @pre_auth.response_type %>
39
- <%= hidden_field_tag :response_mode, @pre_auth.response_mode %>
40
- <%= hidden_field_tag :scope, @pre_auth.scope %>
41
- <%= hidden_field_tag :code_challenge, @pre_auth.code_challenge %>
42
- <%= hidden_field_tag :code_challenge_method, @pre_auth.code_challenge_method %>
35
+ <%= hidden_field_tag :client_id, @pre_auth.client.uid, id: nil %>
36
+ <%= hidden_field_tag :redirect_uri, @pre_auth.redirect_uri, id: nil %>
37
+ <%= hidden_field_tag :state, @pre_auth.state, id: nil %>
38
+ <%= hidden_field_tag :response_type, @pre_auth.response_type, id: nil %>
39
+ <%= hidden_field_tag :response_mode, @pre_auth.response_mode, id: nil %>
40
+ <%= hidden_field_tag :scope, @pre_auth.scope, id: nil %>
41
+ <%= hidden_field_tag :code_challenge, @pre_auth.code_challenge, id: nil %>
42
+ <%= hidden_field_tag :code_challenge_method, @pre_auth.code_challenge_method, id: nil %>
43
43
  <%= submit_tag t('doorkeeper.authorizations.buttons.deny'), class: "btn btn-danger btn-lg btn-block" %>
44
44
  <% end %>
45
45
  </div>
@@ -100,7 +100,10 @@ en:
100
100
  unauthorized_client: 'The client is not authorized to perform this request using this method.'
101
101
  access_denied: 'The resource owner or authorization server denied the request.'
102
102
  invalid_scope: 'The requested scope is invalid, unknown, or malformed.'
103
- invalid_code_challenge_method: 'The code challenge method must be plain or S256.'
103
+ invalid_code_challenge_method:
104
+ zero: 'The authorization server does not support PKCE as there are no accepted code_challenge_method values.'
105
+ one: 'The code_challenge_method must be %{challenge_methods}.'
106
+ other: 'The code_challenge_method must be one of %{challenge_methods}.'
104
107
  server_error: 'The authorization server encountered an unexpected condition which prevented it from fulfilling the request.'
105
108
  temporarily_unavailable: 'The authorization server is currently unable to handle the request due to a temporary overloading or maintenance of the server.'
106
109
 
@@ -12,7 +12,7 @@ module Doorkeeper
12
12
  #
13
13
  def initialize(config = Config.new, &block)
14
14
  @config = config
15
- instance_eval(&block)
15
+ instance_eval(&block) if block_given?
16
16
  end
17
17
 
18
18
  # Builds and validates configuration.
@@ -11,6 +11,7 @@ module Doorkeeper
11
11
  validate_reuse_access_token_value
12
12
  validate_token_reuse_limit
13
13
  validate_secret_strategies
14
+ validate_pkce_code_challenge_methods
14
15
  end
15
16
 
16
17
  private
@@ -24,8 +25,8 @@ module Doorkeeper
24
25
  return if !reuse_access_token || strategy.allows_restoring_secrets?
25
26
 
26
27
  ::Rails.logger.warn(
27
- "You have configured both reuse_access_token " \
28
- "AND strategy strategy '#{strategy}' that cannot restore tokens. " \
28
+ "[DOORKEEPER] You have configured both reuse_access_token " \
29
+ "AND '#{strategy}' strategy which cannot restore tokens. " \
29
30
  "This combination is unsupported. reuse_access_token will be disabled",
30
31
  )
31
32
  @reuse_access_token = false
@@ -43,11 +44,22 @@ module Doorkeeper
43
44
  (token_reuse_limit > 0 && token_reuse_limit <= 100)
44
45
 
45
46
  ::Rails.logger.warn(
46
- "You have configured an invalid value for token_reuse_limit option. " \
47
+ "[DOORKEEPER] You have configured an invalid value for token_reuse_limit option. " \
47
48
  "It will be set to default 100",
48
49
  )
49
50
  @token_reuse_limit = 100
50
51
  end
52
+
53
+ def validate_pkce_code_challenge_methods
54
+ return if pkce_code_challenge_methods.all? {|method| method =~ /^plain$|^S256$/ }
55
+
56
+ ::Rails.logger.warn(
57
+ "[DOORKEEPER] You have configured an invalid value for pkce_code_challenge_methods option. " \
58
+ "It will be set to default ['plain', 'S256']",
59
+ )
60
+
61
+ @pkce_code_challenge_methods = ['plain', 'S256']
62
+ end
51
63
  end
52
64
  end
53
65
  end