Module: Doorkeeper::Models::SecretStorable::ClassMethods

Defined in:
lib/doorkeeper/models/concerns/secret_storable.rb

Overview

:nodoc

Instance Method Summary collapse

Instance Method Details

#fallback_secret_strategyObject

Determine the fallback storing strategy Unless configured, there will be no fallback


100
101
102
# File 'lib/doorkeeper/models/concerns/secret_storable.rb', line 100

def fallback_secret_strategy
  nil
end

#find_by_fallback_token(attr, plain_secret) ⇒ Doorkeeper::AccessToken?

Allow looking up previously plain tokens as a fallback IFF a fallback strategy has been defined

Parameters:

  • attr (Symbol)

    The token attribute we're looking with.

  • plain_secret (#to_s)

    plain secret value (any object that responds to `#to_s`)

Returns:


61
62
63
64
65
66
67
68
69
70
71
# File 'lib/doorkeeper/models/concerns/secret_storable.rb', line 61

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

#find_by_plaintext_token(attr, token) ⇒ Doorkeeper::AccessToken?

Returns an instance of the Doorkeeper::AccessToken with specific token value.

Parameters:

  • attr (Symbol)

    The token attribute we're looking with.

  • token (#to_s)

    token value (any object that responds to `#to_s`)

Returns:


42
43
44
45
46
47
# File 'lib/doorkeeper/models/concerns/secret_storable.rb', line 42

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

#secret_matches?Boolean

Compare the given plaintext with the secret

Parameters:

  • input (String)

    The plain input to compare.

  • secret (String)

    The secret value to compare with.

Returns:

  • (Boolean)

    Whether input matches secret as per the secret strategy


28
# File 'lib/doorkeeper/models/concerns/secret_storable.rb', line 28

delegate :secret_matches?, to: :secret_strategy

#secret_strategyObject

Determines the secret storing transformer Unless configured otherwise, uses the plain secret strategy


93
94
95
# File 'lib/doorkeeper/models/concerns/secret_storable.rb', line 93

def secret_strategy
  ::Doorkeeper::SecretStoring::Plain
end

#upgrade_fallback_value(instance, attr, plain_secret) ⇒ Object

Allow implementations in ORMs to replace a plain value falling back to to avoid it remaining as plain text.

Parameters:

  • instance

    An instance of this model with a plain value token.

  • attr

    The secret attribute name to upgrade.

  • plain_secret

    The plain secret to upgrade.


85
86
87
88
# File 'lib/doorkeeper/models/concerns/secret_storable.rb', line 85

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