GetLoginUrl() public method

Gets the login uri.
public GetLoginUrl ( ) : Uri
return System.Uri
        /// <summary>
        /// Get FacebookOAuthClient.
        /// </summary>
        void MainPage_Loaded()
        {
            using (DbStorage fbdb = new DbStorage(strConnectionString))
            {
                IQueryable<Db> fbQuery = from db in fbdb.user select db;
                Db ac = fbQuery.FirstOrDefault();
                if(ac == null){
                    string appId = "YOUR FACEBOOK APP ID";
                    string[] extendedPermissions = new[] { "publish_stream"};

                    var oauth = new FacebookOAuthClient { AppId = appId };
                    var parameters = new Dictionary<string, object>
                            {
                               { "response_type", "token" },
                                { "display", "touch" }
                            };
                    if (extendedPermissions != null && extendedPermissions.Length > 0)
                    {
                        var scope = new StringBuilder();
                        scope.Append(string.Join(",", extendedPermissions));
                        parameters["scope"] = scope.ToString();
                    }
                    var loginUrl = oauth.GetLoginUrl(parameters);
                    //Add webBrowser to the contentPanel
                    _webBrowser.Navigate(loginUrl);
                    ContentPanel.Children.Add(_webBrowser);
                    _webBrowser.Navigated += webBrowser_Navigated;
                    //Open the facebook login page into the browser
           
            }
        }
        }
        public FacebookLoginDialog(string appId, string extendedPermissions)
        {
            if (string.IsNullOrEmpty(appId))
                throw new ArgumentNullException("appId");

            // Make sure to set the app id.
            var oauthClient = new FacebookOAuthClient { AppId = appId };

            IDictionary<string, object> loginParameters = new Dictionary<string, object>();

            // The requested response: an access token (token), an authorization code (code), or both (code token).
            loginParameters["response_type"] = "token";

            // list of additional display modes can be found at http://developers.facebook.com/docs/reference/dialogs/#display
            loginParameters["display"] = "popup";

            // add the 'scope' parameter only if we have extendedPermissions.
            if (!string.IsNullOrEmpty(extendedPermissions))
            {
                // A comma-delimited list of permissions
                loginParameters["scope"] = extendedPermissions;
            }

            // when the Form is loaded navigate to the login url.
            _loginUrl = oauthClient.GetLoginUrl(loginParameters);

            InitializeComponent();
        }
Esempio n. 3
0
        //private void TempCode()
        //{
        //    var app = new FacebookApp();
        //    dynamic me = app.Get("me");
        //    string firstName = me.first_name;
        //    string lastName = me.last_name;
        //    string email = me.email;
        //}
        //
        // GET: /Account/LogOn/
        public ActionResult LogOn(string returnUrl)
        {
            //TempCode();

            // MLW TODO Temp to try to fix case when user cookie has expired. Consider both Ajax and non-Ajax cases.
            if (returnUrl != null)
            {
                FormsAuthentication.SignOut();

                // This results in the html being shown in a message box for the Ajax requests (Eg. delete event)
                //return RedirectToAction("Index", "Home");  // Enough of a clue that they need to log back in?

                // The following shows a messagebox with the following for ajax requests(?)
                return Content("You have been logged out due to inaction.\r\n Please log back in.");
                // Seemed to return that as the entire content instead...Confusing.

            }

            var oAuthClient = new FacebookOAuthClient(FacebookApplication.Current);
            oAuthClient.RedirectUri = new Uri(redirectUrl);

            // See http://developers.facebook.com/docs/reference/dialogs/oauth/

            var loginUri = oAuthClient.GetLoginUrl(new Dictionary<string, object> { { "state", returnUrl }, {"scope", "publish_stream"} });

            SMap.GetLogger().Application("Log on attempt to: " + loginUri.AbsoluteUri + " based on redirect url " + redirectUrl);

            return Redirect(loginUri.AbsoluteUri);
        }
 /// <summary>
 /// Logon to application
 /// </summary>
 public ActionResult LogOn(string returnUrl)
 {
     var oAuthClient = new FacebookOAuthClient(FacebookApplication.Current);
     oAuthClient.RedirectUri = new Uri(redirectUrl);
     var loginUri = oAuthClient.GetLoginUrl(new Dictionary<string, object> { { "state", returnUrl } });
     return Redirect(loginUri.AbsoluteUri);
 }
