Exemplo n.º 1
0
        void requestTokenQuery_QueryResponse(object sender, WebQueryResponseEventArgs e)
        {
            try
            {
                StreamReader reader      = new StreamReader(e.Response);
                string       strResponse = reader.ReadToEnd();
                var          parameters  = MainUtil.GetQueryParameters(strResponse);
                OAuthTokenKey = parameters["oauth_token"];
                tokenSecret   = parameters["oauth_token_secret"];
                var authorizeUrl = AppSettings.AuthorizeUri + "?oauth_token=" + OAuthTokenKey;

                Dispatcher.BeginInvoke(() =>
                {
                    this.AuthenticationBrowser.Navigate(new Uri(authorizeUrl, UriKind.RelativeOrAbsolute));
                });
            }
            catch (Exception ex)
            {
                Dispatcher.BeginInvoke(() =>
                {
                    MessageBox.Show("Twitter login error: " + ex.ToString());
                });
            }
        }
Exemplo n.º 2
0
        private void BrowserNavigated(object sender, NavigationEventArgs e)
        {
            if (App.loginselected == 1)
            {
                if (string.IsNullOrEmpty(e.Uri.Fragment))
                {
                    return;
                }
                if (e.Uri.AbsoluteUri.Replace(e.Uri.Fragment, "") == "http://www.iitkgp.ac.in/?" || e.Uri.AbsoluteUri.Replace(e.Uri.Fragment, "") == "https://www.google.co.in/?")
                {
                    string text = HttpUtility.HtmlDecode(e.Uri.Fragment).TrimStart('#');
                    //char [] separators = {'&',';'};
                    var pairs = text.Split('&');
                    foreach (var pair in pairs)
                    {
                        var kvp = pair.Split('=');
                        if (kvp.Length == 2)
                        {
                            if (kvp[0] == "access_token")
                            {
                                fbAccessToken = kvp[1];
                                MessageBox.Show("Access granted");
                                App.fbaccesstokenkey = fbAccessToken;
                                App.writeBackToken();
                            }
                        }
                    }

                    if (string.IsNullOrEmpty(fbAccessToken))
                    {
                        MessageBox.Show("Unable to authenticate facebook");
                    }
                }
                NavigationService.GoBack();
            }
            if (App.loginselected == 3)
            {
                if (e.Uri.ToString().StartsWith("http://www.iitkgp.ac.in/"))
                {
                    if (e.Uri.ToString().ToLower().Contains("error"))
                    {
                        MessageBox.Show("Unable to authenticate linkedin");
                    }
                    else
                    {
                        string   ret = e.Uri.ToString();
                        string[] arr = ret.Split('?');
                        arr = arr[1].Split('&');
                        if (arr[0].Split('=')[0].Equals("code"))
                        {
                            if (arr[1].Split('=')[1].Equals(state))
                            {
                                authcode = arr[0].Split('=')[1];
                                getLdAccessToken();
                            }
                            else
                            {
                                MessageBox.Show("Unable to authenticate linkedin");
                                NavigationService.GoBack();
                            }
                        }
                        else
                        {
                            MessageBox.Show("Unable to authenticate linkedin");
                            NavigationService.GoBack();
                        }
                    }
                }
            }
            if (App.loginselected == 2)
            {
                if (e.Uri.ToString().StartsWith(AppSettings.CallbackUri))
                {
                    if (e.Uri.ToString().ToLower().Contains("oauth_verifier"))
                    {
                        var AuthorizeResult = MainUtil.GetQueryParameters(e.Uri.ToString());
                        var VerifyPin       = AuthorizeResult["oauth_verifier"];
                        this.AuthenticationBrowser.Visibility = Visibility.Collapsed;
                        var AccessTokenQuery = OAuthUtil.GetAccessTokenQuery(OAuthTokenKey, tokenSecret, VerifyPin);

                        AccessTokenQuery.QueryResponse += new EventHandler <WebQueryResponseEventArgs>(AccessTokenQuery_QueryResponse);
                        AccessTokenQuery.RequestAsync(AppSettings.AccessTokenUri, null);
                    }
                    else
                    {
                        MessageBox.Show("Unable to authenticate twitter");

                        NavigationService.GoBack();
                    }
                }
            }
        }