Beispiel #1
0
        /// <summary>
        /// OnLoad method
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLoad(EventArgs e) {
            string SignedRequest = HttpContext.Current.Request["signed_request"];
            if (SignedRequest == null) {
                throw new FacebookException("Cannot find Facebook POST data as expected. Make sure you're viewing this page in an Iframe Application Tab of a Facebook Page.");
            }
            data = Helpers.Generic.ParseSignedRequest(SignedRequest);

            if (data["oauth_token"] != null) {
                _Api = new GraphApi.Api((string)data["oauth_token"], Helpers.Generic.UnixTimestampToDateTime((int)data["expires"]));
            }

            base.OnLoad(e);
        }
Beispiel #2
0
        /// <summary>
        /// Event handler of 'OnInit' event
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLoad(EventArgs e) {
            if (!IsPostBack) {
                string SignedRequest = HttpContext.Current.Request["signed_request"];
                if (SignedRequest == null) {
                    throw new FacebookException("Cannot find Facebook POST data as expected. Make sure you're viewing this page in a Facebook Iframe Application.");
                }

                JsonObject JO = Helpers.Generic.ParseSignedRequest(SignedRequest);
                if (JO["user_id"] == null) IsAuthorized = false;
                else {
                    IsAuthorized = true;
                    _Api = new GraphApi.Api((string)JO["oauth_token"], Helpers.Generic.UnixTimestampToDateTime((int)JO["expires"]));

                    Page.Cache["GraphApi"] = _Api;
                }
                UserData = new BasicUserData((JsonObject)JO["user"]);
            } else {
                _Api = (GraphApi.Api)Page.Cache["GraphApi"];
            }

            bool RedirectForExtendedPermission = false;
            if (_Api != null&&CheckExtendedPermissions&&!string.IsNullOrEmpty(ExtendedPermissions.Trim())) {
                JsonArray JA = _Api.Fql(string.Format("SELECT {0} FROM permissions WHERE uid = me()",ExtendedPermissions));
                JsonObject JO = JA.JsonObjects[0];
                foreach (KeyValuePair<string, object> KVP in JO.Properties) {
                    if ((int)KVP.Value == 0) {
                        RedirectForExtendedPermission = true;
                        break;
                    }
                }
            }

            if ((_Api==null && RequireLogin)||RedirectForExtendedPermission) {
                FacebookGraphToolkitConfiguration Config = (FacebookGraphToolkitConfiguration)WebConfigurationManager.GetSection("FacebookGraphToolkitConfiguration");
                string RedirectUrl = Config._FacebookAppAddress + Config._PostAuthorizeRedirectURL;
                string AuthorizeUrl = String.Format("https://graph.facebook.com/oauth/authorize?client_id={0}&redirect_uri={1}&scope={2}", Config._FacebookAppID, RedirectUrl, ExtendedPermissions);
                Helpers.IframeHelper.IframeRedirect(AuthorizeUrl, false);
            }

            base.OnLoad(e);
        }