Last active
February 3, 2017 15:11
-
-
Save johnkors/3cdb64df3f2f9be5180181a9b6cfb3fc to your computer and use it in GitHub Desktop.
Validation of Discourse SSO payload
This file contains hidden or 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
private static bool IsValid(string encodedPayload, string signature) | |
{ | |
return Hash(DISCOURSE_SECRET, encodedPayload) == signature; | |
} | |
private static string Hash(string secret, string encodedPayload) | |
{ | |
var hasher = new HMACSHA256(Encoding.UTF8.GetBytes(secret)); | |
var hash = hasher.ComputeHash(Encoding.UTF8.GetBytes(encodedPayload)); | |
return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment