Class: Commons::Authentication::JSONWebToken

Inherits:
Object
  • Object
show all
Defined in:
lib/commons/authentication/json_web_token.rb

Constant Summary collapse

SECRET_KEY =
Commons.secret_key_base.to_s

Class Method Summary collapse

Class Method Details

.decode(token) ⇒ Object



11
12
13
14
# File 'lib/commons/authentication/json_web_token.rb', line 11

def self.decode(token)
  decoded = JWT.decode(token, SECRET_KEY)[0]
  HashWithIndifferentAccess.new decoded
end

.encode(payload, exp = 24.hours.from_now) ⇒ Object



6
7
8
9
# File 'lib/commons/authentication/json_web_token.rb', line 6

def self.encode(payload, exp = 24.hours.from_now)
  payload[:expires_at] = exp.to_i
  JWT.encode(payload, SECRET_KEY)
end