Class: TokenAuthenticatableStrategies::Digest
- Defined in:
- app/models/concerns/token_authenticatable_strategies/digest.rb
Instance Attribute Summary
Attributes inherited from Base
#klass, #options, #token_field
Instance Method Summary collapse
- #find_token_authenticatable(token, unscoped = false) ⇒ Object
- #get_token(instance) ⇒ Object
- #set_token(instance, token) ⇒ Object
Methods inherited from Base
#ensure_token, #ensure_token!, fabricate, #initialize, #reset_token!
Constructor Details
This class inherits a constructor from TokenAuthenticatableStrategies::Base
Instance Method Details
#find_token_authenticatable(token, unscoped = false) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'app/models/concerns/token_authenticatable_strategies/digest.rb', line 5 def find_token_authenticatable(token, unscoped = false) return unless token token_authenticatable = relation(unscoped).find_by(token_field_name => Gitlab::CryptoHelper.sha256(token)) if @options[:fallback] token_authenticatable ||= fallback_strategy.find_token_authenticatable(token) end token_authenticatable end |
#get_token(instance) ⇒ Object
17 18 19 20 21 22 |
# File 'app/models/concerns/token_authenticatable_strategies/digest.rb', line 17 def get_token(instance) token = instance.cleartext_tokens&.[](@token_field) token ||= fallback_strategy.get_token(instance) if @options[:fallback] token end |
#set_token(instance, token) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'app/models/concerns/token_authenticatable_strategies/digest.rb', line 24 def set_token(instance, token) return unless token instance.cleartext_tokens ||= {} instance.cleartext_tokens[@token_field] = token instance[token_field_name] = Gitlab::CryptoHelper.sha256(token) instance[@token_field] = nil if @options[:fallback] end |