class Nexmo::JWT

Constants

VERSION

Attributes

generator[RW]
iat[RW]
typ[RW]

Public Class Methods

new(params = {}) click to toggle source
# File lib/nexmo-jwt/jwt.rb, line 7
def initialize(params = {})
  @generator = params.fetch(:generator)
  @typ = params.fetch(:typ, 'JWT')
  @iat = params.fetch(:iat, Time.now.to_i)
end

Public Instance Methods

generate() click to toggle source
# File lib/nexmo-jwt/jwt.rb, line 13
def generate
  ::JWT.encode(to_payload, generator.private_key, generator.alg)
end
to_payload() click to toggle source
# File lib/nexmo-jwt/jwt.rb, line 17
def to_payload
  hash = {
    iat: iat,
    jti: generator.jti,
    exp: generator.exp || iat + generator.ttl,
    sub: generator.subject,
    application_id: generator.application_id,
    typ: typ
  }
  hash.merge!(generator.paths) if generator.paths
  hash.merge!(nbf: generator.nbf) if generator.nbf
  hash
end