From 6fcecf395a98828057d8751363311c78d62dc3bc Mon Sep 17 00:00:00 2001 From: Phil Phillips Date: Wed, 6 May 2020 11:30:55 -0700 Subject: [PATCH] Make Doorkeeper::Application#read_attribute_for_serialization public. This allows for custom serializers. --- .../orm/active_record/mixins/application.rb | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/lib/doorkeeper/orm/active_record/mixins/application.rb b/lib/doorkeeper/orm/active_record/mixins/application.rb index b6455d216..869cdf2f2 100644 --- a/lib/doorkeeper/orm/active_record/mixins/application.rb +++ b/lib/doorkeeper/orm/active_record/mixins/application.rb @@ -12,12 +12,12 @@ module Application has_many :access_grants, foreign_key: :application_id, dependent: :delete_all, - class_name: Doorkeeper.config.access_grant_class + class_name: Doorkeeper.config.access_grant_class.to_s has_many :access_tokens, foreign_key: :application_id, dependent: :delete_all, - class_name: Doorkeeper.config.access_token_class + class_name: Doorkeeper.config.access_token_class.to_s validates :name, :secret, :uid, presence: true validates :uid, uniqueness: { case_sensitive: true } @@ -31,7 +31,7 @@ module Application has_many :authorized_tokens, -> { where(revoked_at: nil) }, foreign_key: :application_id, - class_name: Doorkeeper.config.access_token_class + class_name: Doorkeeper.config.access_token_class.to_s has_many :authorized_applications, through: :authorized_tokens, @@ -84,6 +84,21 @@ def as_json(options = {}) end end + def authorized_for_resource_owner?(resource_owner) + Doorkeeper.configuration.authorize_resource_owner_for_client.call(self, resource_owner) + end + + # We need to hook into this method to allow serializing plan-text secrets + # when secrets hashing enabled. + # + # @param key [String] attribute name + # + def read_attribute_for_serialization(key) + return super unless key.to_s == "secret" + + plaintext_secret || secret + end + private def generate_uid @@ -91,7 +106,7 @@ def generate_uid end def generate_secret - return unless secret.blank? + return if secret.present? renew_secret end @@ -131,17 +146,6 @@ def extract_serializable_attributes(options = {}) only.uniq end - # We need to hook into this method to allow serializing plan-text secrets - # when secrets hashing enabled. - # - # @param key [String] attribute name - # - def read_attribute_for_serialization(key) - return super unless key.to_s == "secret" - - plaintext_secret || secret - end - # Collection of attributes that could be serialized for public. # Override this method if you need additional attributes to be serialized. # @@ -153,7 +157,7 @@ def serializable_attributes end end - class_methods do + module ClassMethods # Returns Applications associated with active (not revoked) Access Tokens # that are owned by the specific Resource Owner. #