Skip to content

Instantly share code, notes, and snippets.


pcolombo/gist:dbbea020618c521a2bd5 Secret

Last active Aug 29, 2015
What would you like to do?
Using JWT to generate a livefyre collection meta jwt token
using Newtonsoft.Json;
using PROJECT.Web.Models;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Dynamic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Web;
namespace PROJECT.Web.Helpers
public class LivefyreHelper
public static String GetNetwork()
return ConfigurationManager.AppSettings["livefyreNetwork"];
public static String GetSiteId()
return ConfigurationManager.AppSettings["livefyreSiteId"];
public static String GetSiteSecret()
return ConfigurationManager.AppSettings["livefyreSecretKey"];
public static String GetCollectionToken(String ID, MetaInfo metaInfo)
string siteSecret = GetSiteSecret();
var meta = new Dictionary<string, object>() {
{"title", metaInfo.Title},
{"url", metaInfo.Url},
{"tags", ""},
{"type", "livecomments"}
var metaStr = JsonConvert.SerializeObject(meta);
byte[] hash;
using (var md5 = MD5.Create())
hash = md5.ComputeHash(Encoding.UTF8.GetBytes(metaStr));
StringBuilder sBuilder = new StringBuilder();
// Loop through each byte of the hashed data
// and format each one as a hexadecimal string.
for (int i = 0; i < hash.Length; i++)
meta.Add("articleId", ID);
string token = JWT.JsonWebToken.Encode(meta, siteSecret, JWT.JwtHashAlgorithm.HS256);
return token;

This comment has been minimized.

Copy link
Owner Author

@pcolombo pcolombo commented Feb 24, 2015

Updated on 2/24/15 with correct meta.Add

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment