Module: Lab::JsonWebTokenService
- Defined in:
- app/services/lab/json_web_token_service.rb
Overview
This class is used to encode and decode the JWT token
Constant Summary collapse
- SECRET_KEY =
Rails.application.secrets.secret_key_base.to_s
Class Method Summary collapse
Class Method Details
.decode(token, request_ip) ⇒ Object
14 15 16 17 |
# File 'app/services/lab/json_web_token_service.rb', line 14 def decode(token, request_ip) decoded = JWT.decode(token, SECRET_KEY + request_ip)[0] HashWithIndifferentAccess.new decoded end |
.encode(payload, request_ip, exp = 18.hours.from_now) ⇒ Object
9 10 11 12 |
# File 'app/services/lab/json_web_token_service.rb', line 9 def encode(payload, request_ip, exp = 18.hours.from_now) payload[:exp] = exp.to_i JWT.encode(payload, SECRET_KEY + request_ip) end |