/* public FacebookLayer() { authorizer = new CanvasAuthorizer { Perms = "publish_stream" }; if (authorizer.Authorize()) { fbClient = new FacebookClient(CurrentSession.AccessToken); User = new FacebookUser(); try { var me = (IDictionary<string, object>) fbClient.Get("me"); User.FacebookId = (string) me["id"]; User.FacebookName = (string) me["first_name"]; } catch { isAccessTokenValid = false; return; } isAccessTokenValid = true; IDictionary<string, object> friendsData = (IDictionary<string, object>) fbClient.Get("me/friends"); facebookData = new FacebookData(User, friendsData); SortedFriends = facebookData.SortedFriends; } } */ public FacebookLayer(CanvasAuthorizer auth) { this.authorizer = auth; if (this.authorizer.Authorize()) { fbClient = new FacebookClient(CurrentSession.AccessToken); User = new FacebookUser(); try { var me = (IDictionary<string, object>) fbClient.Get("me"); User.FacebookId = (string) me["id"]; User.FacebookName = (string) me["first_name"]; } catch { isAccessTokenValid = false; return; } isAccessTokenValid = true; IDictionary<string, object> friendsData = (IDictionary<string, object>) fbClient.Get("me/friends"); facebookData = new FacebookData(User, (IList<object>)friendsData["data"]); } }
protected void Page_Load(object sender, EventArgs e) { if (Page.IsPostBack) { CheckIfFacebookAppIsSetupCorrectly(); var auth = new CanvasAuthorizer { Permissions = new[] { "user_about_me" } }; if (auth.Authorize()) { ShowFacebookContent(); } } else { AmazonSimpleDB sdb = GetSDB(); // Should I clean out the AWS domain state? if (Page.Request.Params["delaws"] == "1") { //Deleting a domain DeleteDomainRequest deleteDomainAction = new DeleteDomainRequest().WithDomainName("ZigMeRecos"); sdb.DeleteDomain(deleteDomainAction); } // Now read from the AWS domain and populate the dropdown list // First check to see if a domain contain service types exists. if not then create it and populate it // Listing domains /*ListDomainsResponse sdbListDomainsResponse = sdb.ListDomains(new ListDomainsRequest()); if (sdbListDomainsResponse.IsSetListDomainsResult()) { ListDomainsResult listDomainsResult = sdbListDomainsResponse.ListDomainsResult; if (!listDomainsResult.DomainName.Contains("ZigMeServiceTypes")) { } else { String selectExpression = "Select * From ZigMeServiceTypes"; SelectRequest selectRequestAction = new SelectRequest().WithSelectExpression(selectExpression); SelectResponse selectResponse = sdb.Select(selectRequestAction); if (selectResponse.IsSetSelectResult()) { SelectResult selectResult = selectResponse.SelectResult; foreach (Item item in selectResult.Item) { foreach (Amazon.SimpleDB.Model.Attribute attribute in item.Attribute) { if (attribute.IsSetName() && attribute.IsSetValue()) { } } } } } }*/ } }
protected void Page_Load(object sender, EventArgs e) { CheckIfFacebookAppIsSetupCorrectly(); var auth = new CanvasAuthorizer { Permissions = new[] { "user_about_me" } }; if (auth.Authorize()) { ShowFacebookContent(); } }
protected internal override System.Uri GetLoginUrl(IFacebookApplication settings, HttpContextBase httpContext, IDictionary<string, object> parameters) { var authorizer = new CanvasAuthorizer(settings, httpContext) { ReturnUrlPath = ReturnUrlPath, CancelUrlPath = CancelUrlPath, LoginDisplayMode = LoginDisplayMode }; if (!String.IsNullOrEmpty(Permissions)) { authorizer.Permissions = Permissions.Replace(" ", String.Empty).Split(','); } if (string.IsNullOrEmpty(CancelUrlPath)) { // set it to this same url instead of going to facebook.com var canvasUrlBuilder = new CanvasUrlBuilder(settings, httpContext.Request); var currentPathAndQuery = canvasUrlBuilder.CurrentCanvasPathAndQuery; if (currentPathAndQuery.Contains("?")) { var parts = currentPathAndQuery.Split('?'); if (parts.Length == 2 && !string.IsNullOrEmpty(parts[1])) { var queryStrings = FacebookUtils.ParseUrlQueryString(parts[1]); // remove oauth 2 error querystrings. // error_reason=user_denied&error_denied=access_denied&error_description=The+user+denied+your+request. if (queryStrings.ContainsKey("error_reason")) { queryStrings.Remove("error_reason"); } if (queryStrings.ContainsKey("error_denied")) { queryStrings.Remove("error_denied"); } if (queryStrings.ContainsKey("error_description")) { queryStrings.Remove("error_description"); } currentPathAndQuery = parts[0] + "?" + FacebookUtils.ToJsonQueryString(queryStrings); } } authorizer.CancelUrlPath = currentPathAndQuery; } return authorizer.GetLoginUrl(null); }
protected void Page_Load(object sender, EventArgs e) { var auth = new CanvasAuthorizer{Perms = "publish_stream"}; FacebookLayer fb = new FacebookLayer(auth); if (auth.Authorize()) { if (Request.QueryString["action"] != null) { LocationActions(Request.QueryString, fb); } ShowFacebookContent(fb); } }
internal virtual protected Uri GetLoginUrl(IFacebookApplication settings, HttpContextBase httpContext, IDictionary<string, object> parameters) { Contract.Requires(settings != null); Contract.Requires(httpContext != null); var authorizer = new CanvasAuthorizer(settings, httpContext) { ReturnUrlPath = this.ReturnUrlPath, CancelUrlPath = this.CancelUrlPath, LoginDisplayMode = this.LoginDisplayMode }; if (!String.IsNullOrEmpty(this.Permissions)) { authorizer.Permissions = this.Permissions.Replace(" ", String.Empty).Split(','); } return authorizer.GetLoginUrl(parameters); }
public CanvasAuthorizerFacade(CanvasAuthorizer baseInstance) : base(baseInstance) { this.baseInstance = baseInstance; }
/* private fbuser Setfbid() { string oauth = ""; oauth = HttpContext.Current.Request.QueryString["code"].ToString(); //oauth = oauth.Substring(0, oauth.IndexOf("|")); fbuser fbuser = new fbuser(); //oauth = oauth.Substring(0, oauth.IndexOf("|")); WebClient wc = new WebClient(); wc.Encoding = System.Text.Encoding.UTF8; //This is if you have non english characters //string result = wc.DownloadString("https://graph.facebook.com/oauth/access_token?response_type=token&client_secret=" + ConfigurationManager.AppSettings.Get("Secret").ToString() + "&client_id=" + ConfigurationManager.AppSettings.Get("fbAppID").ToString() + "&code=" + oauth); string strsend = "https://graph.facebook.com/oauth/access_token?client_id=" + ConfigurationManager.AppSettings.Get("fbAppID").ToString() + "&redirect_uri=" + thereturnpage + "&client_secret=" + ConfigurationManager.AppSettings.Get("Secret").ToString() + "&code=" + oauth; var url = "https://graph.facebook.com/oauth/authorize?client_id=" + ConfigurationSettings.AppSettings.Get("fbAppID").ToString() + "&redirect_uri=" + ConfigurationSettings.AppSettings.Get("App_URL").ToString() + "default.aspx&scope=" + strrequiredAppPermissions; string result = wc.DownloadString(url); string accesstoken = result.Replace("access_token=", ""); int endofaccesstoken = accesstoken.IndexOf("&expire"); accesstoken = accesstoken.Substring(0, endofaccesstoken); //Get user id wc.Encoding = System.Text.Encoding.UTF8; //This is if you have non english characters string result2 = wc.DownloadString("https://graph.facebook.com/me?access_token=" + accesstoken); try { JObject o = JObject.Parse(result2); string fbid = (string)o["id"]; string email = ""; string firstname = ""; string lastname = ""; if (o["email"] != null) { email = (string)o["email"]; } if (o["first_name"] != null) { firstname = (string)o["first_name"]; } if (o["last_name"] != null) { lastname = (string)o["last_name"]; } bool isnewuser = false; BlueIkons_DB.SPs.UpdateFBUser(Convert.ToInt64(fbid), firstname, lastname, email, accesstoken).Execute(); fbuser.UID = Convert.ToInt64(fbid); fbuser.Email = email; fbuser.Firstname = firstname; fbuser.Lastname = lastname; fbuser.AccessToken = accesstoken; } catch { } return fbuser; }*/ protected fbuser PopulatefbuserGraph() { CanvasAuthorizer authorizer; fbuser localfbuser = new fbuser(); FacebookApp fbApp = new FacebookApp(); authorizer = new CanvasAuthorizer(); authorizer.Permissions = requiredAppPermissions; //if ((authorizer.Session != null) || ((HttpContext.Current.Request.QueryString["code"] != null) && (HttpContext.Current.Request.QueryString["code"] != ""))) if (authorizer.Session != null) { //ShowFacebookContent(); JsonObject myInfo = (JsonObject)fbApp.Get("me"); localfbuser.UID = Convert.ToInt64(myInfo["id"].ToString()); localfbuser.AccessToken = fbApp.AccessToken; localfbuser.SessionKey = fbApp.Session.Signature; localfbuser.Firstname = myInfo["first_name"].ToString(); localfbuser.Lastname = myInfo["last_name"].ToString(); localfbuser.Fullname = localfbuser.Firstname + " " + localfbuser.Lastname; localfbuser.Email = getfbappemail(myInfo); //HttpContext.Current.Session["fbuser"] = fbuser; BlueIkons_DB.SPs.UpdateFBUser(localfbuser.UID, localfbuser.Firstname, localfbuser.Lastname, localfbuser.Email, localfbuser.AccessToken).Execute(); if ((HttpContext.Current.Session["invite"] != null) || (HttpContext.Current.Request.QueryString["invite"] != null)) { updateinvite(localfbuser); } //Eventomatic_DB.SPs.UpdateResource(fbuser.UID, fbuser.Firstname, fbuser.Lastname, "", HttpContext.Current.Request.UserHostAddress, GetCurrentPageName(), 0, 0, fbuser.SessionKey, fbuser.AccessToken, 0).Execute(); } else if ((HttpContext.Current.Request.QueryString["fbid"] != null) && (HttpContext.Current.Request.QueryString["fbid"] != "")) { localfbuser = Getfbuser(Convert.ToInt64(HttpContext.Current.Request.QueryString["fbid"].ToString())); if (HttpContext.Current.Request.QueryString["invite"] != null) { updateinvite(localfbuser); } //HttpContext.Current.Session["fbuser"] = fbuser; } else { if (HttpContext.Current.Request.QueryString["invite"] != null) { //remember invitekey HttpContext.Current.Session["invite"] = HttpContext.Current.Request.QueryString["invite"].ToString(); } var pageName = Path.GetFileName(HttpContext.Current.Request.PhysicalPath); var urlSB = new StringBuilder(); urlSB.Append("https://graph.facebook.com/oauth/authorize?client_id="); urlSB.Append(ConfigurationManager.AppSettings["fbAppID"]); urlSB.Append("&redirect_uri="); urlSB.Append(ConfigurationManager.AppSettings["App_URL"]); urlSB.Append(pageName); urlSB.Append("&scope="); urlSB.Append(strrequiredAppPermissions); //var url = authorizer.ge auth.GetLoginUrl(new HttpRequestWrapper(Request)); Uri newuri = new Uri(urlSB.ToString()); var content = CanvasUrlBuilder.GetCanvasRedirectHtml(newuri); HttpContext.Current.Response.ContentType = "text/html"; HttpContext.Current.Response.Write(content); HttpContext.Current.Response.End(); } return localfbuser; }