doorkeeper 5.4.0.rc1 → 5.5.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +108 -9
- data/README.md +4 -4
- data/app/controllers/doorkeeper/applications_controller.rb +3 -3
- data/app/controllers/doorkeeper/authorizations_controller.rb +16 -5
- data/app/controllers/doorkeeper/authorized_applications_controller.rb +1 -1
- data/app/controllers/doorkeeper/token_info_controller.rb +12 -2
- data/app/controllers/doorkeeper/tokens_controller.rb +34 -26
- data/app/views/doorkeeper/applications/_form.html.erb +1 -1
- data/app/views/doorkeeper/applications/show.html.erb +16 -12
- data/app/views/doorkeeper/authorizations/form_post.html.erb +11 -0
- data/config/locales/en.yml +3 -1
- data/lib/doorkeeper.rb +6 -1
- data/lib/doorkeeper/config.rb +109 -78
- data/lib/doorkeeper/config/abstract_builder.rb +1 -1
- data/lib/doorkeeper/config/option.rb +1 -3
- data/lib/doorkeeper/config/validations.rb +53 -0
- data/lib/doorkeeper/engine.rb +1 -1
- data/lib/doorkeeper/grant_flow.rb +45 -0
- data/lib/doorkeeper/grant_flow/fallback_flow.rb +15 -0
- data/lib/doorkeeper/grant_flow/flow.rb +44 -0
- data/lib/doorkeeper/grant_flow/registry.rb +50 -0
- data/lib/doorkeeper/helpers/controller.rb +8 -4
- data/lib/doorkeeper/models/access_grant_mixin.rb +12 -7
- data/lib/doorkeeper/models/access_token_mixin.rb +12 -8
- data/lib/doorkeeper/models/application_mixin.rb +5 -4
- data/lib/doorkeeper/models/concerns/revocable.rb +1 -1
- data/lib/doorkeeper/oauth/authorization/code.rb +5 -1
- data/lib/doorkeeper/oauth/authorization/context.rb +5 -5
- data/lib/doorkeeper/oauth/authorization/token.rb +11 -5
- data/lib/doorkeeper/oauth/authorization/uri_builder.rb +1 -1
- data/lib/doorkeeper/oauth/authorization_code_request.rb +10 -17
- data/lib/doorkeeper/oauth/base_request.rb +1 -1
- data/lib/doorkeeper/oauth/client_credentials/creator.rb +3 -2
- data/lib/doorkeeper/oauth/client_credentials/issuer.rb +1 -0
- data/lib/doorkeeper/oauth/client_credentials/validator.rb +3 -1
- data/lib/doorkeeper/oauth/code_request.rb +2 -2
- data/lib/doorkeeper/oauth/code_response.rb +17 -11
- data/lib/doorkeeper/oauth/error_response.rb +4 -3
- data/lib/doorkeeper/oauth/helpers/scope_checker.rb +1 -3
- data/lib/doorkeeper/oauth/password_access_token_request.rb +21 -2
- data/lib/doorkeeper/oauth/pre_authorization.rb +37 -11
- data/lib/doorkeeper/oauth/refresh_token_request.rb +13 -0
- data/lib/doorkeeper/oauth/token.rb +4 -5
- data/lib/doorkeeper/oauth/token_introspection.rb +1 -5
- data/lib/doorkeeper/oauth/token_request.rb +1 -1
- data/lib/doorkeeper/orm/active_record.rb +5 -6
- data/lib/doorkeeper/orm/active_record/mixins/access_grant.rb +12 -2
- data/lib/doorkeeper/orm/active_record/mixins/access_token.rb +10 -2
- data/lib/doorkeeper/orm/active_record/mixins/application.rb +76 -10
- data/lib/doorkeeper/orm/active_record/redirect_uri_validator.rb +5 -0
- data/lib/doorkeeper/rails/routes.rb +1 -3
- data/lib/doorkeeper/rake/db.rake +3 -3
- data/lib/doorkeeper/rake/setup.rake +5 -0
- data/lib/doorkeeper/request.rb +49 -12
- data/lib/doorkeeper/request/refresh_token.rb +2 -1
- data/lib/doorkeeper/server.rb +1 -1
- data/lib/doorkeeper/stale_records_cleaner.rb +4 -4
- data/lib/doorkeeper/version.rb +2 -6
- data/lib/generators/doorkeeper/templates/add_owner_to_application_migration.rb.erb +1 -1
- data/lib/generators/doorkeeper/templates/initializer.rb +9 -7
- data/lib/generators/doorkeeper/templates/migration.rb.erb +12 -5
- metadata +25 -306
- data/Appraisals +0 -26
- data/CODE_OF_CONDUCT.md +0 -46
- data/CONTRIBUTING.md +0 -49
- data/Dangerfile +0 -67
- data/Dockerfile +0 -29
- data/Gemfile +0 -25
- data/NEWS.md +0 -1
- data/RELEASING.md +0 -11
- data/Rakefile +0 -28
- data/SECURITY.md +0 -15
- data/UPGRADE.md +0 -2
- data/bin/console +0 -30
- data/doorkeeper.gemspec +0 -42
- data/gemfiles/rails_5_0.gemfile +0 -19
- data/gemfiles/rails_5_1.gemfile +0 -19
- data/gemfiles/rails_5_2.gemfile +0 -19
- data/gemfiles/rails_6_0.gemfile +0 -19
- data/gemfiles/rails_master.gemfile +0 -19
- data/spec/controllers/application_metal_controller_spec.rb +0 -64
- data/spec/controllers/applications_controller_spec.rb +0 -274
- data/spec/controllers/authorizations_controller_spec.rb +0 -743
- data/spec/controllers/protected_resources_controller_spec.rb +0 -361
- data/spec/controllers/token_info_controller_spec.rb +0 -50
- data/spec/controllers/tokens_controller_spec.rb +0 -499
- data/spec/dummy/Rakefile +0 -9
- data/spec/dummy/app/assets/config/manifest.js +0 -2
- data/spec/dummy/app/controllers/application_controller.rb +0 -5
- data/spec/dummy/app/controllers/custom_authorizations_controller.rb +0 -9
- data/spec/dummy/app/controllers/full_protected_resources_controller.rb +0 -14
- data/spec/dummy/app/controllers/home_controller.rb +0 -18
- data/spec/dummy/app/controllers/metal_controller.rb +0 -13
- data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +0 -13
- data/spec/dummy/app/helpers/application_helper.rb +0 -7
- data/spec/dummy/app/models/user.rb +0 -11
- data/spec/dummy/app/views/home/index.html.erb +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/config.ru +0 -6
- data/spec/dummy/config/application.rb +0 -51
- data/spec/dummy/config/boot.rb +0 -7
- data/spec/dummy/config/database.yml +0 -15
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -31
- data/spec/dummy/config/environments/production.rb +0 -64
- data/spec/dummy/config/environments/test.rb +0 -45
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -9
- data/spec/dummy/config/initializers/doorkeeper.rb +0 -166
- data/spec/dummy/config/initializers/secret_token.rb +0 -10
- data/spec/dummy/config/initializers/session_store.rb +0 -10
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -16
- data/spec/dummy/config/locales/doorkeeper.en.yml +0 -5
- data/spec/dummy/config/routes.rb +0 -13
- data/spec/dummy/db/migrate/20111122132257_create_users.rb +0 -11
- data/spec/dummy/db/migrate/20120312140401_add_password_to_users.rb +0 -7
- data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +0 -69
- data/spec/dummy/db/migrate/20151223200000_add_owner_to_application.rb +0 -9
- data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +0 -13
- data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +0 -8
- data/spec/dummy/db/migrate/20180210183654_add_confidential_to_applications.rb +0 -13
- data/spec/dummy/db/schema.rb +0 -70
- data/spec/dummy/public/404.html +0 -26
- data/spec/dummy/public/422.html +0 -26
- data/spec/dummy/public/500.html +0 -26
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +0 -9
- data/spec/factories.rb +0 -30
- data/spec/generators/application_owner_generator_spec.rb +0 -28
- data/spec/generators/confidential_applications_generator_spec.rb +0 -29
- data/spec/generators/enable_polymorphic_resource_owner_generator_spec.rb +0 -47
- data/spec/generators/install_generator_spec.rb +0 -36
- data/spec/generators/migration_generator_spec.rb +0 -28
- data/spec/generators/pkce_generator_spec.rb +0 -28
- data/spec/generators/previous_refresh_token_generator_spec.rb +0 -44
- data/spec/generators/templates/routes.rb +0 -4
- data/spec/generators/views_generator_spec.rb +0 -29
- data/spec/grape/grape_integration_spec.rb +0 -137
- data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +0 -26
- data/spec/lib/config_spec.rb +0 -813
- data/spec/lib/doorkeeper_spec.rb +0 -27
- data/spec/lib/models/expirable_spec.rb +0 -61
- data/spec/lib/models/reusable_spec.rb +0 -40
- data/spec/lib/models/revocable_spec.rb +0 -58
- data/spec/lib/models/scopes_spec.rb +0 -61
- data/spec/lib/models/secret_storable_spec.rb +0 -135
- data/spec/lib/oauth/authorization/uri_builder_spec.rb +0 -39
- data/spec/lib/oauth/authorization_code_request_spec.rb +0 -180
- data/spec/lib/oauth/base_request_spec.rb +0 -210
- data/spec/lib/oauth/base_response_spec.rb +0 -45
- data/spec/lib/oauth/client/credentials_spec.rb +0 -90
- data/spec/lib/oauth/client_credentials/creator_spec.rb +0 -135
- data/spec/lib/oauth/client_credentials/issuer_spec.rb +0 -110
- data/spec/lib/oauth/client_credentials/validation_spec.rb +0 -57
- data/spec/lib/oauth/client_credentials_integration_spec.rb +0 -27
- data/spec/lib/oauth/client_credentials_request_spec.rb +0 -108
- data/spec/lib/oauth/client_spec.rb +0 -38
- data/spec/lib/oauth/code_request_spec.rb +0 -46
- data/spec/lib/oauth/code_response_spec.rb +0 -36
- data/spec/lib/oauth/error_response_spec.rb +0 -64
- data/spec/lib/oauth/error_spec.rb +0 -21
- data/spec/lib/oauth/forbidden_token_response_spec.rb +0 -20
- data/spec/lib/oauth/helpers/scope_checker_spec.rb +0 -110
- data/spec/lib/oauth/helpers/unique_token_spec.rb +0 -21
- data/spec/lib/oauth/helpers/uri_checker_spec.rb +0 -262
- data/spec/lib/oauth/invalid_request_response_spec.rb +0 -73
- data/spec/lib/oauth/invalid_token_response_spec.rb +0 -53
- data/spec/lib/oauth/password_access_token_request_spec.rb +0 -201
- data/spec/lib/oauth/pre_authorization_spec.rb +0 -218
- data/spec/lib/oauth/refresh_token_request_spec.rb +0 -166
- data/spec/lib/oauth/scopes_spec.rb +0 -146
- data/spec/lib/oauth/token_request_spec.rb +0 -164
- data/spec/lib/oauth/token_response_spec.rb +0 -84
- data/spec/lib/oauth/token_spec.rb +0 -156
- data/spec/lib/option_spec.rb +0 -51
- data/spec/lib/request/strategy_spec.rb +0 -54
- data/spec/lib/secret_storing/base_spec.rb +0 -60
- data/spec/lib/secret_storing/bcrypt_spec.rb +0 -49
- data/spec/lib/secret_storing/plain_spec.rb +0 -44
- data/spec/lib/secret_storing/sha256_hash_spec.rb +0 -48
- data/spec/lib/server_spec.rb +0 -49
- data/spec/lib/stale_records_cleaner_spec.rb +0 -102
- data/spec/models/doorkeeper/access_grant_spec.rb +0 -175
- data/spec/models/doorkeeper/access_token_spec.rb +0 -650
- data/spec/models/doorkeeper/application_spec.rb +0 -442
- data/spec/requests/applications/applications_request_spec.rb +0 -259
- data/spec/requests/applications/authorized_applications_spec.rb +0 -32
- data/spec/requests/endpoints/authorization_spec.rb +0 -91
- data/spec/requests/endpoints/token_spec.rb +0 -79
- data/spec/requests/flows/authorization_code_errors_spec.rb +0 -82
- data/spec/requests/flows/authorization_code_spec.rb +0 -530
- data/spec/requests/flows/client_credentials_spec.rb +0 -207
- data/spec/requests/flows/implicit_grant_errors_spec.rb +0 -46
- data/spec/requests/flows/implicit_grant_spec.rb +0 -91
- data/spec/requests/flows/password_spec.rb +0 -316
- data/spec/requests/flows/refresh_token_spec.rb +0 -241
- data/spec/requests/flows/revoke_token_spec.rb +0 -196
- data/spec/requests/flows/skip_authorization_spec.rb +0 -66
- data/spec/requests/protected_resources/metal_spec.rb +0 -16
- data/spec/requests/protected_resources/private_api_spec.rb +0 -83
- data/spec/routing/custom_controller_routes_spec.rb +0 -133
- data/spec/routing/default_routes_spec.rb +0 -41
- data/spec/routing/scoped_routes_spec.rb +0 -47
- data/spec/spec_helper.rb +0 -54
- data/spec/spec_helper_integration.rb +0 -4
- data/spec/support/dependencies/factory_bot.rb +0 -4
- data/spec/support/doorkeeper_rspec.rb +0 -22
- data/spec/support/helpers/access_token_request_helper.rb +0 -14
- data/spec/support/helpers/authorization_request_helper.rb +0 -43
- data/spec/support/helpers/config_helper.rb +0 -11
- data/spec/support/helpers/model_helper.rb +0 -78
- data/spec/support/helpers/request_spec_helper.rb +0 -110
- data/spec/support/helpers/url_helper.rb +0 -62
- data/spec/support/orm/active_record.rb +0 -5
- data/spec/support/shared/controllers_shared_context.rb +0 -133
- data/spec/support/shared/hashing_shared_context.rb +0 -36
- data/spec/support/shared/models_shared_examples.rb +0 -56
- data/spec/validators/redirect_uri_validator_spec.rb +0 -183
- data/spec/version/version_spec.rb +0 -17
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Doorkeeper
|
4
|
+
module GrantFlow
|
5
|
+
module Registry
|
6
|
+
mattr_accessor :flows
|
7
|
+
self.flows = {}
|
8
|
+
|
9
|
+
mattr_accessor :aliases
|
10
|
+
self.aliases = {}
|
11
|
+
|
12
|
+
# Allows to register custom OAuth grant flow so that Doorkeeper
|
13
|
+
# could recognize and process it.
|
14
|
+
#
|
15
|
+
def register(name_or_flow, **options)
|
16
|
+
unless name_or_flow.is_a?(Doorkeeper::GrantFlow::Flow)
|
17
|
+
name_or_flow = Flow.new(name_or_flow, **options)
|
18
|
+
end
|
19
|
+
|
20
|
+
flow_key = name_or_flow.name.to_sym
|
21
|
+
|
22
|
+
if flows.key?(flow_key)
|
23
|
+
::Kernel.warn <<~WARNING
|
24
|
+
[DOORKEEPER] '#{flow_key}' grant flow already registered and will be overridden
|
25
|
+
in #{caller(1..1).first}
|
26
|
+
WARNING
|
27
|
+
end
|
28
|
+
|
29
|
+
flows[flow_key] = name_or_flow
|
30
|
+
end
|
31
|
+
|
32
|
+
# Allows to register aliases that could be used in `grant_flows`
|
33
|
+
# configuration option. It is possible to have aliases like 1:1 or
|
34
|
+
# 1:N, i.e. "implicit_oidc" => ['token', 'id_token', 'id_token token'].
|
35
|
+
#
|
36
|
+
def register_alias(alias_name, **options)
|
37
|
+
aliases[alias_name.to_sym] = Array.wrap(options.fetch(:as))
|
38
|
+
end
|
39
|
+
|
40
|
+
def expand_alias(alias_name)
|
41
|
+
aliases.fetch(alias_name.to_sym, [])
|
42
|
+
end
|
43
|
+
|
44
|
+
# [NOTE]: make it to use #fetch after removing fallbacks
|
45
|
+
def get(name)
|
46
|
+
flows[name.to_sym]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -16,6 +16,8 @@ module Doorkeeper
|
|
16
16
|
|
17
17
|
# :doc:
|
18
18
|
def current_resource_owner
|
19
|
+
return @current_resource_owner if defined?(@current_resource_owner)
|
20
|
+
|
19
21
|
@current_resource_owner ||= begin
|
20
22
|
instance_eval(&Doorkeeper.config.authenticate_resource_owner)
|
21
23
|
end
|
@@ -36,7 +38,9 @@ module Doorkeeper
|
|
36
38
|
|
37
39
|
# :doc:
|
38
40
|
def doorkeeper_token
|
39
|
-
@doorkeeper_token
|
41
|
+
return @doorkeeper_token if defined?(@doorkeeper_token)
|
42
|
+
|
43
|
+
@doorkeeper_token ||= OAuth::Token.authenticate(request, *config_methods)
|
40
44
|
end
|
41
45
|
|
42
46
|
def config_methods
|
@@ -58,10 +62,10 @@ module Doorkeeper
|
|
58
62
|
end
|
59
63
|
|
60
64
|
def handle_token_exception(exception)
|
61
|
-
error = get_error_response_from_exception
|
62
|
-
headers.merge!
|
65
|
+
error = get_error_response_from_exception(exception)
|
66
|
+
headers.merge!(error.headers)
|
63
67
|
self.response_body = error.body.to_json
|
64
|
-
self.status
|
68
|
+
self.status = error.status
|
65
69
|
end
|
66
70
|
|
67
71
|
def skip_authorization?
|
@@ -13,7 +13,7 @@ module Doorkeeper
|
|
13
13
|
include Models::Scopes
|
14
14
|
include Models::ResourceOwnerable
|
15
15
|
|
16
|
-
#
|
16
|
+
# Never uses PKCE if PKCE migrations were not generated
|
17
17
|
def uses_pkce?
|
18
18
|
self.class.pkce_supported? && code_challenge.present?
|
19
19
|
end
|
@@ -24,8 +24,8 @@ module Doorkeeper
|
|
24
24
|
#
|
25
25
|
# @param token [#to_s] token value (any object that responds to `#to_s`)
|
26
26
|
#
|
27
|
-
# @return [Doorkeeper::AccessGrant, nil]
|
28
|
-
# if there is no record with such token
|
27
|
+
# @return [Doorkeeper::AccessGrant, nil]
|
28
|
+
# AccessGrant object or nil if there is no record with such token
|
29
29
|
#
|
30
30
|
def by_token(token)
|
31
31
|
find_by_plaintext_token(:token, token)
|
@@ -36,8 +36,8 @@ module Doorkeeper
|
|
36
36
|
#
|
37
37
|
# @param application_id [Integer]
|
38
38
|
# ID of the Application
|
39
|
-
# @param resource_owner [ActiveRecord::Base]
|
40
|
-
# instance of the Resource Owner model
|
39
|
+
# @param resource_owner [ActiveRecord::Base, Integer]
|
40
|
+
# instance of the Resource Owner model or it's ID
|
41
41
|
#
|
42
42
|
def revoke_all_for(application_id, resource_owner, clock = Time)
|
43
43
|
by_resource_owner(resource_owner)
|
@@ -89,8 +89,7 @@ module Doorkeeper
|
|
89
89
|
# suitable for PKCE validation
|
90
90
|
#
|
91
91
|
def generate_code_challenge(code_verifier)
|
92
|
-
|
93
|
-
padded_result.split("=")[0] # Remove any trailing '='
|
92
|
+
Base64.urlsafe_encode64(Digest::SHA256.digest(code_verifier), padding: false)
|
94
93
|
end
|
95
94
|
|
96
95
|
def pkce_supported?
|
@@ -100,6 +99,9 @@ module Doorkeeper
|
|
100
99
|
##
|
101
100
|
# Determines the secret storing transformer
|
102
101
|
# Unless configured otherwise, uses the plain secret strategy
|
102
|
+
#
|
103
|
+
# @return [Doorkeeper::SecretStoring::Base]
|
104
|
+
#
|
103
105
|
def secret_strategy
|
104
106
|
::Doorkeeper.config.token_secret_strategy
|
105
107
|
end
|
@@ -107,6 +109,9 @@ module Doorkeeper
|
|
107
109
|
##
|
108
110
|
# Determine the fallback storing strategy
|
109
111
|
# Unless configured, there will be no fallback
|
112
|
+
#
|
113
|
+
# @return [Doorkeeper::SecretStoring::Base]
|
114
|
+
#
|
110
115
|
def fallback_secret_strategy
|
111
116
|
::Doorkeeper.config.token_secret_fallback_strategy
|
112
117
|
end
|
@@ -61,8 +61,8 @@ module Doorkeeper
|
|
61
61
|
#
|
62
62
|
# @param application_id [Integer]
|
63
63
|
# ID of the Application
|
64
|
-
# @param resource_owner [ActiveRecord::Base]
|
65
|
-
# instance of the Resource Owner model
|
64
|
+
# @param resource_owner [ActiveRecord::Base, Integer]
|
65
|
+
# instance of the Resource Owner model or it's ID
|
66
66
|
#
|
67
67
|
def revoke_all_for(application_id, resource_owner, clock = Time)
|
68
68
|
by_resource_owner(resource_owner)
|
@@ -94,8 +94,8 @@ module Doorkeeper
|
|
94
94
|
# Interface to enumerate access token records in batches in order not
|
95
95
|
# to bloat the memory. Could be overloaded in any ORM extension.
|
96
96
|
#
|
97
|
-
def find_access_token_in_batches(relation,
|
98
|
-
relation.find_in_batches(
|
97
|
+
def find_access_token_in_batches(relation, **args, &block)
|
98
|
+
relation.find_in_batches(**args, &block)
|
99
99
|
end
|
100
100
|
|
101
101
|
# Enumerates AccessToken records in batches to find a matching token.
|
@@ -230,10 +230,11 @@ module Doorkeeper
|
|
230
230
|
#
|
231
231
|
# @param application_id [Integer]
|
232
232
|
# ID of the Application model instance
|
233
|
-
# @param resource_owner [Integer]
|
234
|
-
#
|
233
|
+
# @param resource_owner [ActiveRecord::Base, Integer]
|
234
|
+
# Resource Owner model instance or it's ID
|
235
235
|
#
|
236
|
-
# @return [
|
236
|
+
# @return [ActiveRecord::Relation]
|
237
|
+
# collection of matching AccessToken objects
|
237
238
|
#
|
238
239
|
def authorized_tokens_for(application_id, resource_owner)
|
239
240
|
by_resource_owner(resource_owner).where(
|
@@ -262,6 +263,9 @@ module Doorkeeper
|
|
262
263
|
##
|
263
264
|
# Determines the secret storing transformer
|
264
265
|
# Unless configured otherwise, uses the plain secret strategy
|
266
|
+
#
|
267
|
+
# @return [Doorkeeper::SecretStoring::Base]
|
268
|
+
#
|
265
269
|
def secret_strategy
|
266
270
|
::Doorkeeper.config.token_secret_strategy
|
267
271
|
end
|
@@ -373,7 +377,7 @@ module Doorkeeper
|
|
373
377
|
return unless self.class.refresh_token_revoked_on_use?
|
374
378
|
|
375
379
|
old_refresh_token&.revoke
|
376
|
-
|
380
|
+
update_attribute(:previous_refresh_token, "") if previous_refresh_token.present?
|
377
381
|
end
|
378
382
|
|
379
383
|
private
|
@@ -20,8 +20,8 @@ module Doorkeeper
|
|
20
20
|
# @param uid [#to_s] UID (any object that responds to `#to_s`)
|
21
21
|
# @param secret [#to_s] secret (any object that responds to `#to_s`)
|
22
22
|
#
|
23
|
-
# @return [Doorkeeper::Application, nil]
|
24
|
-
# if there is no record with such credentials
|
23
|
+
# @return [Doorkeeper::Application, nil]
|
24
|
+
# Application instance or nil if there is no record with such credentials
|
25
25
|
#
|
26
26
|
def by_uid_and_secret(uid, secret)
|
27
27
|
app = by_uid(uid)
|
@@ -60,9 +60,10 @@ module Doorkeeper
|
|
60
60
|
|
61
61
|
# Set an application's valid redirect URIs.
|
62
62
|
#
|
63
|
-
# @param uris [String, Array] Newline-separated string or array the URI(s)
|
63
|
+
# @param uris [String, Array<String>] Newline-separated string or array the URI(s)
|
64
|
+
#
|
65
|
+
# @return [String] The redirect URI(s) separated by newlines.
|
64
66
|
#
|
65
|
-
# @return [String] The redirect URI(s) seperated by newlines.
|
66
67
|
def redirect_uri=(uris)
|
67
68
|
super(uris.is_a?(Array) ? uris.join("\n") : uris)
|
68
69
|
end
|
@@ -11,7 +11,7 @@ module Doorkeeper
|
|
11
11
|
@resource_owner = resource_owner
|
12
12
|
end
|
13
13
|
|
14
|
-
def issue_token
|
14
|
+
def issue_token!
|
15
15
|
return @token if defined?(@token)
|
16
16
|
|
17
17
|
@token = Doorkeeper.config.access_grant_model.create!(access_grant_attributes)
|
@@ -21,6 +21,10 @@ module Doorkeeper
|
|
21
21
|
{ action: :show, code: token.plaintext_token }
|
22
22
|
end
|
23
23
|
|
24
|
+
def access_grant?
|
25
|
+
true
|
26
|
+
end
|
27
|
+
|
24
28
|
private
|
25
29
|
|
26
30
|
def authorization_code_expires_in
|
@@ -4,12 +4,12 @@ module Doorkeeper
|
|
4
4
|
module OAuth
|
5
5
|
module Authorization
|
6
6
|
class Context
|
7
|
-
attr_reader :client, :grant_type, :scopes
|
7
|
+
attr_reader :client, :grant_type, :resource_owner, :scopes
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
def initialize(**attributes)
|
10
|
+
attributes.each do |name, value|
|
11
|
+
instance_variable_set(:"@#{name}", value) if respond_to?(name)
|
12
|
+
end
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -7,7 +7,7 @@ module Doorkeeper
|
|
7
7
|
attr_reader :pre_auth, :resource_owner, :token
|
8
8
|
|
9
9
|
class << self
|
10
|
-
def build_context(pre_auth_or_oauth_client, grant_type, scopes)
|
10
|
+
def build_context(pre_auth_or_oauth_client, grant_type, scopes, resource_owner)
|
11
11
|
oauth_client = if pre_auth_or_oauth_client.respond_to?(:application)
|
12
12
|
pre_auth_or_oauth_client.application
|
13
13
|
elsif pre_auth_or_oauth_client.respond_to?(:client)
|
@@ -17,9 +17,10 @@ module Doorkeeper
|
|
17
17
|
end
|
18
18
|
|
19
19
|
Doorkeeper::OAuth::Authorization::Context.new(
|
20
|
-
oauth_client,
|
21
|
-
grant_type,
|
22
|
-
scopes,
|
20
|
+
client: oauth_client,
|
21
|
+
grant_type: grant_type,
|
22
|
+
scopes: scopes,
|
23
|
+
resource_owner: resource_owner,
|
23
24
|
)
|
24
25
|
end
|
25
26
|
|
@@ -48,13 +49,14 @@ module Doorkeeper
|
|
48
49
|
@resource_owner = resource_owner
|
49
50
|
end
|
50
51
|
|
51
|
-
def issue_token
|
52
|
+
def issue_token!
|
52
53
|
return @token if defined?(@token)
|
53
54
|
|
54
55
|
context = self.class.build_context(
|
55
56
|
pre_auth.client,
|
56
57
|
Doorkeeper::OAuth::IMPLICIT,
|
57
58
|
pre_auth.scopes,
|
59
|
+
resource_owner,
|
58
60
|
)
|
59
61
|
|
60
62
|
@token = Doorkeeper.config.access_token_model.find_or_create_for(
|
@@ -74,6 +76,10 @@ module Doorkeeper
|
|
74
76
|
}
|
75
77
|
end
|
76
78
|
|
79
|
+
def access_token?
|
80
|
+
true
|
81
|
+
end
|
82
|
+
|
77
83
|
private
|
78
84
|
|
79
85
|
def controller
|
@@ -3,7 +3,6 @@
|
|
3
3
|
module Doorkeeper
|
4
4
|
module OAuth
|
5
5
|
class AuthorizationCodeRequest < BaseRequest
|
6
|
-
validate :pkce_support, error: :invalid_request
|
7
6
|
validate :params, error: :invalid_request
|
8
7
|
validate :client, error: :invalid_client
|
9
8
|
validate :grant, error: :invalid_grant
|
@@ -32,12 +31,6 @@ module Doorkeeper
|
|
32
31
|
|
33
32
|
grant.revoke
|
34
33
|
|
35
|
-
resource_owner = if Doorkeeper.config.polymorphic_resource_owner?
|
36
|
-
grant.resource_owner
|
37
|
-
else
|
38
|
-
grant.resource_owner_id
|
39
|
-
end
|
40
|
-
|
41
34
|
find_or_create_access_token(
|
42
35
|
grant.application,
|
43
36
|
resource_owner,
|
@@ -49,16 +42,16 @@ module Doorkeeper
|
|
49
42
|
super
|
50
43
|
end
|
51
44
|
|
52
|
-
def
|
53
|
-
Doorkeeper.config.
|
45
|
+
def resource_owner
|
46
|
+
if Doorkeeper.config.polymorphic_resource_owner?
|
47
|
+
grant.resource_owner
|
48
|
+
else
|
49
|
+
grant.resource_owner_id
|
50
|
+
end
|
54
51
|
end
|
55
52
|
|
56
|
-
def
|
57
|
-
|
58
|
-
!pkce_supported? &&
|
59
|
-
code_verifier.present?
|
60
|
-
|
61
|
-
@invalid_request_reason.nil?
|
53
|
+
def pkce_supported?
|
54
|
+
Doorkeeper.config.access_grant_model.pkce_supported?
|
62
55
|
end
|
63
56
|
|
64
57
|
def validate_params
|
@@ -91,8 +84,8 @@ module Doorkeeper
|
|
91
84
|
# if either side (server or client) request PKCE, check the verifier
|
92
85
|
# against the DB - if PKCE is supported
|
93
86
|
def validate_code_verifier
|
94
|
-
return true unless
|
95
|
-
return
|
87
|
+
return true unless pkce_supported?
|
88
|
+
return grant.code_challenge.blank? if code_verifier.blank?
|
96
89
|
|
97
90
|
if grant.code_challenge_method == "S256"
|
98
91
|
grant.code_challenge == generate_code_challenge(code_verifier)
|
@@ -27,7 +27,7 @@ module Doorkeeper
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def find_or_create_access_token(client, resource_owner, scopes, server)
|
30
|
-
context = Authorization::Token.build_context(client, grant_type, scopes)
|
30
|
+
context = Authorization::Token.build_context(client, grant_type, scopes, resource_owner)
|
31
31
|
@access_token = server_config.access_token_model.find_or_create_for(
|
32
32
|
application: client,
|
33
33
|
resource_owner: resource_owner,
|
@@ -25,7 +25,7 @@ module Doorkeeper
|
|
25
25
|
private
|
26
26
|
|
27
27
|
def with_revocation(existing_token:)
|
28
|
-
if existing_token && server_config.revoke_previous_client_credentials_token
|
28
|
+
if existing_token && server_config.revoke_previous_client_credentials_token?
|
29
29
|
existing_token.with_lock do
|
30
30
|
raise Errors::DoorkeeperError, :invalid_token_reuse if existing_token.revoked?
|
31
31
|
|
@@ -39,7 +39,8 @@ module Doorkeeper
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def lookup_existing_token?
|
42
|
-
server_config.reuse_access_token ||
|
42
|
+
server_config.reuse_access_token ||
|
43
|
+
server_config.revoke_previous_client_credentials_token?
|
43
44
|
end
|
44
45
|
|
45
46
|
def find_existing_token_for(client, scopes)
|
@@ -6,13 +6,13 @@ module Doorkeeper
|
|
6
6
|
attr_reader :pre_auth, :resource_owner
|
7
7
|
|
8
8
|
def initialize(pre_auth, resource_owner)
|
9
|
-
@pre_auth
|
9
|
+
@pre_auth = pre_auth
|
10
10
|
@resource_owner = resource_owner
|
11
11
|
end
|
12
12
|
|
13
13
|
def authorize
|
14
14
|
auth = Authorization::Code.new(pre_auth, resource_owner)
|
15
|
-
auth.issue_token
|
15
|
+
auth.issue_token!
|
16
16
|
CodeResponse.new(pre_auth, auth)
|
17
17
|
end
|
18
18
|
|