Created
January 16, 2018 23:03
-
-
Save brainded/cebff40d9a8bd3e66bf4e26e88dd3322 to your computer and use it in GitHub Desktop.
Mode White-Label Embed Token Security
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Globalization; | |
using System.Text.RegularExpressions; | |
using System.Text; | |
using System.Security.Cryptography; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
//https://help.modeanalytics.com/articles/setting-up-white-label-embeds/ | |
string accessKey = "abcd"; | |
string accessSecret = "1234"; | |
string timestamp = "1000"; | |
var url = "https://modeanalytics.com/demo/reports/aaabbcccddd/embed?access_key=abcd&max_age=3600¶m_foo=bar×tamp=1000"; | |
var request = string.Join(",", new string[] { "GET", "", "1B2M2Y8AsgTpgAmY7PhCfg==", url, timestamp }); | |
var signature = HashHmac(request, accessSecret); | |
var signedUrl = string.Format("{0}&signature={1}", url, signature); | |
Console.WriteLine(signedUrl); | |
} | |
public static string HashHmac(string value, string secret) | |
{ | |
byte[] valueByteArray = Encoding.ASCII.GetBytes(value); | |
byte[] secretByteArray = Encoding.ASCII.GetBytes(secret); | |
using (var hmacSha256 = new HMACSHA256(secretByteArray)) | |
{ | |
var hashedValue = hmacSha256.ComputeHash(valueByteArray); | |
return BitConverter.ToString(hashedValue).ToLower().Replace("-", string.Empty); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment