Sha256: deb993eade35b12fd8b53932fbc16b2a9993180f83a2eaec1bd6fadadd7a0deb

Contents?: true

Size: 728 Bytes

Versions: 3

Compression:

Stored size: 728 Bytes

Contents

module LatoCore

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

    # This functon return a token with encrypted payload information.
    def core__encode_token exp, payload
      exp = 1.day.from_now unless exp
      payload[:exp] = exp.to_i
      return JWT.encode(payload, Rails.application.secrets.secret_key_base)
    end

    # This function return the payload of a token.
    def core__decode_token token
      begin
        body = JWT.decode(token, Rails.application.secrets.secret_key_base)[0]
        return HashWithIndifferentAccess.new body
      rescue => exception
        return nil
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lato_core-2.1.2 lib/lato_core/interfaces/token.rb
lato_core-2.1.1 lib/lato_core/interfaces/token.rb
lato_core-2.1 lib/lato_core/interfaces/token.rb