Class: CrazyTrain::JWT

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

Constant Summary collapse

HEADERS =
{ 'alg' => 'HS256', 'typ' => 'JWT' }.freeze

Class Method Summary collapse

Class Method Details

.decode(token, secret = CrazyTrain.config.secret) ⇒ Object



9
10
11
# File 'lib/crazy_train/jwt.rb', line 9

def self.decode(token, secret = CrazyTrain.config.secret)
  ::JWT.decode(token, secret, true, HEADERS)
end

.encode(payload, secret = CrazyTrain.config.secret) ⇒ Object



5
6
7
# File 'lib/crazy_train/jwt.rb', line 5

def self.encode(payload, secret = CrazyTrain.config.secret)
  ::JWT.encode(payload, secret, 'HS256', HEADERS)
end

.generate_jwt_secretObject



18
19
20
# File 'lib/crazy_train/jwt.rb', line 18

def self.generate_jwt_secret
  SecureRandom.alphanumeric(32)
end

.generate_token(payload_string) ⇒ Object



13
14
15
16
# File 'lib/crazy_train/jwt.rb', line 13

def self.generate_token(payload_string)
  payload = JSON.parse(payload_string || '{}')
  encode(payload)
end