module LatoCore::Interface::Token

This module contains a list of functions used to manage tokens. All functions on the module depends on 'jwt' gem.

Public Instance Methods

core__decode_token(token) click to toggle source

This function return the payload of a token.

# File lib/lato_core/interfaces/token.rb, line 15
def core__decode_token token
  begin
    body = JWT.decode(token, Rails.application.secrets.secret_key_base,
                      true, algorithm: 'HS256')[0]
    return HashWithIndifferentAccess.new body
  rescue => exception
    return nil
  end
end
core__encode_token(exp, payload) click to toggle source

This functon return a token with encrypted payload information.

# File lib/lato_core/interfaces/token.rb, line 8
def core__encode_token exp, payload
  exp = 1.day.from_now unless exp
  payload[:exp] = exp.to_i
  JWT.encode(payload, Rails.application.secrets.secret_key_base, 'HS256')
end