Class: Authn::TokenField::Digest

Inherits:
Base
  • Object
show all
Defined in:
lib/authn/token_field/digest.rb

Constant Summary

Constants inherited from Base

Base::TRUE_PROC

Instance Attribute Summary

Attributes inherited from Base

#expires_at_field, #klass, #options, #token_field

Instance Method Summary collapse

Methods inherited from Base

#ensure_token, #ensure_token!, #expirable?, #expired?, #expires_at, fabricate, #initialize, #relation, #reset_token!, #sensitive_fields, #token_with_expiration, #write_new_token

Constructor Details

This class inherits a constructor from Authn::TokenField::Base

Instance Method Details

#encode(token) ⇒ Object



20
21
22
# File 'lib/authn/token_field/digest.rb', line 20

def encode(token)
  Gitlab::CryptoHelper.sha256(token)
end

#find_token_authenticatable(token, unscoped = false) ⇒ Object



10
11
12
13
14
# File 'lib/authn/token_field/digest.rb', line 10

def find_token_authenticatable(token, unscoped = false)
  return unless token

  relation(unscoped).find_by(token_field_name => encode(token)) # rubocop:disable CodeReuse/ActiveRecord: -- This is meant to be used in AR models.
end

#get_token(token_owner_record) ⇒ Object



16
17
18
# File 'lib/authn/token_field/digest.rb', line 16

def get_token(token_owner_record)
  token_owner_record.cleartext_tokens&.[](token_field)
end

#set_token(token_owner_record, token) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/authn/token_field/digest.rb', line 24

def set_token(token_owner_record, token)
  return unless token

  token_owner_record.cleartext_tokens ||= {}
  token_owner_record.cleartext_tokens[token_field] = token
  token_owner_record[token_field_name] = encode(token)
end

#token_fieldsObject



6
7
8
# File 'lib/authn/token_field/digest.rb', line 6

def token_fields
  super + [token_field_name]
end