private async void webBrowser_Navigating(object sender, NavigatingEventArgs e) { if (e.Uri.ToString().StartsWith("https://www.facebook.com/connect/login_success.html")) { e.Cancel = true; WebViewBorder.Visibility = System.Windows.Visibility.Collapsed; LoginButtonBorder.Visibility = System.Windows.Visibility.Collapsed; LoggedInPanel.Visibility = System.Windows.Visibility.Visible; if (Pulsate.GetCurrentState() != ClockState.Active) { Pulsate.RepeatBehavior = RepeatBehavior.Forever; Pulsate.Begin(); } FacebookUser user = null; string accessToken = ""; try { accessToken = e.Uri.ToString().Substring(e.Uri.ToString().IndexOf("access_token=") + "access_token=".Length); if (accessToken.IndexOf("&") > 0) { accessToken = accessToken.Substring(0, accessToken.IndexOf("&")); } user = await FacebookUserResponse.GetFacebookUser(accessToken); } catch { } if (user == null) { if (Pulsate.GetCurrentState() == ClockState.Active) { Pulsate.Stop(); } await webBrowser.ClearCookiesAsync(); WebViewBorder.Visibility = System.Windows.Visibility.Collapsed; LoginButtonBorder.Visibility = System.Windows.Visibility.Visible; LoggedInPanel.Visibility = System.Windows.Visibility.Collapsed; MessageBox.Show("Unable to login using Facebook. Please try again."); } else { await Authenticate(accessToken, user.Id); } } }
//private async void webBrowser_Navigating(object sender, NavigatingEventArgs e) //{ // // mockado // await Authenticate("453253", _requestToken); //} private async void webBrowser_Navigating(object sender, NavigatingEventArgs e) { if (e.Uri.ToString().StartsWith("https://www.linkedin.com/sucess.htm")) { e.Cancel = true; WebViewBorder.Visibility = System.Windows.Visibility.Collapsed; LoginButtonBorder.Visibility = System.Windows.Visibility.Collapsed; LoggedInPanel.Visibility = System.Windows.Visibility.Visible; if (Pulsate.GetCurrentState() != ClockState.Active) { Pulsate.RepeatBehavior = RepeatBehavior.Forever; Pulsate.Begin(); } //FacebookUser user = null; //string accessToken = ""; try { //accessToken = e.Uri.ToString().Substring(e.Uri.ToString().IndexOf("access_token=") + "access_token=".Length); //accessToken = _accessToken; string queryParams = e.Uri.Query; if (queryParams.Length > 0) { QueryString qs = new QueryString(queryParams); if (qs["oauth_verifier"] != null) { this._oAuthVerifier = qs["oauth_verifier"]; } } //if (accessToken.IndexOf("&") > 0) // accessToken = accessToken.Substring(0, accessToken.IndexOf("&")); //user = await FacebookUserResponse.GetFacebookUser(accessToken); await this.GetAccessToken(); } catch { } if (_oAuthVerifier == "") { if (Pulsate.GetCurrentState() == ClockState.Active) { Pulsate.Stop(); } await webBrowser.ClearCookiesAsync(); WebViewBorder.Visibility = System.Windows.Visibility.Collapsed; LoginButtonBorder.Visibility = System.Windows.Visibility.Visible; LoggedInPanel.Visibility = System.Windows.Visibility.Collapsed; MessageBox.Show("Unable to login using Linkedin. Please try again."); } //if (user == null) //{ // if (Pulsate.GetCurrentState() == ClockState.Active) // { // Pulsate.Stop(); // } // await webBrowser.ClearCookiesAsync(); // WebViewBorder.Visibility = System.Windows.Visibility.Collapsed; // LoginButtonBorder.Visibility = System.Windows.Visibility.Visible; // LoggedInPanel.Visibility = System.Windows.Visibility.Collapsed; // MessageBox.Show("Unable to login using Facebook. Please try again."); //} else { await Authenticate(_accessToken, _requestToken); } } }