def encode(token_body = {}, algorithm = nil)
    token_body[:aud] = @options[:audience_ids] if @options[:audience_ids] && !token_body[:aud] && !token_body['aud']
    token_body[:exp] = Time.now.to_i + 7 * 24 * 60 * 60 unless token_body[:exp] || token_body['exp']
    self.class.encode(token_body, algorithm ? @options.merge(:algorithm => algorithm) : @options)
  end
def encode(token_body = {}, algorithm = nil)
    token_body[:aud] = @options[:audience_ids] if @options[:audience_ids] && !token_body[:aud] && !token_body['aud']
    token_body[:exp] = Time.now.to_i + 7 * 24 * 60 * 60 unless token_body[:exp] || token_body['exp']
    self.class.encode(token_body, algorithm ? @options.merge(:algorithm => algorithm) : @options)
  end
Creates a new token en/decoder for a service that is associated with
 the the audience_ids, the symmetrical token validation key, and the
 public and/or private keys.
 @param [Hash] options Supported options:
   * :audience_ids [Array<String>, String] -- An array or space separated
     string of values which indicate the token is intended for this service
     instance. It will be compared with tokens as they are decoded to ensure
     that the token was intended for this audience.
   * :skey [String] -- used to sign and validate tokens using symmetrical
     key algoruthms
   * :pkey [String, File, OpenSSL::PKey::PKey] -- may be a String or File in
     PEM or DER formats. May include public and/or private key data. The
     private key is used to sign tokens and the public key is used to
     validate tokens.
   * :algorithm [String] -- Sets default used for encoding. May be HS256,
     HS384, HS512, RS256, RS384, RS512, or none.
   * :verify [String] -- Verifies signatures when decoding tokens. Defaults
     to +true+.
   * :accept_algorithms [String, Array<String>] -- An Array or space separated
     string of values which list what algorthms are accepted for token
     signatures. Defaults to all possible values of :algorithm except 'none'.
 @note the TokenCoder instance must be configured with the appropriate
   key material to support particular algorithm families and operations
   -- i.e. :pkey must include a private key in order to sign tokens with
   the RS algorithms.
 Encode a JWT token. Takes a hash of values to use as the token body.
 Returns a signed token in JWT format (header, body, signature).
 @param token_body (see TokenCoder.encode)
 @param [String] algorithm -- overrides default. See {#initialize} for possible values.
 @return (see TokenCoder.encode)