module Doorkeeper::Models::SecretStorable::ClassMethods

def fallback_secret_strategy

Unless configured, there will be no fallback
Determine the fallback storing strategy
#
def fallback_secret_strategy
  nil
end

def find_by_fallback_token(attr, plain_secret)

Returns:
  • (Doorkeeper::AccessToken, nil) - AccessToken object or nil

Parameters:
  • plain_secret (#to_s) --
  • attr (Symbol) --
def find_by_fallback_token(attr, plain_secret)
  return nil unless fallback_secret_strategy
  # Use the previous strategy to look up
  stored_token = fallback_secret_strategy.transform_secret(plain_secret)
  find_by(attr => stored_token).tap do |resource|
    return nil unless resource
    upgrade_fallback_value resource, attr, plain_secret
  end
end

def find_by_plaintext_token(attr, token)

Returns:
  • (Doorkeeper::AccessToken, nil) - AccessToken object or nil

Parameters:
  • token (#to_s) --
  • attr (Symbol) --
def find_by_plaintext_token(attr, token)
  token = token.to_s
  find_by(attr => secret_strategy.transform_secret(token)) ||
    find_by_fallback_token(attr, token)
end

def secret_strategy

Unless configured otherwise, uses the plain secret strategy
Determines the secret storing transformer
#
def secret_strategy
  ::Doorkeeper::SecretStoring::Plain
end

def upgrade_fallback_value(instance, attr, plain_secret)

Parameters:
  • plain_secret () --
  • attr () --
  • instance () --
def upgrade_fallback_value(instance, attr, plain_secret)
  upgraded = secret_strategy.store_secret(instance, attr, plain_secret)
  instance.update(attr => upgraded)
end