Class: TokenAuthenticatableStrategies::Digest
- Inherits:
-
Base
- Object
- Base
- TokenAuthenticatableStrategies::Digest
show all
- 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
Methods inherited from Base
#ensure_token, #ensure_token!, #expirable?, #expired?, #expires_at, fabricate, #format_token, #initialize, #reset_token!, #token_with_expiration
Instance Method Details
#find_token_authenticatable(token, unscoped = false) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
|
# File 'app/models/concerns/token_authenticatable_strategies/digest.rb', line 9
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
21
22
23
24
25
26
|
# File 'app/models/concerns/token_authenticatable_strategies/digest.rb', line 21
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
28
29
30
31
32
33
34
35
|
# File 'app/models/concerns/token_authenticatable_strategies/digest.rb', line 28
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
|
#token_fields ⇒ Object
5
6
7
|
# File 'app/models/concerns/token_authenticatable_strategies/digest.rb', line 5
def token_fields
super + [token_field_name]
end
|