Represents the authentication result of Facebook.
예제 #1
0
        private void TakeLoggedInAction(Facebook.FacebookOAuthResult facebookOAuthResult)
        {
            if (facebookOAuthResult == null)
            {
                // the user closed the FacebookLoginDialog, so do nothing.
                // MessageBox.Show("Cancelled!");
                this.Close();
                return;
            }

            // Even though facebookOAuthResult is not null, it could had been an
            // OAuth 2.0 error, so make sure to check IsSuccess property always.
            if (facebookOAuthResult.IsSuccess)
            {
                // since our respone_type in FacebookLoginDialog was token,
                // we got the access_token
                // The user now has successfully granted permission to our app.
                GlobalSetting.FacebookAccessToken = facebookOAuthResult.AccessToken;
            }
            else
            {
                // for some reason we failed to get the access token.
                // most likely the user clicked don't allow.
                MessageBox.Show(facebookOAuthResult.ErrorDescription);
                this.Close();
            }
        }
예제 #2
0
        private void LoginSucceded(FacebookOAuthResult oauthResult)
        {
            var fb = new FacebookClient(oauthResult.AccessToken);

            fb.GetCompleted += (o, e) =>
            {
                if (e.Error != null)
                {
                    Dispatcher.BeginInvoke(() => MessageBox.Show(e.Error.Message));
                    return;
                }
                var result = (IDictionary<string, object>)e.GetResultData();

                StorageSettings settings = new StorageSettings();
                settings.FacebookAccessToken = oauthResult.AccessToken;
                settings.FacebookAccessTokenExpires = oauthResult.Expires;
                settings.FacebookUserName = result["username"].ToString();

                SaveNewUserToXmlFile(result["username"].ToString());

                Dispatcher.BeginInvoke(() => NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative)));
            };

            fb.GetAsync("me");
        }
        private void DisplayAppropriateMessage(FacebookOAuthResult facebookOAuthResult)
        {
            if (facebookOAuthResult != null)
            {
                if (facebookOAuthResult.IsSuccess)
                {
                    _accessToken = facebookOAuthResult.AccessToken;
                    var fb = new FacebookClient(facebookOAuthResult.AccessToken);

                    dynamic result = fb.Get("/me");
                    var name = result.name;

                    // for .net 3.5
                    //var result = (IDictionary<string, object>)fb.Get("/me");
                    //var name = (string)result["name"];

                    MessageBox.Show("Hi " + name);
                    btnLogout.Visible = true;
                }
                else
                {
                    MessageBox.Show(facebookOAuthResult.ErrorDescription);
                }
            }
        }
예제 #4
0
        public int ProcessFbOathResult(FacebookOAuthResult oauthResult)
        {
            var resultCode = 0;
            var accessToken = oauthResult.AccessToken;
            App.ViewModel.UserPreference.AccessKey = accessToken;
            var fbS = new FacebookClient(accessToken);

            fbS.GetCompleted += (o, res) =>
                                    {
                                        if (res.Error != null)
                                        {
                                            resultCode = 1;
                                            return;
                                        }

                                        var result = (IDictionary<string, object>) res.GetResultData();
                                        App.ViewModel.UserPreference.FbUserId = (string) result["id"];
                                        App.ViewModel.UserPreference.Name = (string) result["name"];
                                        App.ViewModel.LoadData(true);
                                        App.ViewModel.SaveSettings();
                                        Dispatcher.BeginInvoke(() =>
                                                                   {
                                                                       facebookImage.Source =
                                                                           App.ViewModel.UserPreference.UserImage;
                                                                       name.Text = App.ViewModel.UserPreference.Name;
                                                                   });
                                    };

            fbS.GetTaskAsync("me");
            return resultCode;
        }
예제 #5
0
        private void TakeLoggedInAction(FacebookOAuthResult facebookOAuthResult)
        {
            if (facebookOAuthResult == null)
            {
                // the user closed the FacebookLoginDialog, so do nothing.
                MessageBox.Show("Cancelled!");
                return;
            }

            // Even though facebookOAuthResult is not null, it could had been an
            // OAuth 2.0 error, so make sure to check IsSuccess property always.
            if (facebookOAuthResult.IsSuccess)
            {
                // since our respone_type in FacebookLoginDialog was token,
                // we got the access_token
                // The user now has successfully granted permission to our app.
                var dlg = new InfoDialog(facebookOAuthResult.AccessToken);
                dlg.ShowDialog();
            }
            else
            {
                // for some reason we failed to get the access token.
                // most likely the user clicked don't allow.
                MessageBox.Show(facebookOAuthResult.ErrorDescription);
            }
        }
