Class: ConsoleUtils::RequestUtils::SimpleTokenAutomator

Inherits:
Object
  • Object
show all
Defined in:
lib/console_utils/request_utils/auth_automators.rb

Class Method Summary collapse

Class Method Details

.call(rq) ⇒ Object


11
12
13
14
15
16
17
18
19
# File 'lib/console_utils/request_utils/auth_automators.rb', line 11

def self.call(rq)
  if rq.can_auto_auth?
    model_key = ConsoleUtils.user_model.model_name.param_key
    header_names = ::SimpleTokenAuthentication.header_names[model_key.to_sym]
    fields = header_names.keys
    user = ConsoleUtils.find_user(rq.uid, scope: ConsoleUtils.user_model.select(:id, *fields))
    header_names.each { |field, name| rq.headers[name] ||= user.public_send(field) }
  end
end