Class: MaticJWT::Generator
- Inherits:
-
Object
- Object
- MaticJWT::Generator
- Defined in:
- lib/matic-jwt/generator.rb
Instance Method Summary collapse
- #authentication_header_for(client_name, secret, payload = {}) ⇒ Object
-
#initialize(expiration: EXPIRATION, scheme: SCHEME) ⇒ Generator
constructor
A new instance of Generator.
- #token_for(client_name, secret, payload = {}) ⇒ Object
Constructor Details
#initialize(expiration: EXPIRATION, scheme: SCHEME) ⇒ Generator
Returns a new instance of Generator.
3 4 5 6 |
# File 'lib/matic-jwt/generator.rb', line 3 def initialize(expiration: EXPIRATION, scheme: SCHEME) @expiration = expiration @scheme = scheme end |
Instance Method Details
#authentication_header_for(client_name, secret, payload = {}) ⇒ Object
13 14 15 16 |
# File 'lib/matic-jwt/generator.rb', line 13 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
8 9 10 11 |
# File 'lib/matic-jwt/generator.rb', line 8 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 |