Esempio n. 5
0
        public FacebookForm()
        {
            InitializeComponent();

            string _appID = Properties.Settings.Default.fb_AppKey;
            string _appSec = Properties.Settings.Default.fb_AppSec;
            string[] extendedPermissions = new[] { "publish_stream", "offline_access" };

            var oauth = new FacebookOAuthClient { AppId = _appID, AppSecret = _appSec };

            var parameters = new Dictionary<string, object>
                    {
                        { "response_type", "token" },
                        { "display", "popup" }
                    };

            if (extendedPermissions != null && extendedPermissions.Length > 0)
            {
                var scope = new StringBuilder();
                scope.Append(string.Join(",", extendedPermissions));
                parameters["scope"] = scope.ToString();
            }

            var loginUrl = oauth.GetLoginUrl(parameters);
            webBrowser1.Navigate(loginUrl);
        }
Esempio n. 6
0
 public ActionResult FBLogOn(string returnUrl)
 {
     var oAuthClient = new FacebookOAuthClient(FacebookApplication.Current);
     oAuthClient.RedirectUri = new Uri(HttpContext.Request.Url,Url.Action("FBOAuth","Auth"));
     var loginUri = oAuthClient.GetLoginUrl(new Dictionary<string, object> { { "state", returnUrl }, { "scope", "user_about_me,user_activities,user_education_history,user_hometown,user_interests,user_location,user_likes,user_religion_politics,user_work_history" } });
     return Redirect(loginUri.AbsoluteUri);
 }
        public FacebookLoginDialog(string appId, string[] extendedPermissions, bool logout)
        {
            var oauth = new FacebookOAuthClient { AppId = appId };

            var loginParameters = new Dictionary<string, object>
                    {
                        { "response_type", "token" },
                        { "display", "popup" }
                    };

            if (extendedPermissions != null && extendedPermissions.Length > 0)
            {
                var scope = new StringBuilder();
                scope.Append(string.Join(",", extendedPermissions));
                loginParameters["scope"] = scope.ToString();
            }

            var loginUrl = oauth.GetLoginUrl(loginParameters);

            if (logout)
            {
                var logoutParameters = new Dictionary<string, object>
                    {
                        { "next", loginUrl }
                    };
            }
            else
            {
                this.navigateUrl = loginUrl;
            }

            InitializeComponent();
        }
Esempio n. 8
0
 //
 // GET: /Account/LogOn/
 public ActionResult LogOn(string returnUrl)
 {
     string redirectUrl = "http://" + Request.Url.Host + "/Account/OAuth/";
     var oAuthClient = new FacebookOAuthClient(FacebookApplication.Current);
     oAuthClient.RedirectUri = new Uri(redirectUrl);
     var loginUri = oAuthClient.GetLoginUrl(new Dictionary<string, object> { { "state", returnUrl } });
     return Redirect(loginUri.AbsoluteUri);
 }
Esempio n. 9
0
 public static string GetFacebookLoginLink(string host, LoginMethod method)
 {
     var oAuthClient = new FacebookOAuthClient(FacebookApplication.Current);
     string redirectUrl = String.Format("{0}/{1}?method={2}", host, "login.aspx", EnumHelper.EnumToString(method));
     oAuthClient.RedirectUri = new Uri(redirectUrl);
     var loginUri = oAuthClient.GetLoginUrl(new Dictionary<string, object> { { "state", redirectUrl } });
     return loginUri.AbsoluteUri;
 }
Esempio n. 10
0
        public ActionResult OAuth(string returnUrl)
        {
            var oAuthClient = new FacebookOAuthClient(FacebookApplication.Current);
            oAuthClient.RedirectUri = new Uri(redirectUrl);

            var loginUri = oAuthClient.GetLoginUrl(new Dictionary<string, object> { { "state", "state_" }, { "scope", "offline_access,manage_pages,publish_stream" } });
            return Redirect(loginUri.AbsoluteUri);
        }
        public void ItShouldThrowInvalidOperationException()
        {
            var oauth = new FacebookOAuthClient();

            var parameters = new Dictionary<string, object>();
            parameters["client_id"] = "dummy client id";
            parameters["redirect_uri"] = null;

            Assert.Throws<ArgumentException>(() => oauth.GetLoginUrl(parameters));
        }
