protected override void OnInit(EventArgs e) { base.OnInit(e); IsLoggedIn = _authorizer.IsAuthorized(); if (!IsLoggedIn) { Uri authurl = _authorizer.GetLoginUrl(new HttpRequestWrapper(Request)); CanvasRedirect(authurl.ToString()); } else { FacebookUserId = _facebookApp.UserId; AccessToken = _facebookApp.Session.AccessToken; using (IAchievementManager manager = new AchievementManager()) { User user = manager.GetUser(FacebookUserId); if (user != null) { SteamUserId = user.SteamUserId; } } } }
/// <summary> /// Gets the login url. /// </summary> /// <param name="settings">The Facebook application settings.</param> /// <param name="httpContext">The http context.</param> /// <param name="parameters">The login parameters.</param> /// <returns>The login url.</returns> internal virtual protected Uri GetLoginUrl(IFacebookApplication settings, HttpContextBase httpContext, IDictionary <string, object> parameters) { if (settings == null) { throw new ArgumentNullException("settings"); } if (httpContext == null) { throw new ArgumentNullException("httpContext"); } 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)); }
protected internal override 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)); }
internal virtual protected Uri GetLoginUrl(IFacebookApplication settings, HttpContextBase httpContext, IDictionary <string, object> parameters) { Contract.Requires(settings != null); Contract.Requires(httpContext != null); this.ReturnUrlPath = FacebookConfigurationSection.Current.ReturnUrlPath; this.CancelUrlPath = FacebookConfigurationSection.Current.CancelUrlPath; 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)); }