Class: RailsBase::Authentication::SessionTokenVerifier

Inherits:
ServiceBase
  • Object
show all
Defined in:
app/services/rails_base/authentication/session_token_verifier.rb

Instance Method Summary collapse

Methods inherited from ServiceBase

inherited, #internal_validate, #service_base_logging, #validate!

Methods included from ServiceLogging

#aletered_message, #class_name, #log, #log_prefix, #logger, #service_id

Instance Method Details

#callObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/services/rails_base/authentication/session_token_verifier.rb', line 8

def call
  if mfa_randomized_token.nil?
    context.fail!(message: "Authorization token not present. Please Log in")
  end

  decoded = RailsBase::Encryption.decode(value: mfa_randomized_token, purpose: purpose || Constants::MSET_PURPOSE)
  if decoded.nil?
    context.fail!(message: "Authorization token has expired. Please Log in")
  end

  begin
    json_decoded = JSON.parse(decoded)
  rescue StandardError => e
    log(level: :fatal, msg: "Json parse error. [#{decoded}] could not be parsed.")
    context.fail!(message: "Authorization token has failed. Please Log in")
  end

  log(level: :info, msg: "Decoded message: #{json_decoded}")

  context.user_id = json_decoded['user_id']
  context.expires_at = json_decoded['expires_at']
end