Esempio n. 12
0
    private string GetFbLoginUrl()
    {
        string callBackUrl = Settings.Url + "/CallbackFB.aspx";
        callBackUrl += "?ReturnUrl=" + StringUtils.ToHexString(HttpUtility.UrlEncode("/Contact.aspx"));//facebook sdk does not like special characters

        FacebookOAuthClient oauth = new FacebookOAuthClient(GlobalObjects.FBApp);
        oauth.RedirectUri = new Uri(callBackUrl);

        Dictionary<string, object> dict = new Dictionary<string, object>();
        dict.Add("scope", "email");
        return oauth.GetLoginUrl(dict).ToString();
    }
        public ActionResult Login(string id, string returnUrl)
        {
            if (id != null)
            {
                Session["PersonTryingToLogin"] = PersonDataAccessor.FetchPersonFromPublicId(id);
            }

            var oAuthClient = new FacebookOAuthClient(FacebookApplication.Current);
            oAuthClient.RedirectUri = new Uri(ConfigurationManager.AppSettings["RedirectUrl"]);
            var loginUri = oAuthClient.GetLoginUrl(new Dictionary<string, object> { { "state", returnUrl } });
            return Redirect(loginUri.AbsoluteUri + "&scope=user_birthday,email");
        }
        public void GivenParametersAsCodeTokenThenShouldEncodeCorrectly()
        {
            var oauth = new FacebookOAuthClient();

            var loginParameters = new Dictionary<string, object>();
            loginParameters["client_id"] = "appid";
            loginParameters["client_secret"] = "clientsecret";
            loginParameters["response_type"] = "code token";

            var loginUrl = oauth.GetLoginUrl(loginParameters);

            Assert.Equal("http://www.facebook.com/dialog/oauth/?client_id=appid&client_secret=clientsecret&response_type=code%20token&redirect_uri=http%3A%2F%2Fwww.facebook.com%2Fconnect%2Flogin_success.html",
                loginUrl.AbsoluteUri);
        }
