Class: MaticJWT::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/matic-jwt/generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(expiration: EXPIRATION, scheme: SCHEME) ⇒ Generator

Returns a new instance of Generator.



5
6
7
8
# File 'lib/matic-jwt/generator.rb', line 5

def initialize(expiration: EXPIRATION, scheme: SCHEME)
  @expiration = expiration
  @scheme = scheme
end

Instance Method Details

#authentication_header_for(client_name, secret, payload = {}) ⇒ Object



15
16
17
18
# File 'lib/matic-jwt/generator.rb', line 15

def authentication_header_for(client_name, secret, payload = {})
  token = token_for(client_name, secret, payload)
  "#{@scheme} #{token}"
end

#token_for(client_name, secret, payload = {}) ⇒ Object



10
11
12
13
# File 'lib/matic-jwt/generator.rb', line 10

def token_for(client_name, secret, payload = {})
  jwt_payload = payload.merge(client_name: client_name, exp: @expiration.since.to_i)
  JWT.encode(jwt_payload, secret, ALGORITHM)
end