public FacebookInstance GetInstance(FacebookConfigElement elem, NameValueCollection paramCollection) { string signed_request = paramCollection["signed_request"].Default().DecodeUrl(); FacebookInstance instance = null; string json = null; if (!signed_request.isEmpty()) { #region check the signature of the signed request string hash = signed_request.Part('.', 0).Decode64(); json = signed_request.Part('.', 1).Decode64(); string evidence = signed_request.Part('.', 1).HashForKey(elem.appSecret); if (hash.NotEquals(evidence)) throw new FormatException("Invalid Signature"); #endregion } instance = new FacebookInstance(elem, json); instance.HttpParameters = paramCollection.ToDictionary(); return instance; }
internal FacebookInstance(FacebookConfigElement elem, string json=null) { Connected = false; page = new Page(null); user = new User(null); HttpParameters = new Dictionary<string,string>(); AppId = elem.appId; AppName = elem.key; AdminId = elem.adminId; PageId = elem.pageId; PageName = elem.pageName; PageUrl = elem.pageUrl; if (json != null) { JavaScriptSerializer jss = new JavaScriptSerializer(); jss.RegisterConverters(new JavaScriptConverter[] { new DynamicJsonConverter() }); var fb = jss.Deserialize(json, typeof(object)) as dynamic; string code = fb.algorithm; if (code.NotEquals("HMAC-SHA256")) throw new ArgumentException("Expected HMAC-SHA256"); Connected = true; try { app_data = fb.app_data; } catch { } algorithm = fb.algorithm; try { expires = fb.expires.ToString(); } catch { } issued_at = fb.issued_at.ToString(); try { oauth_token = fb.oauth_token; } catch { } page = new Page(fb.page); user = new User(fb); } }
protected override object GetElementKey(ConfigurationElement element) { FacebookConfigElement obj = (FacebookConfigElement)element; return(obj.key); }