class Nexmo::JWT
Public Class Methods
generate(payload, private_key = nil)
click to toggle source
Generate an encoded JSON
Web Token.
By default the Nexmo
Ruby SDK generates a short lived JWT
per request.
To generate a long lived JWT
for multiple requests or to specify JWT
claims directly call {Nexmo::JWT.generate} to generate a token, and set the token attribute on the client object.
Documentation for the Nexmo
Ruby JWT
generator gem can be found at www.rubydoc.info/github/nexmo/nexmo-jwt-ruby
@example
claims = { application_id: application_id, ttl: 800, subject: 'My_Subject' } private_key = File.read('path/to/private.key') client.config.token = Nexmo::JWT.generate(claims, private_key)
@param [Hash] payload @param [String, OpenSSL::PKey::RSA] private_key
@return [String]
# File lib/nexmo/jwt.rb, line 36 def self.generate(payload, private_key = nil) raise "Expecting 'private_key' in either the payload or as a separate parameter" if !payload[:private_key] && !private_key payload[:private_key] = private_key if private_key && !payload[:private_key] @token = Nexmo::JWTBuilder.new(payload).jwt.generate end