Module: Doorkeeper::DeviceAuthorizationGrant::DeviceGrantMixin::ClassMethods
- Defined in:
- lib/doorkeeper/device_authorization_grant/orm/active_record/device_grant_mixin.rb
Overview
ClassMethods
Instance Method Summary collapse
-
#fallback_secret_strategy ⇒ Object
Determine the fallback storing strategy Unless configured, there will be no fallback.
-
#find_by_fallback_device_code(plain_secret) ⇒ Doorkeeper::DeviceAuthorizationGrant::DeviceGrant?
Allow looking up previously plain device codes as a fallback IFF a fallback strategy has been defined.
-
#find_by_plaintext_device_code(device_code) ⇒ Doorkeeper::DeviceAuthorizationGrant::DeviceGrant?
(also: #by_device_code)
Returns an instance of the DeviceGrant with specific device code value.
-
#secret_strategy ⇒ Object
Determines the secret storing transformer Unless configured otherwise, uses the plain secret strategy.
-
#upgrade_fallback_value(instance, plain_secret) ⇒ Object
Allows to replace a plain value fallback, 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
103 104 105 |
# File 'lib/doorkeeper/device_authorization_grant/orm/active_record/device_grant_mixin.rb', line 103 def fallback_secret_strategy ::Doorkeeper.configuration.token_secret_fallback_strategy end |
#find_by_fallback_device_code(plain_secret) ⇒ Doorkeeper::DeviceAuthorizationGrant::DeviceGrant?
Allow looking up previously plain device codes as a fallback IFF a fallback strategy has been defined
73 74 75 76 77 78 79 80 81 |
# File 'lib/doorkeeper/device_authorization_grant/orm/active_record/device_grant_mixin.rb', line 73 def find_by_fallback_device_code(plain_secret) return nil unless fallback_secret_strategy # Use the previous strategy to look up stored_code = fallback_secret_strategy.transform_secret(plain_secret) find_by(device_code: stored_code).tap do |resource| upgrade_fallback_value(resource, plain_secret) if resource end end |
#find_by_plaintext_device_code(device_code) ⇒ Doorkeeper::DeviceAuthorizationGrant::DeviceGrant? Also known as: by_device_code
Returns an instance of the DeviceGrant with specific device code value.
58 59 60 61 62 63 |
# File 'lib/doorkeeper/device_authorization_grant/orm/active_record/device_grant_mixin.rb', line 58 def find_by_plaintext_device_code(device_code) device_code = device_code.to_s find_by(device_code: secret_strategy.transform_secret(device_code)) || find_by_fallback_device_code(device_code) end |
#secret_strategy ⇒ Object
Determines the secret storing transformer Unless configured otherwise, uses the plain secret strategy
97 98 99 |
# File 'lib/doorkeeper/device_authorization_grant/orm/active_record/device_grant_mixin.rb', line 97 def secret_strategy ::Doorkeeper.configuration.token_secret_strategy end |
#upgrade_fallback_value(instance, plain_secret) ⇒ Object
Allows to replace a plain value fallback, to avoid it remaining as plain text.
89 90 91 92 93 |
# File 'lib/doorkeeper/device_authorization_grant/orm/active_record/device_grant_mixin.rb', line 89 def upgrade_fallback_value(instance, plain_secret) upgraded = secret_strategy.store_secret(instance, :device_code, plain_secret) instance.update(device_code: upgraded) end |