-
-
Save darkpssngr/726162ed0bd67ffdd616370c65a17e68 to your computer and use it in GitHub Desktop.
SSO Login for Freshdesk support portal - ASP.Net C# Sample Code
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
static string GetSsoUrl(string baseUrl, string secret, string name, string email) { | |
var timems = (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds.ToString(); | |
return String.Format("{0}/login/sso?name={1}&email={2}×tamp={3}&hash={4}", | |
baseUrl, Server.UrlEncode(name), Server.UrlEncode(email), timems, GetHash(secret, name, email, timems)); | |
} | |
private static string GetHash(string secret, string name, string email, string timems) { | |
var input = name + secret + email + timems; | |
var keybytes = Encoding.UTF8.GetBytes(secret); | |
var inputBytes = Encoding.UTF8.GetBytes(input); | |
var crypto = new HMACMD5(keybytes); | |
var hash = crypto.ComputeHash(inputBytes); | |
return hash.Select(b => b.ToString("x2")) | |
.Aggregate(new StringBuilder(), | |
(current, next) => current.Append(next), | |
current => current.ToString()); | |
} |
Can you update the code to say 'seconds' or 'times' instead of 'timems'? I was thinking it was supposed to be in milliseconds because of the variable name. You could use DateTimeOffset.UtcNow.ToUnixTimeSeconds()
instead of doing the date math...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@CGijbels Updated the gist. Thanks :)