Module: LatoCore::Interface::Token
- Included in:
- LatoCore::Interface
- Defined in:
- lib/lato_core/interfaces/token.rb
Overview
This module contains a list of functions used to manage tokens. All functions on the module depends on ‘jwt’ gem.
Instance Method Summary collapse
-
#core__decode_token(token) ⇒ Object
This function return the payload of a token.
-
#core__encode_token(exp, payload) ⇒ Object
This functon return a token with encrypted payload information.
Instance Method Details
#core__decode_token(token) ⇒ Object
This function return the payload of a token.
15 16 17 18 19 20 21 22 23 |
# 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) ⇒ Object
This functon return a token with encrypted payload information.
8 9 10 11 12 |
# 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 |