function encodeJwt_(payload, key) {
  var header = {
    alg: 'RS256',
    typ: 'JWT'
  };
  var toSign = Utilities.base64EncodeWebSafe(JSON.stringify(header)) + '.' +
      Utilities.base64EncodeWebSafe(JSON.stringify(payload));
  var signatureBytes =
      Utilities.computeRsaSha256Signature(toSign, key);
  var signature = Utilities.base64EncodeWebSafe(signatureBytes);
  return toSign + '.' + signature;
}
Encodes and signs a JWT.

@param {Object} payload The JWT payload.
@param {string} key The key to use when generating the signature.
@return {string} The encoded and signed JWT.