Sha256: af84a2ee3a03b7594a54027f0303e835843235011a00e7427312025159e8aa8f

Contents?: true

Size: 783 Bytes

Versions: 4

Compression:

Stored size: 783 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
      JWT.encode(payload, Rails.application.secrets.secret_key_base, 'HS256')
    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,
                          true, algorithm: 'HS256')[0]
        return HashWithIndifferentAccess.new body
      rescue => exception
        return nil
      end
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lato_core-2.2.2 lib/lato_core/interfaces/token.rb
lato_core-2.2.0 lib/lato_core/interfaces/token.rb
lato_core-2.1.4 lib/lato_core/interfaces/token.rb
lato_core-2.1.3 lib/lato_core/interfaces/token.rb