Class: JsonWebToken

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

Class Method Summary collapse

Class Method Details

.decode(token) ⇒ Object


10
11
12
13
14
15
16
17
# File 'lib/json_web_token.rb', line 10

def self.decode(token)
  begin
    payload =JWT.decode(token, Rails.application.secrets.secret_key_base, false)
    return HashWithIndifferentAccess.new(payload[0])
  rescue
    nil
  end
end

.encode(payload, expiration = 2500.hours.from_now) ⇒ Object


5
6
7
8
# File 'lib/json_web_token.rb', line 5

def self.encode(payload, expiration = 2500.hours.from_now)
  payload['exp'] = expiration.to_i # Set expiration to 24 hours.
  JWT.encode(payload, Rails.application.secrets.secret_key_base, 'none')
end