Class: Funneler::TokenHandler

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

Class Method Summary collapse

Class Method Details

.extract_data_from(token) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/funneler/token_handler.rb', line 19

def extract_data_from(token)
  key = Funneler.configuration.jwt_key
  algorithm = Funneler.configuration.jwt_algorithm
  verify = (algorithm != nil || key != nil)
  data, _ = JWT.decode(token, key, verify, algorithm: algorithm)
  data
end

.generate_token(data:, expires_in_days: nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/funneler/token_handler.rb', line 6

def generate_token(data:, expires_in_days: nil)
  key = Funneler.configuration.jwt_key
  algorithm = Funneler.configuration.jwt_algorithm

  expires_in_days ||= Funneler.configuration.expires_in_days
  if expires_in_days
    expiration = Time.now + (expires_in_days * 24 * 60 * 60)
    data = { exp: expiration.to_i }.merge(data)
  end

  JWT.encode(data, key, algorithm)
end