From a4d4767a33b3231fa7077d272cbb06e0734a2645 Mon Sep 17 00:00:00 2001 From: JeremyC-za Date: Fri, 24 Mar 2023 17:43:15 +0200 Subject: [PATCH] Warning instead of raising config errors --- lib/doorkeeper.rb | 5 +++-- lib/doorkeeper/config/validations.rb | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/doorkeeper.rb b/lib/doorkeeper.rb index 2400bc9c4..0f296bedd 100644 --- a/lib/doorkeeper.rb +++ b/lib/doorkeeper.rb @@ -118,9 +118,10 @@ class << self attr_reader :orm_adapter def configure(&block) - @config = Config::Builder.new(&block).build + builder = Config::Builder.new(&block) + @config = builder.config setup - @config + builder.build end # @return [Doorkeeper::Config] configuration instance diff --git a/lib/doorkeeper/config/validations.rb b/lib/doorkeeper/config/validations.rb index bf9760014..828360302 100644 --- a/lib/doorkeeper/config/validations.rb +++ b/lib/doorkeeper/config/validations.rb @@ -11,6 +11,7 @@ def validate! validate_reuse_access_token_value validate_token_reuse_limit validate_secret_strategies + validate_custom_access_token_attributes end private @@ -48,6 +49,27 @@ def validate_token_reuse_limit ) @token_reuse_limit = 100 end + + # Validate that the access_token and access_grant models + # both respond to all of the custom attributes + def validate_custom_access_token_attributes + return if custom_access_token_attributes.blank? + + unrecognized_attributes = [] + custom_access_token_attributes.each do |attrib| + [access_token_model, access_grant_model].each do |model| + next if model.has_attribute?(attrib) + + unrecognized_attributes << attrib + ::Rails.logger.warn( + "[DOORKEEPER] #{access_token_model} does not respond to custom attribute '#{attrib}'. " \ + "This custom attribute will be ignored.", + ) + end + end + + @custom_access_token_attributes -= unrecognized_attributes + end end end end