Skip to content

Commit

Permalink
Make Doorkeeper::Application#read_attribute_for_serialization public.
Browse files Browse the repository at this point in the history
This allows for custom serializers.
  • Loading branch information
irphilli authored and nbulaj committed May 7, 2020
1 parent 8495a81 commit 6fcecf3
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions lib/doorkeeper/orm/active_record/mixins/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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,
Expand Down Expand Up @@ -84,14 +84,29 @@ 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
self.uid = Doorkeeper::OAuth::Helpers::UniqueToken.generate if uid.blank?
end

def generate_secret
return unless secret.blank?
return if secret.present?

renew_secret
end
Expand Down Expand Up @@ -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.
#
Expand All @@ -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.
#
Expand Down

0 comments on commit 6fcecf3

Please sign in to comment.