Class: ApiEngineBase::Jwt::Decode

Inherits:
ServiceBase show all
Defined in:
app/services/api_engine_base/jwt/decode.rb

Constant Summary

Constants inherited from ServiceBase

ServiceBase::ON_ARGUMENT_VALIDATION

Instance Method Summary collapse

Methods inherited from ServiceBase

inherited, #internal_validate, #service_base_logging, #validate!

Methods included from ArgumentValidation

included

Methods included from ServiceLogging

#aletered_message, #class_name, #log, #log_error, #log_info, #log_prefix, #log_warn, #logger, #service_id

Instance Method Details

#callObject



10
11
12
13
14
15
16
17
18
19
# File 'app/services/api_engine_base/jwt/decode.rb', line 10

def call
  data = JWT.decode(token, ApiEngineBase.config.jwt.hmac_secret, true, { algorithm: "HS256" })

  context.payload = data[0].with_indifferent_access
  context.headers = data[1].with_indifferent_access
rescue JWT::DecodeError => e
  log_error(e)

  context.fail!(msg: "Invalid Token")
end