예제 #6
0
 private void LoginDenied(FacebookOAuthResult result)
 {
     MessageBox.Show("Lo siento, no pudimos registrarte");
     SettingsManager.FacebookActive = false;
     SettingsManager.FacebookToken = string.Empty;
     SettingsManager.DoNotSuggestFacebookIntegration = true;
     NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
 }
        public void IsSuccessShouldBeFalse()
        {
            var parameters = new Dictionary<string, object>
                                 {
                                     { "error_reason", "dummy error reason" }
                                 };

            var result = new FacebookOAuthResult(parameters);

            Assert.False(result.IsSuccess);
        }
        public void IsSuccessShouldBeTrue()
        {
            var parameters = new Dictionary<string, object>
                                 {
                                     { "code", "dummycode" }
                                 };

            var result = new FacebookOAuthResult(parameters);

            Assert.True(result.IsSuccess);
        }
        public void CodeShouldBeTheOneSpecifiedInDictionary()
        {
            var code = "2.XeyH7lWz33itx1R86_uBeg__.3600.1294930800-100001327642026|t8SsfSR2XI6yhBAkhX95J7p9hJ0";
            var parameters = new Dictionary<string, object>
                                 {
                                     { "code", code }
                                 };

            var result = new FacebookOAuthResult(parameters);

            Assert.Equal(code, result.Code);
        }
        public void CodeShouldBeTheOneSpecifiedInDictionary()
        {
            var parameters = new Dictionary<string, object>
                                {
                                    { "code", "code" },
                                    { "access_token", "accesstoken" }
                                };

            var result = new FacebookOAuthResult(parameters);

            Assert.Equal("code", result.Code);
        }
예제 #11
0
 private void WebBrowserNavigated(object sender, WebBrowserNavigatedEventArgs e)
 {
     FacebookOAuthResult result;
     if (FacebookOAuthResult.TryParse(e.Url, out result))
     {
         Result = result;
         DialogResult = result.IsSuccess;
     }
     else
     {
         Result = null;
     }
 }
 private void webBrowser_Navigated(object sender, WebBrowserNavigatedEventArgs e)
 {
     FacebookOAuthResult result;
     if (FacebookOAuthResult.TryParse(e.Url, out result))
     {
         this.FacebookOAuthResult = result;
         this.DialogResult = result.IsSuccess ? DialogResult.OK : DialogResult.No;
     }
     else
     {
         this.FacebookOAuthResult = null;
     }
 }
 private void webBrowser_Navigated(object sender, WebBrowserNavigatedEventArgs e)
 {
     FacebookOAuthResult oauthResult;
     if (_fb.TryParseOAuthCallbackUrl(e.Url, out oauthResult))
     {
         FacebookOAuthResult = oauthResult;
         DialogResult = FacebookOAuthResult.IsSuccess ? DialogResult.OK : DialogResult.No;
     }
     else
     {
         FacebookOAuthResult = null;
     }
 }
        public virtual bool TryParseOAuthCallbackUrl(Uri url, out FacebookOAuthResult facebookOAuthResult)
        {
            facebookOAuthResult = null;

            try
            {
                facebookOAuthResult = ParseOAuthCallbackUrl(url);
                return true;
            }
            catch
            {
                return false;
            }
        }
