Exemplo n.º 1
0
        private void manualLoginToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Clipboard.SetText(authorizationUrlString);
            MessageBox.Show(this,
                            @"Manual login URL has been copied into your clipboard!" + Environment.NewLine +
                            @" Open your web browser and paste URL into address bar." + Environment.NewLine + @"Fill the PIN code in next form.",
                            @"Manual login process", MessageBoxButtons.OK, MessageBoxIcon.Information);
            TextInputForm tiform = new TextInputForm();

            if (DialogResult.OK == tiform.ShowDialog(this))
            {
                Login.Authenticate(tiform.UserText.Trim());
                DialogResult = DialogResult.OK;
                Close();
            }
        }
Exemplo n.º 2
0
        public async Task LoginAsync(string provider)
        {
            var account = new SimpleAuth.Account();

            switch (provider)
            {
            case Constants.Providers.Google:
                var clientId          = Device.RuntimePlatform == Device.iOS ? Constants.ApiInfo.GoogleInfo.GoogleiOSClientId : Constants.ApiInfo.GoogleInfo.GoogleWebClientId;
                var clientSecret      = Device.RuntimePlatform == Device.iOS ? null : Constants.ApiInfo.GoogleInfo.GoogleClientSecret;
                var googAuthenticator = new GoogleApi(Constants.Providers.Google, clientId, clientSecret)
                {
                    Scopes = Constants.ApiInfo.GoogleInfo.GoogleScopes
                };
                account = await googAuthenticator.Authenticate();

                break;

            case Constants.Providers.Facebook:
                var facebookAuthenticator = new FacebookApi(Constants.Providers.Facebook, Constants.ApiInfo.FacebookInfo.FacebookAppId, Constants.ApiInfo.FacebookInfo.FacebookSecret);
                account = await facebookAuthenticator.Authenticate();

                break;

            case Constants.Providers.Microsoft:
                var microsoftAuthenticator = new MicrosoftLiveConnectApi(Constants.Providers.Microsoft, Constants.ApiInfo.MicrosoftInfo.MicrosoftAppId, Constants.ApiInfo.MicrosoftInfo.MicrosoftSecret)
                {
                    Scopes = Constants.ApiInfo.MicrosoftInfo.MicrosoftScopes
                };
                account = await microsoftAuthenticator.Authenticate();

                break;

            case Constants.Providers.Twitter:
                var twitterAuthenticator = new TwitterApi(Constants.Providers.Twitter, Constants.ApiInfo.TwitterInfo.TwitterAppId, Constants.ApiInfo.TwitterInfo.TwitterSecret)
                {
                    RedirectUrl = new Uri("https://mobile.twitter.com/home")
                };
                account = await twitterAuthenticator.Authenticate();

                break;

            case Constants.Providers.Local:
                break;

            default:
                break;
            }

            var oauthAccount = account as SimpleAuth.OAuthAccount;

            if (!string.IsNullOrEmpty(oauthAccount.Token))
            {
                await StoreToken(oauthAccount.Token);

                _navigation.NavigateToRoot <MainPageViewModel>(true, null);
            }
            return;
        }
Exemplo n.º 3
0
        public ActionResult TwitterCallback(string oauth_token, string oauth_verifier)
        {
            if (oauth_token == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            var requestToken = new OAuthRequestToken {
                Token = oauth_token
            };
            string Token, TokenSecret;

            Token = ""; TokenSecret = "";
            twitter.Authenticate(requestToken, oauth_verifier, ref Token, ref TokenSecret);
            TwitterUser user = twitter.userInfo();                                                    //get user's info

            if (OAuthWebSecurity.Login("twitter", user.Id.ToString(), createPersistentCookie: false)) //if has account then login
            {
                return(RedirectToAction("Index", "Home"));                                            //go back to the home page
            }
            if (User.Identity.IsAuthenticated)                                                        //used when adding an external loggin
            {
                // If the current user is logged in add the new account
                DatabaseCallsApi _api = new DatabaseCallsApi();

                _api.AddOrUpdateService(WebSecurity.CurrentUserId, "twitter", Token, TokenSecret); //set the service for the user

                OAuthWebSecurity.CreateOrUpdateAccount("twitter", user.Id.ToString(), WebSecurity.CurrentUserName);

                return(RedirectToAction("Index", "Home")); //go back to the home page
            }
            else
            {
                // User is new, ask for their desired membership name

                CheckChanceState();

                string loginData = OAuthWebSecurity.SerializeProviderUserId("twitter", user.Id.ToString());
                ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData("twitter").DisplayName;
                if (Token != "" && TokenSecret != "")
                {
                    Session["AccessToken"]       = Token;
                    Session["AccessTokenSecret"] = TokenSecret;
                }
                return(View("ExternalLoginConfirmation", new RegisterExternalLoginModel {
                    UserName = user.ScreenName, ExternalLoginData = loginData
                }));
            }
        }
Exemplo n.º 4
0
        public async Task <bool> LoginToTwitter()
        {
            try
            {
#if __IOS__
                if (Device.HasIntegratedTwitter)
                {
                    return(await LoginTwitterOld());
                }
#endif
                var account = await twitter.Authenticate();

                var user = await twitter.Get <Dictionary <string, string> >("account/verify_credentials.json");

                Settings.TwitterDisplay = user["name"];
                Settings.TwitterAccount = user["id"];
                return(true);
            }
            catch (Exception x)
            {
                Console.WriteLine(x);
            }
            return(false);
        }