The answers below are missing:
After successfully logging in, Facebook recommends that you confirm that the cookies are in fact legitimate and placed on the client machine.
Here are two methods that you can use together to solve this problem. You might want to add the IsValidFacebookSignature method to the calebt utility class. Notice that I also changed the GetFacebookCookie method a bit.
private bool IsValidFacebookSignature() { //keys must remain in alphabetical order string[] keyArray = { "expires", "session_key", "ss", "user" }; string signature = ""; foreach (string key in keyArray) signature += string.Format("{0}={1}", key, GetFacebookCookie(key)); signature += SecretKey; //your secret key issued by FB MD5 md5 = MD5.Create(); byte[] hash = md5.ComputeHash(Encoding.UTF8.GetBytes(signature.Trim())); StringBuilder sb = new StringBuilder(); foreach (byte hashByte in hash) sb.Append(hashByte.ToString("x2", CultureInfo.InvariantCulture)); return (GetFacebookCookie("") == sb.ToString()); } private string GetFacebookCookie(string cookieName) { //APIKey issued by FB string fullCookie = string.IsNullOrEmpty(cookieName) ? ApiKey : ApiKey + "_" + cookieName; return Request.Cookies[fullCookie].Value; }
The SecretKey and ApiKey are the values โโprovided to you by Facebook. In this case, these values โโshould be set, preferably from the .config file.
nikmd23 Jun 03 '09 at 2:34 2009-06-03 02:34
source share