Class: CrazyTrain::JWT
- Inherits:
-
Object
- Object
- CrazyTrain::JWT
- Defined in:
- lib/crazy_train/jwt.rb
Constant Summary collapse
- HEADERS =
{ 'alg' => 'HS256', 'typ' => 'JWT' }.freeze
Class Method Summary collapse
- .decode(token, secret = CrazyTrain.config.secret) ⇒ Object
- .encode(payload, secret = CrazyTrain.config.secret) ⇒ Object
- .generate_jwt_secret ⇒ Object
- .generate_token(payload_string) ⇒ Object
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_secret ⇒ Object
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 |