Class: Reattract::JwtGenerator

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

Overview

Handles generation of JWTs

Constant Summary collapse

ALGO_HMAC_256 =
'HS256'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expired_at: default_exp, scopes: nil) ⇒ JwtGenerator

Returns a new instance of JwtGenerator.



12
13
14
15
# File 'lib/reattract/jwt_generator.rb', line 12

def initialize(expired_at: default_exp, scopes: nil)
  @expired_at = expired_at.to_i
  @scopes = scopes&.join(',')
end

Instance Attribute Details

#expired_atObject

Returns the value of attribute expired_at.



10
11
12
# File 'lib/reattract/jwt_generator.rb', line 10

def expired_at
  @expired_at
end

#scopesObject

Returns the value of attribute scopes.



10
11
12
# File 'lib/reattract/jwt_generator.rb', line 10

def scopes
  @scopes
end

Instance Method Details

#generateObject



17
18
19
# File 'lib/reattract/jwt_generator.rb', line 17

def generate
  JWT.encode payload, hmac_secret, algorithm
end