Module: Doorkeeper::Models::SecretStorable::ClassMethods
- Defined in:
- lib/doorkeeper/models/concerns/secret_storable.rb
Overview
:nodoc
Instance Method Summary collapse
-
#fallback_secret_strategy ⇒ Object
Determine the fallback storing strategy Unless configured, there will be no fallback.
-
#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.
-
#find_by_plaintext_token(attr, token) ⇒ Doorkeeper::AccessToken?
Returns an instance of the Doorkeeper::AccessToken with specific token value.
-
#secret_matches? ⇒ Boolean
Compare the given plaintext with the secret.
-
#secret_strategy ⇒ Object
Determines the secret storing transformer Unless configured otherwise, uses the plain secret strategy.
-
#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.
Instance Method Details
#fallback_secret_strategy ⇒ Object
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
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.
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
28 |
# File 'lib/doorkeeper/models/concerns/secret_storable.rb', line 28 delegate :secret_matches?, to: :secret_strategy |
#secret_strategy ⇒ Object
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.
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 |