lib/matic-jwt/generator.rb in matic-jwt-1.1.0 vs lib/matic-jwt/generator.rb in matic-jwt-1.2.0

- old
+ new

@@ -1,17 +1,18 @@ module MaticJWT class Generator - def initialize(expiration: EXPIRATION) + def initialize(expiration: EXPIRATION, scheme: SCHEME) @expiration = expiration + @scheme = scheme end - def token_for(client_name, secret) - payload = {client_name: client_name, exp: @expiration.since.to_i} - JWT.encode(payload, secret, ALGORITHM) + 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 - def authentication_header_for(client_name, secret, scheme: SCHEME) - token = token_for(client_name, secret) - "#{scheme} #{token}" + def authentication_header_for(client_name, secret, payload = {}) + token = token_for(client_name, secret, payload) + "#{@scheme} #{token}" end end end