예제 #15
0
        private void facebookWhois(FacebookOAuthResult fboa)
        {
            var fba = new FacebookClient(fboa.AccessToken);

            var resultWhois = (IDictionary<string, object>)fba.Get("/me");
            var name = (string)resultWhois["name"];
            Properties.Settings.Default.fb_sn = name; //Store Facebook Profile Name!
            FacebookForm_Output = "Currently logged in as: " + name; //Output Success message.
            Properties.Settings.Default.Save();

            //Ask the user if they'll help spread the word about Downstream:
            DialogResult d = MessageBox.Show(
                "If you're happy with Downstream, could I have your permission\n" +
                "to post a status about Downstream?\n\nIt costs nothing to you but means a lot to the developer!",
                "Downstream Appreciation Notice", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (d == System.Windows.Forms.DialogResult.Yes)
            {
                //Use fba FacebookClient object (Code reuse!)
                dynamic parameters = new ExpandoObject();
                parameters.message = "I'm using Downstream to listen to music! Get it free!";
                parameters.link = "http://mattryder.co.uk/project/downstream";
                parameters.picture = "http://mattryder.co.uk/image/downstreamicon.png";
                parameters.name = "Downstream Media Player";
                parameters.caption = "Downstream Download";
                parameters.description = "Downstream is a free application that plays the music you want to listen to, and allows you to share your musical tastes through Facebook and Twitter.";
                parameters.action = new
                {
                    name = "Download Downstream",
                    link = "http://mattryder.co.uk/project/downstream"
                };

                parameters.privacy = new {
                        value = "ALL_FRIENDS",
                };

                parameters.targeting = new {
                        countries = "UK",
                        regions = "6,53",
                        locales = "6",
                };

                dynamic result = fba.Post("me/feed", parameters);
                FacebookForm_Output = "Thanks for supporting Downstream!";

            }
            this.Close();
        }
        private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
        {
            // whenever the browser navigates to a new url, try parsing the url.
            // the url may be the result of OAuth 2.0 authentication.

            FacebookOAuthResult oauthResult;
            if (_fb.TryParseOAuthCallbackUrl(e.Url, out oauthResult))
            {
                // The url is the result of OAuth 2.0 authentication
                FacebookOAuthResult = oauthResult;
                DialogResult = FacebookOAuthResult.IsSuccess ? DialogResult.OK : DialogResult.No;
            }
            else
            {
                // The url is NOT the result of OAuth 2.0 authentication.
                FacebookOAuthResult = null;
            }
        }
예제 #17
0
        private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
        {
            // whenever the browser navigates to a new url, try parsing the url
            // the url may be the result of OAuth 2.0 authentication.

            Facebook.FacebookOAuthResult oauthResult;
            if (_fb.TryParseOAuthCallbackUrl(e.Url, out oauthResult))
            {
                // The url is the result of OAuth 2.0 authentication.
                FacebookOAuthResult = oauthResult;
                DialogResult        = FacebookOAuthResult.IsSuccess ? DialogResult.OK : DialogResult.No;
            }
            else
            {
                // The url is NOT the result of OAuth 2.0 authentication.
                FacebookOAuthResult = null;
            }
        }
예제 #18
0
        public bool ProcessFbOathResult(FacebookOAuthResult oauthResult)
        {
            var resultProcess = false;
            var accessToken = oauthResult.AccessToken;
            App.ViewModel.UserPreference.AccessKey = accessToken;
            var fbS = new FacebookClient(accessToken);

            fbS.GetCompleted += (o, res) =>
                                    {
                                        if (res.Error != null)
                                        {
                                            Dispatcher.BeginInvoke(() =>
                                                                       {
                                                                           gridFBLoggedIn.Visibility =
                                                                               Visibility.Collapsed;
                                                                           FaceBookLoginPage.Visibility =
                                                                               Visibility.Collapsed;
                                                                           LinkButton.Visibility = Visibility.Visible;
                                                                       });

                                            return;
                                        }

                                        var result = (IDictionary<string, object>) res.GetResultData();
                                        App.ViewModel.UserPreference.FbUserId = (string) result["id"];
                                        App.ViewModel.UserPreference.Name = (string) result["name"];
                                        App.ViewModel.LoadData(true);
                                        App.ViewModel.SaveSettings();
                                        Dispatcher.BeginInvoke(() =>
                                                                   {
                                                                       facebookImage.Source =
                                                                           App.ViewModel.UserPreference.UserImage;
                                                                       name.Text = App.ViewModel.UserPreference.Name;
                                                                   });
                                        resultProcess = true;
                                    };

            fbS.GetAsync("me");
            return resultProcess;
        }
예제 #19
0
 private void formWebBrowser_Navigated(object sender, WebBrowserNavigatedEventArgs e)
 {
     FacebookOAuthResult result;
     if (FacebookOAuthResult.TryParse(e.Url, out result))
     {
         this.FacebookOAuthResult = result;
         if (result.IsSuccess)
         {
             FacebookUpload fbDlg = new FacebookUpload(this.FacebookOAuthResult.AccessToken);
             fbDlg.Show();
             this.Close();
         }
         else
         {
             System.Windows.MessageBox.Show("Failed to login. Please try again. Error:\n" + result.ErrorDescription);
             this.Close();
         }
     }
     else
     {
         this.FacebookOAuthResult = null;
     }
 }
예제 #20
0
        private void loginSucceeded(FacebookOAuthResult authResult)
        {
            TitleBox.Visibility = Visibility.Visible;
            FacebookLoginBrowser.Visibility = Visibility.Collapsed;
            InfoBox.Visibility = Visibility.Visible;

            var fb = new FacebookClient(authResult.AccessToken);

            fb.GetCompleted +=
                (o, e) =>
                {
                    if (e.Error == null)
                    {
                        var result = (IDictionary<string, object>)e.GetResultData();
                        Dispatcher.BeginInvoke(() => InfoBox.ItemsSource = result);
                    }
                    else
                    {
                        MessageBox.Show(e.Error.Message);
                    }
                };

            fb.GetAsync("/me");
        }
예제 #21
0
 /// <summary>
 /// Try parsing the uri to <see cref="FacebookOAuthResult"/>.
 /// </summary>
 /// <param name="uri">
 /// The url to parse.
 /// </param>
 /// <param name="result">
 /// An instance of <see cref="FacebookOAuthResult"/>.
 /// </param>
 /// <returns>
 /// Returns true if parsing was successful otherwise false.
 /// </returns>
 public static bool TryParse(Uri uri, out FacebookOAuthResult result)
 {
     result = Parse(uri, false);
     return(result != null);
 }
        private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
        {
            client.UseFacebookBeta = true;
            client.IsSecureConnection = true;
            FacebookOAuthResult oauthResult;
            if (client.TryParseOAuthCallbackUrl(e.Url, out oauthResult))
            {
                // The url is the result of OAuth 2.0 authentication
                FacebookOAuthResult = oauthResult;
                client.AccessToken = FacebookOAuthResult.AccessToken;
                var fb = new FacebookClient(FacebookOAuthResult.AccessToken);

                // Note: the result can either me IDictionary<string,object> or IList<object>
                // json objects with properties can be casted to IDictionary<string,object> or IDictionary<string,dynamic>
                // json arrays can be casted to IList<object> or IList<dynamic>

                // for this particular request we can guarantee that the result is
                // always IDictionary<string,object>.
                var result = (IDictionary<string, object>)client.Get("me");

                // make sure to cast the object to appropriate type
                var id = (string)result["id"];

                // FacebookClient's Get/Post/Delete methods only supports JSON response results.
                // For non json results, you will need to use different mechanism,

                // here is an example for pictures.
                // available picture types: square (50x50), small (50xvariable height), large (about 200x variable height) (all size in pixels)
                // for more info visit http://developers.facebook.com/docs/reference/api
                string profilePictureUrl = string.Format("https://graph.facebook.com/{0}/picture?type={1}", id, "square");
                pictureBox1.LoadAsync(profilePictureUrl);
                pictureBox1.Visible = true;
                var dicParams = new Dictionary<string, object>();
                dicParams["message"] = "Can You see this?";
                dicParams["caption"] = "Test2";
                dicParams["description"] = "first sample1";
                dicParams["name"] = "This is Test2";
                dicParams["req_perms"] = "manage_pages";
                dicParams["scope"] = "manage_pages";

                //Get the access token of the posting user if we need to
                //if (destinationID != this.FacebookAccount.UserAccountId)
                //{

                //}
                //var webClient = new WebClient();
                //string oauthUrl = string.Format("https://graph.facebook.com/me/accounts?access_token={0}", FacebookOAuthResult.AccessToken);

                //string data = webClient.DownloadString(oauthUrl);
                //var json = new JavaScriptSerializer();
                //var pages = (Dictionary<string, object>)json.DeserializeObject(data);
                //object[] pages2 = (object[])pages.FirstOrDefault(p => p.Key == "data").Value;
                //string accessToken = null;
                //foreach (object page in pages2)
                //{
                    //Dictionary<string, object> page2 = (Dictionary<string, object>)page;
                //    if (page2["name"].ToString() == "MQ163")
                //    {
                //        accessToken = page2["access_token"].ToString();
                //        break;
                //    }
                //}
                //var json = System.Runtime.Serialization.s
                //https://developers.facebook.com/docs/howtos/login/login-as-page/
                //https://graph.facebook.com/seshu.miriyala.1/accounts?access_token=AAACEdEose0cBAG7kZCHS59oeoB4fV6jjRsm4je68vpMQUqXM6G5YsasRCFs4wPi3ld0bdGSAZAZBLZBEbyPrMRHvSk78uJZAdApaZC7D6gx9NyE08vLf0W
                //http://developers.facebook.com/docs/getting-started/graphapi/
                //http://stackoverflow.com/questions/3010707/facebook-graph-api-facebook-pages
                dicParams["access_token"] = FacebookOAuthResult.AccessToken;
                //var fbc = new FacebookClient(accessToken);
                //string pagePosts = webClient.DownloadString(string.Format("https://graph.facebook.com/wikipedia/posts?access_token={0} ", accessToken));
                //String[] permissions = { "offline_access", "publish_stream", "user_photos", "publish_checkins", "photo_upload" };
                //FacebookClient.a.authorize(MainActivity.this, permissions,
                //            new LoginDialogListener());
                dynamic publishResponse = client.Post("https://graph.facebook.com/MQ163/feed", dicParams);
            }
            else
            {
                // The url is NOT the result of OAuth 2.0 authentication.
                FacebookOAuthResult = null;
            }
        }
예제 #23
0
        private void GetItemsFromFacebook(FacebookOAuthResult facebookOAuthResult)
        {
            if (facebookOAuthResult != null)
            {
                if (facebookOAuthResult.IsSuccess)
                {
                    _accessToken = facebookOAuthResult.AccessToken;
                    var fb = new FacebookClient(facebookOAuthResult.AccessToken);

                    try
                    {
                        //dynamic parameters = new ExpandoObject();
                        //parameters.fields = "locations";
                        //dynamic result2 = fb.Get("me", parameters);

                        //Console.WriteLine(result2);

                        //foreach (var loc in result2.locations.data)
                        //{
                        //    string lName = loc.place.name;
                        //    Console.WriteLine(lName);
                        //}

                        _fbContext.AddFacebookLocationsToContext(facebookOAuthResult.AccessToken);

                        _fbContext.AddFacebookEventsToContext(facebookOAuthResult.AccessToken);

                        _fbContext.MyLoFacebookAlignment01();

                        _fbContext.MyLoSchemaReasoner();

                        _fbContext.SaveContextToFile();

                        string outFile = @"../../../Output1.txt";
                        using (StreamWriter outStream = new StreamWriter(outFile, false))
                        {
                            _fbContext.WriteGraph(outStream);
                        }

                        textBox1.Text = "Finished Finding Items on Facebook";

                        buttonFBlogout.Visible = true;
                    }
                    catch (FacebookOAuthException fbEx)
                    {
                        // oauth exception occurred
                        textBox1.Text = String.Format("FacebookAPI Oauth Error {0}", fbEx.Message);
                    }
                    catch (FacebookApiLimitException fbEx)
                    {
                        // api limit exception occurred.
                        textBox1.Text = String.Format("FacebookAPI App Limit Error {0}", fbEx.Message);
                    }
                    catch (FacebookApiException fbEx)
                    {
                        // other general facebook api exception
                        textBox1.Text = String.Format("FacebookAPI App Error {0}", fbEx.Message);
                    }
                    catch (Exception fbEx)
                    {
                        // non-facebook exception such as no internet connection.
                        textBox1.Text = String.Format("Non Facebook API App Error {0}", fbEx.Message);
                    }
                }
                else
                {
                    textBox1.Text = String.Format(facebookOAuthResult.ErrorDescription);
                }
            }
        }
예제 #24
0
        private void TakeLoggedInAction(FacebookOAuthResult facebookOAuthResult)
        {
            if (facebookOAuthResult == null)
            {
                // the user closed the FacebookLoginDialog, so do nothing.
                MessageBox.Show("Cancelled!");
                return;
            }

            // Even though facebookOAuthResult is not null, it could had been an
            // OAuth 2.0 error, so make sure to check IsSuccess property always.
            if (facebookOAuthResult.IsSuccess)
            {
                // since our respone_type in FacebookLoginDialog was token,
                // we got the access_token
                // The user now has successfully granted permission to our app. facebookOAuthResult.AccessToken

                // set token in settings
                Properties.Settings.Default.fbToken = Security.EncryptString(facebookOAuthResult.AccessToken, Security.encryptionPassw);
                Properties.Settings.Default.Save();

                // hide login button
                button5.Visible = false;

                // call function that returns the name of the logged person
                showFBName(facebookOAuthResult.AccessToken);
            }
            else
            {
                // for some reason we failed to get the access token.
                // most likely the user clicked don't allow.
                MessageBox.Show(facebookOAuthResult.ErrorDescription);
            }
        }
예제 #25
0
        private void UpdateLoginControl(FacebookOAuthResult r)
        {
            if (r != null)
            {

                List<string> s = MyHelper.getUserInfo(r.AccessToken, "me", FB_Image.UserImageDir);
                pBoxUserAvatar.ImageLocation = s[1];
                lbLoginUserName.Text = s[0];
                lbLoginID.Text = s[2];
                bool flag = false;
                //Set private album
                if (File.Exists(Path.Combine(FB_Image.RelativeDirectory, FB_Image.UserSettingDir,s[2])))
                {
                    UserSetting a = MyHelper.DeSerializeObject<UserSetting>(Path.Combine(FB_Image.RelativeDirectory, FB_Image.UserSettingDir , s[2]));
                    if (a != null)
                    {
                        Form1.ActiveUser = a;
                    }
                    else
                    {
                        Form1.ActiveUser = new UserSetting(r.AccessToken, s[0], s[2], r.Expires.ToString(), s[1]);
                        Form1.ActiveUser.CheckTime = MyHelper.GetUnixTimesStamp(DateTime.Now);
                    }

                    if (a != null && !string.IsNullOrEmpty(a.PrivateAlbumID) && !string.IsNullOrEmpty(a.PrivateAlbumName))
                    {
                        ActiveUser.PrivateAlbumID = a.PrivateAlbumID;
                        ActiveUser.PrivateAlbumName = a.PrivateAlbumName;
                        lbPrivateAlbum.Text = a.PrivateAlbumName.ToString();
                        lbLoginPrivateAlbum.Text = a.PrivateAlbumName.ToString();
                        flag = true;
                    }

                }
                else
                {
                    Form1.ActiveUser = new UserSetting(r.AccessToken, s[0], s[2], r.Expires.ToString(), s[1]);
                    Form1.ActiveUser.CheckTime = MyHelper.GetUnixTimesStamp(DateTime.Now);
                }
                LoadFriendList();
                //LoadMessage();

                if (!flag)
                {
                    CreateAlbum a = new CreateAlbum(ActiveUser.AccessToken);
                    a.StartPosition = FormStartPosition.CenterParent;
                    if (a.ShowDialog() == DialogResult.OK)
                    {
                        if (Form1.ActiveUser != null)
                        {
                            Form1.ActiveUser.PrivateAlbumID = a.AlbumID;
                            Form1.ActiveUser.PrivateAlbumName = a.AlbumName;
                            lbPrivateAlbum.Text = a.AlbumName.ToString();
                            lbLoginPrivateAlbum.Text = a.AlbumName.ToString();
                        }
                    }
                }
                ActiveUser.AccessToken = r.AccessToken;

                if (ActiveUser.Albums.Count == 0)
                {
                    ActiveUser.Albums = CreateAlbum.GetUserAlbumsForComboBox(ActiveUser.AccessToken, "all");
                }
                cmbInputAlbum.DataSource = ActiveUser.Albums;
                cmbInputAlbum.DisplayMember = "Name";
                cmbInputAlbum.ValueMember = "ID";

                btnFacebookLogin.Text = "LogOut";
                isLogin = true;

            }
            else
            {
                lbLoginUserName.Text = "...";
                lbLoginID.Text = "...";
                pBoxUserAvatar.Image = Properties.Resources.profile;
                Form1.ActiveUser = null;
                btnFacebookLogin.Text = "Login";
                lbPrivateAlbum.Text = "...";
                lbLoginPrivateAlbum.Text = "...";
                isLogin = false;
                cmbInputAlbum.Items.Clear();
            }
        }
예제 #26
0
        private Core.Entities.User AcceptFacebookOAuthToken(FacebookOAuthResult facebookOAuthResult)
        {
            Condition.Requires(facebookOAuthResult).IsNotNull();

            // Grab the code.
            string code = facebookOAuthResult.Code;

            // Grab the access token.
            FacebookOAuthClient facebookOAuthClient = FacebookOAuthClient;
            dynamic result = facebookOAuthClient.ExchangeCodeForAccessToken(code);

            var oauthData = new OAuthData
            {
                OAuthProvider = OAuthProvider.Facebook,
                AccessToken = result.access_token,
                ExpiresOn = DateTime.UtcNow.AddSeconds(result.expires)
            };

            // Now grab their info.
            var facebookWebClient = new FacebookWebClient(oauthData.AccessToken);
            dynamic facebookUser = facebookWebClient.Get("me");
            oauthData.Id = facebookUser.id;

            // Not sure how to Inject an IUserService because it requires a Session .. which I don't have.
            var userService = new UserService(DocumentSession);

            // Now associate this facebook user to an existing user OR create a new one.
            return userService.CreateOrUpdate(oauthData, facebookUser.username, facebookUser.name, facebookUser.email);
        }
예제 #27
0
        private static void CheckLoginResults(FacebookOAuthResult facebookOAuthResult)
        {
            if (facebookOAuthResult == null)
            {
                // the user closed the FacebookLoginDialog, so do nothing.
                throw new Exception("Login was cancelled!");
            }

            // Even though facebookOAuthResult is not null, it could had been an
            // OAuth 2.0 error, so make sure to check IsSuccess property always.
            if (facebookOAuthResult.IsSuccess)
            {
                // since our respone_type in FacebookLoginDialog was token,
                // we got the access_token
                // The user now has successfully granted permission to our app.
                LoggedIn = true;
                AccessToken = facebookOAuthResult.AccessToken;
                wasLoginCancelled = false;
                fb = new FacebookClient(AccessToken);
                fb.AppId = API_KEY;
                fb.AppSecret = APP_SECRET;
            }
            else
            {
                // for some reason we failed to get the access token.
                // most likely the user clicked don't allow.
                wasLoginCancelled = false;
                throw new Exception(facebookOAuthResult.ErrorDescription);
            }
        }
예제 #28
0
        public void ErrorDescriptionShouldBeNull()
        {
            var result = new FacebookOAuthResult(new Dictionary<string, object>());

            Assert.Null(result.ErrorDescription);
        }
        private AuthorizeState TranslateResponseState(string returnUrl, FacebookOAuthResult oAuthResult)
        {
            if (oAuthResult.IsSuccess)
            {
                var parameters = new OAuthAuthenticationParameters(Provider.SystemName)
                {
                    ExternalIdentifier = GetAccessToken(oAuthResult.Code),
                    OAuthToken = oAuthResult.Code,
                    OAuthAccessToken = GetAccessToken(oAuthResult.Code)
                };

                if (_externalAuthenticationSettings.AutoRegisterEnabled)
                    GetClaims(parameters);

                var result = _authorizer.Authorize(parameters);

                return new AuthorizeState(returnUrl, result);
            }

            var state = new AuthorizeState(returnUrl, OpenAuthenticationStatus.Error);
            state.AddError(string.Format("Reason: {0}, Description: {1}", oAuthResult.ErrorReason, oAuthResult.ErrorDescription));
            return state;
        }
예제 #30
0
 /// <summary>
 /// Try parsing the uri to <see cref="FacebookOAuthResult"/>.
 /// </summary>
 /// <param name="uri">
 /// The url to parse.
 /// </param>
 /// <param name="result">
 /// An instance of <see cref="FacebookOAuthResult"/>.
 /// </param>
 /// <returns>
 /// Returns true if parsing was successful otherwise false.
 /// </returns>
 public static bool TryParse(Uri uri, out FacebookOAuthResult result)
 {
     result = Parse(uri, false);
     return result != null;
 }
예제 #31
0
        /// <summary>
        /// Try parsing the uri to <see cref="FacebookOAuthResult"/>.
        /// </summary>
        /// <param name="uriString">
        /// The url to parse.
        /// </param>
        /// <param name="result">
        /// An instance of <see cref="FacebookOAuthResult"/>.
        /// </param>
        /// <returns>
        /// Returns true if parsing was successful otherwise false.
        /// </returns>
        public static bool TryParse(string uriString, out FacebookOAuthResult result)
        {
            if (Uri.IsWellFormedUriString(uriString, UriKind.RelativeOrAbsolute))
            {
                return TryParse(new Uri(uriString), out result);
            }

            result = null;
            return false;
        }
예제 #32
0
        public void CodeShouldBeNull()
        {
            var result = new FacebookOAuthResult(new Dictionary<string, object>());

            Assert.Null(result.Code);
        }
예제 #33
0
        public void AccessTokenShouldBeNull()
        {
            var result = new FacebookOAuthResult(new Dictionary<string, object>());

            Assert.Null(result.AccessToken);
        }