class JWT::Encode

The Encode class is responsible for encoding JWT tokens.

Public Class Methods

new(options) click to toggle source

Initializes a new Encode instance.

@param options [Hash] the options for encoding the JWT token. @option options [Hash] :payload the payload of the JWT token. @option options [Hash] :headers the headers of the JWT token. @option options [String] :key the key used to sign the JWT token. @option options [String] :algorithm the algorithm used to sign the JWT token.

# File lib/jwt/encode.rb, line 15
def initialize(options)
  @token     = Token.new(payload: options[:payload], header: options[:headers])
  @key       = options[:key]
  @algorithm = options[:algorithm]
end

Public Instance Methods

segments() click to toggle source

Encodes the JWT token and returns its segments.

@return [String] the encoded JWT token.

# File lib/jwt/encode.rb, line 24
def segments
  @token.verify_claims!(:numeric)
  @token.sign!(algorithm: @algorithm, key: @key)
  @token.jwt
end