Class: JwtManager

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

Constant Summary collapse

HS265 =
'HS256'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(secret_key_env_var_name = 'JWT_MANAGER_SHARED_SECRET') ⇒ JwtManager

Returns a new instance of JwtManager.



7
8
9
10
11
12
# File 'lib/jwt_manager.rb', line 7

def initialize(secret_key_env_var_name = 'JWT_MANAGER_SHARED_SECRET')
  if ENV[secret_key_env_var_name].nil?
    raise ArgumentError, 'JWT Shared secret not configured.'
  end
  @hmac_secret = ENV[secret_key_env_var_name]
end

Instance Method Details

#decode(token) ⇒ Object



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

def decode(token)
  JWT.decode(token, @hmac_secret, true, algorithm: HS265)
end

#encode(payload) ⇒ Object



14
15
16
# File 'lib/jwt_manager.rb', line 14

def encode(payload)
  JWT.encode(payload, @hmac_secret, HS265)
end