Skip to content

Instantly share code, notes, and snippets.

@kellyelton
Created February 2, 2014 23:01
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kellyelton/8776309 to your computer and use it in GitHub Desktop.
Save kellyelton/8776309 to your computer and use it in GitHub Desktop.
Freshdesk c# sso /w timestamp
public ActionResult HelpLogin()
{
const string key = "abcdefghijklmnopqrtuvwxyz";
const string pathTemplate = "http://demo.freshdesk.com/login/sso?name={0}&email={1}&timestamp={2}&hash={3}";
var username = UserHelper.CurrentUser.UserName;
var email = UserHelper.CurrentUser.Email;
string timems = (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds.ToString();
var hash = GetHash(key, username, email, timems);
var path = String.Format(pathTemplate, Server.UrlEncode(username), Server.UrlEncode(email), timems, hash);
return Redirect(path);
}
private static string GetHash(string secret, string name, string email, string timems)
{
string input = name + email + timems;
var keybytes = Encoding.Default.GetBytes(secret);
var inputBytes = Encoding.Default.GetBytes(input);
var crypto = new HMACMD5(keybytes);
byte[] hash = crypto.ComputeHash(inputBytes);
StringBuilder sb = new StringBuilder();
foreach (byte b in hash)
{
string hexValue = b.ToString("X").ToLower(); // Lowercase for compatibility on case-sensitive systems
sb.Append((hexValue.Length == 1 ? "0" : "") + hexValue);
}
return sb.ToString();
}
@42degrees
Copy link

@kirandarisi, I wish there was a way for me to change this gist but gist.github doesn't allow pull requests, the only choice is to fork it, which @darkpssngr has already done (using my code sample and others).

darkpssngr's fork: https://gist.github.com/darkpssngr/726162ed0bd67ffdd616370c65a17e68

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