Esempio n. 15
0
    private string GetFbLoginUrl()
    {
        string callBackUrl = Settings.Url + "/CallbackFB.aspx";
        string returnUrl = Request.QueryString["ReturnUrl"];
        if (!String.IsNullOrEmpty(returnUrl))
          callBackUrl += "?ReturnUrl=" + StringUtils.ToHexString(returnUrl);//facebook sdk does not like special characters

        FacebookOAuthClient oauth = new FacebookOAuthClient(GlobalObjects.FBApp);
        oauth.RedirectUri = new Uri(callBackUrl);

        Dictionary<string, object> dict = new Dictionary<string, object>();
        dict.Add("scope", "email");
        return oauth.GetLoginUrl(dict).ToString();
    }
        public void ItExceptionMessageShouldBeClientIdRequired()
        {
            var oauth = new FacebookOAuthClient();
            Exception exception = null;

            try
            {
                oauth.GetLoginUrl(null);
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            Assert.Equal("client_id required.", exception.Message);
        }
        public LoginProfile ProcessAuthoriztion(HttpContext context, IDictionary<string, string> @params)
        {
            var builder = new UriBuilder(context.Request.GetUrlRewriter()) {Query = "p=" + context.Request["p"]};
            var oauth = new FacebookOAuthClient
            {
                AppId = KeyStorage.Get("facebookAppID"),
                AppSecret = KeyStorage.Get("facebookAppSecret"),
                RedirectUri = builder.Uri
            };
            FacebookOAuthResult result;
            if (FacebookOAuthResult.TryParse(context.Request.GetUrlRewriter(), out result))
            {
                if (result.IsSuccess)
                {
                    var accessToken = (Facebook.JsonObject)oauth.ExchangeCodeForAccessToken(result.Code);
                    var request = WebRequest.Create("https://graph.facebook.com/me?access_token=" + Uri.EscapeDataString((string)accessToken["access_token"]));
                    using (var response = request.GetResponse())
                    {
                        using (var responseStream = response.GetResponseStream())
                        {
                            var graph = FacebookGraph.Deserialize(responseStream);
                            var profile = ProfileFromFacebook(graph);
                            return profile;
                        }
                    }
                }
                return LoginProfile.FromError(new Exception(result.ErrorReason));
            }
            //Maybe we didn't query
            var extendedPermissions = new[] { "email", "user_about_me" };
            var parameters = new Dictionary<string, object>
                                 {
                                     { "display", "popup" }
                                 };

            if (extendedPermissions.Length > 0)
            {
                var scope = new StringBuilder();
                scope.Append(string.Join(",", extendedPermissions));
                parameters["scope"] = scope.ToString();
            }
            var loginUrl = oauth.GetLoginUrl(parameters);
            context.Response.Redirect(loginUrl.ToString());
            return LoginProfile.FromError(new Exception("Failed to login with facebook"));
        }
Esempio n. 18
0
        public static string generateLoginUrl(int id)
        {
            string[] extendedPermissions = new[] { "publish_stream", "offline_access", "publish_actions" };

            var parameters = new Dictionary<string, object>();

            StringBuilder scope = new StringBuilder();
            scope.Append(string.Join(",", extendedPermissions));

            parameters["scope"] = scope.ToString();
            parameters["response_type"] = "code";
            parameters["display"] = "popup";

            FacebookOAuthClient oAuthClient = new FacebookOAuthClient(FacebookApplication.Current);
            oAuthClient.RedirectUri = new Uri(redirectUrl + "/" + id + "/");
            oAuthClient.AppId = ConfigurationManager.AppSettings["Facebook_API_Key"];
            oAuthClient.AppSecret = ConfigurationManager.AppSettings["Facebook_API_Secret"];
            Uri loginUri = oAuthClient.GetLoginUrl(parameters);
            return loginUri.AbsoluteUri;
        }
Esempio n. 19
0
        public FacebookWindow()
        {
            client = new FacebookOAuthClient { AppId = appId };
            parameters = new Dictionary<string, object> {
                { "response_type", "token" },
                { "display", "popup" }
            };

            if (extendedPermissions != null && extendedPermissions.Length > 0)
            {
                var scope = new StringBuilder();
                scope.Append(string.Join(",", extendedPermissions));
                parameters["scope"] = scope.ToString();
            }

            var loginUrl = client.GetLoginUrl(parameters);
            this.navigateUrl = loginUrl;

            InitializeComponent();
        }
        public void GetLoginUri_IfRedirectUriIsEmpty_ThenItExceptionMessageShouldBeRedirectUriRequired()
        {
            var oauth = new FacebookOAuthClient();

            var parameters = new Dictionary<string, object>();
            parameters["client_id"] = "dummy client id";
            parameters["redirect_uri"] = null;

            Exception exception = null;

            try
            {
                oauth.GetLoginUrl(parameters);
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            Assert.Equal("redirect_uri required.", exception.Message);
        }
Esempio n. 21
0
        //
        // GET: /Account/LogOn

        public ActionResult LogOn(string returnUrl)
        {
            var oauthClient = new FacebookOAuthClient(FacebookApplication.Current) { RedirectUri = GetFacebookRedirectUri() };


            if (!string.IsNullOrWhiteSpace(returnUrl))
            {
                returnUrl = Url.Action("Index", "Facebook");
            }

            dynamic parameters = new ExpandoObject();
            parameters.scope = ExtendedPermissions;

            // add csrf_token to prevent cross site forger attacks
            // pass returnUrl as state, so the callback know which page to redirect when the oauth login is successful
            // to make the querystring ?state=value safe, encode the value of state using Base64UrlEncode.
            var state = new { csrf_token = CalculateMD5Hash(Guid.NewGuid().ToString()), return_url = returnUrl };
            parameters.state = Base64UrlEncode(Encoding.UTF8.GetBytes(JsonSerializer.Current.SerializeObject(state)));
            SetFacebookCsrfToken(state.csrf_token);
            ViewBag.FacebookLoginUrl = oauthClient.GetLoginUrl(parameters).AbsoluteUri;

            return View();
        }
Esempio n. 22
0
        public ActionResult FacebookConnect(int id)
        {
            User user = userService.GetUserById(id);
             SystemConfiguration configuration = systemConfigurationService.Get();
             ViewData["FacebookAppId"] = configuration.FacebookAppId.ToEmptyStringIfNull();

             var oAuthClient = new FacebookOAuthClient();
             oAuthClient.AppId = configuration.FacebookAppId.ToEmptyStringIfNull();

             string redirectUrl = Url.Action("OAuth", "Users", new { id = user.UserId });

             oAuthClient.RedirectUri = new Uri(Request.Url.GetLeftPart(UriPartial.Authority) + redirectUrl);
             //var loginUri = oAuthClient.GetLoginUrl(new Dictionary<string, object> { { "state", returnUrl } });
             var loginUri = oAuthClient.GetLoginUrl();
             return Redirect(loginUri.AbsoluteUri);
        }
        /// <summary>
        /// Starts the authentication flow and redirects to Facebook
        /// </summary>
        public ActionResult FacebookStartLogin(string returnUrl)
        {
            if (!this.Config.AuthenticationProviders.Facebook.IsDefined)
            {
                return ResultHelper.ForbiddenResult(this);
            }
            var oAuthClient = new FacebookOAuthClient();
            oAuthClient.AppId = this.Config.AuthenticationProviders.Facebook.ApiKey;
            oAuthClient.RedirectUri = new Uri(new Uri(Domain), Url.Action("FacebookFinishLogin", "Authentication"));
            var loginUri = oAuthClient.GetLoginUrl(new Dictionary<string, object>(){{"state", Session.SessionToken}});

            Session.NextUrl = returnUrl;

            return new RedirectResult(loginUri.AbsoluteUri);
        }
        public LoginProfile ProcessAuthoriztion(HttpContext context, IDictionary<string, string> @params)
        {
            var builder = new UriBuilder(context.Request.GetUrlRewriter()) {Query = "p=" + context.Request["p"]};
            var oauth = new FacebookOAuthClient
            {
                AppId = KeyStorage.Get("facebookAppID"),
                AppSecret = KeyStorage.Get("facebookAppSecret"),
                RedirectUri = builder.Uri
            };
            FacebookOAuthResult result;
            if (FacebookOAuthResult.TryParse(context.Request.GetUrlRewriter(), out result))
            {
                if (result.IsSuccess)
                {
                    var accessToken = (Facebook.JsonObject)oauth.ExchangeCodeForAccessToken(result.Code);
                    var request = WebRequest.Create("https://graph.facebook.com/me?access_token=" + Uri.EscapeDataString((string)accessToken["access_token"]));
                    using (var response = request.GetResponse())
                    {
                        using (var responseStream = response.GetResponseStream())
                        {
                            var graph = FacebookGraph.Deserialize(responseStream);
                            var profile = ProfileFromFacebook(graph);
                            return profile;
                        }
                    }
                }
                return LoginProfile.FromError(new Exception(result.ErrorReason));
            }
            //Maybe we didn't query
            var extendedPermissions = new[] { "email", "user_about_me" };
            var parameters = new Dictionary<string, object>
                                 {
                                     { "display", "popup" }
                                 };

            if (extendedPermissions.Length > 0)
            {
                var scope = new StringBuilder();
                scope.Append(string.Join(",", extendedPermissions));
                parameters["scope"] = scope.ToString();
            }
            var loginUrl = oauth.GetLoginUrl(parameters);
            context.Response.Redirect(loginUrl.ToString());
            return LoginProfile.FromError(new Exception("Failed to login with facebook"));




            //var client = new FacebookClient
            //                 {
            //                     ClientIdentifier = KeyStorage.Get("facebookAppID"),
            //                     ClientSecret = KeyStorage.Get("facebookAppSecret"),
            //                 };
            //try
            //{
            //    IAuthorizationState authorization = client.ProcessUserAuthorization(new HttpRequestInfo(context.Request));
            //    if (authorization == null)
            //    {
            //        // Kick off authorization request
            //        var scope = new List<string>()
            //                    {
            //                        "email,user_about_me",
            //                    };
            //        client.RequestUserAuthorization(scope, null, null);
            //    }
            //    else
            //    {
            //        var request = WebRequest.Create("https://graph.facebook.com/me?access_token=" + Uri.EscapeDataString(authorization.AccessToken));
            //        using (var response = request.GetResponse())
            //        {
            //            if (response != null)
            //                using (var responseStream = response.GetResponseStream())
            //                {
            //                    var graph = FacebookGraph.Deserialize(responseStream);
            //                    var profile = ProfileFromFacebook(graph);
            //                    return profile;
            //                }
            //        }
            //    }
            //}
            //catch (ProtocolException e)
            //{
            //    if (e.InnerException is WebException)
            //    {
            //        //Read stream
            //        var responce =
            //            new StreamReader((e.InnerException as WebException).Response.GetResponseStream()).ReadToEnd();
            //    }
            //    throw;
            //}

        }
Esempio n. 25
0
 /// <summary>
 /// Open facebook auth page
 /// </summary>
 private void fb_connection()
 {
     // Open facebook auth url
       FacebookOAuthClient oauth = new FacebookOAuthClient();
       Uri loginUrl = oauth.GetLoginUrl(SWFacebookSettings.GetLoginParameters());
       authBrowser.Navigate(loginUrl);
 }
Esempio n. 26
0
        /// <summary>
        /// Gets the login url.
        /// </summary>
        /// <param name="appId">
        /// The app id.
        /// </param>
        /// <param name="redirectUri">
        /// The redirect Uri.
        /// </param>
        /// <param name="extendedPermissions">
        /// The extended permissions (scope).
        /// </param>
        /// <param name="logout">  
        /// Indicates whether to logout existing logged in user or not.  
        /// </param>  
        /// <param name="loginParameters">
        /// The login parameters.
        /// </param>
        /// <returns>
        /// The url to navigate.
        /// </returns>
        public static Uri GetLoginUrl(string appId, Uri redirectUri, string[] extendedPermissions, bool logout, IDictionary<string, object> loginParameters)
        {
            Contract.Requires(!string.IsNullOrEmpty(appId));
            Contract.Ensures(Contract.Result<Uri>() != null);

            var oauth = new FacebookOAuthClient { AppId = appId, RedirectUri = redirectUri };

            var defaultLoginParameters = new Dictionary<string, object>
                                             {
                                                 { "response_type", "code" }, // make it "code" by default for security reasons.
            #if WINDOWS_PHONE
                                                 { "display", "touch" }
            #else
                                                 { "display", "popup" }
            #endif
                                             };

            if (extendedPermissions != null && extendedPermissions.Length > 0)
            {
                defaultLoginParameters["scope"] = string.Join(",", extendedPermissions);
            }

            var mergedLoginParameters = FacebookUtils.Merge(defaultLoginParameters, loginParameters);

            var loginUrl = oauth.GetLoginUrl(mergedLoginParameters);

            Uri navigateUrl;
            if (logout)
            {
                var logoutParameters = new Dictionary<string, object>
                                           {
                                               { "next", loginUrl }
                                           };

                navigateUrl = oauth.GetLogoutUrl(logoutParameters);
            }
            else
            {
                navigateUrl = loginUrl;
            }

            return navigateUrl;
        }
        private void LoginToFbViaJs()
        {
            var loginParameters = new Dictionary<string, object>
                                      {
                                          { "display", "popup" },
                                          { "response_type", "code" } // make it code and not access token for security reasons.
                                      };

            loginParameters["scope"] = ExtendedPermissions;

            var oauthClient = new FacebookOAuthClient { AppId = AppId, RedirectUri = new Uri(SilverlightFacebookCallback) };

            var loginUrl = oauthClient.GetLoginUrl(loginParameters);

            // don't make the response_type = token
            // coz it will be saved in the browser's history.
            // so others might hack it.
            // rather call ExchangeCodeForAccessToken to get access token in server side.
            // we need to this in server side and not in this Silverlight app
            // so that the app secret doesn't get exposed to the client in case someone
            // reverse engineers this Silverlight app.
            HtmlPage.Window.Eval(string.Format("fbLogin('{0}')", loginUrl));
        }
Esempio n. 28
0
 /// <summary>
 /// Sends request to obtain user information with extended permissions to Facebook.
 /// </summary>
 /// <param name="returnUrl">Return Url</param>
 /// <returns>Redirect to Facebook</returns>
 public ActionResult Register(string returnUrl)
 {
     var oAuthClient = new FacebookOAuthClient(FacebookApplication.Current) { RedirectUri = new Uri(GetNewAccountUrl()) };
     var loginUri = oAuthClient.GetLoginUrl(new Dictionary<string, object>
                                                {
                                                    { "state", returnUrl },
                                                    { "scope", "email,user_location,user_birthday" } // FB extended permissions
                                                });
     return Redirect(loginUri.AbsoluteUri);
 }
 public void ItShouldThrowInvalidOperationException()
 {
     var oauth = new FacebookOAuthClient();
     Assert.Throws<ArgumentException>(() => oauth.GetLoginUrl(null));
 }
        private AuthorizeState GenerateRequestState(string returnUrl)
        {
            var facebookClient = new FacebookOAuthClient(FacebookApplication);

            var extendedPermissions = new[] { "publish_stream", "read_stream", "offline_access", "email", "user_about_me" };
            var parameters = new Dictionary<string, object> {
                {"redirect_uri", GenerateCallbackUri() }
            };

            if (extendedPermissions.Length > 0)
            {
                var scope = new StringBuilder();
                scope.Append(string.Join(",", extendedPermissions));
                parameters["scope"] = scope.ToString();
            }

            var result = new RedirectResult(facebookClient.GetLoginUrl(parameters).ToString());

            return new AuthorizeState(returnUrl, OpenAuthenticationStatus.RequiresRedirect) { Result = result };
        }