当前位置: 首页>>代码示例>>C#>>正文


C# Twitter.VerifyCredentials方法代码示例

本文整理汇总了C#中Twitter.VerifyCredentials方法的典型用法代码示例。如果您正苦于以下问题:C# Twitter.VerifyCredentials方法的具体用法?C# Twitter.VerifyCredentials怎么用?C# Twitter.VerifyCredentials使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Twitter的用法示例。


在下文中一共展示了Twitter.VerifyCredentials方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExternalLoginCallback

        public ActionResult ExternalLoginCallback(string returnUrl)
        {
            var externalLoginModel = new ExternalLoginModel();

            var result = OAuthWebSecurity.VerifyAuthentication(Url.Action("ExternalLoginCallback", new { ReturnUrl = returnUrl }));
            if (!result.IsSuccessful)
            {
                return RedirectToAction("ExternalLoginFailure");
            }

            if (OAuthWebSecurity.Login(result.Provider, result.ProviderUserId, false))
            {
                //ModelState.AddModelError("", "This external account is already associated with your account.");
                return RedirectToLocal(returnUrl);
            }

            switch (result.Provider)
            {
                case "facebook":
                    externalLoginModel.UserName = result.UserName;
                    externalLoginModel.DisplayName = result.ExtraData["name"];
                    if (result.ExtraData.Keys.Contains("accesstoken"))
                    {
                        var facebookClient = new Facebook.FacebookClient(result.ExtraData["accesstoken"]);
                        dynamic response = facebookClient.Get("me", new { fields = "verified" });
                        externalLoginModel.FbVerified = response.ContainsKey("verified") && response["verified"];
                    }

                    break;
                case "twitter":
                    externalLoginModel.UserName = "";
                    externalLoginModel.DisplayName = result.UserName;
                    if (result.ExtraData.Keys.Contains("accesstoken") && result.ExtraData.Keys.Contains("accesssecret"))
                    {
                        var twitterClient = new Twitter(ConfigurationManager.AppSettings["TwitterConsumerKey"], ConfigurationManager.AppSettings["TwitterConsumerSecret"], result.ExtraData["accesstoken"], result.ExtraData["accesssecret"]);
                        externalLoginModel.TwitterVerified = twitterClient.VerifyCredentials();
                    }
                    break;
                case "google":
                    externalLoginModel.UserName = result.UserName;
                    externalLoginModel.DisplayName = result.UserName;
                    break;
                default:
                    externalLoginModel.UserName = "";
                    externalLoginModel.DisplayName = "";
                    break;
            }

            if (User.Identity.IsAuthenticated)
            {
                if (ModelState.IsValid)
                {
                    var user = _userRepository.Find(x => x.UserName.ToLower() == User.Identity.Name.ToLower());
                    if (user != null)
                    {
                        if (externalLoginModel.FbVerified)
                        {
                            user.FbVerified = true;
                        }
                        if (externalLoginModel.TwitterVerified)
                        {
                            user.TwitterVerified = true;
                        }
                        using (var uow = new UnitOfWork())
                        {

                            using (_userRepository = new GenericRepository<UserProfile>(uow))
                            {
                                    _userRepository.Update(user);
                            }
                            uow.Save();
                        }
                    }
                }
                // If the current user is logged in add the new account
                OAuthWebSecurity.CreateOrUpdateAccount(result.Provider, result.ProviderUserId, User.Identity.Name);
                return RedirectToLocal(returnUrl);
            }
            // User is new, ask for their desired membership name
            var loginData = OAuthWebSecurity.SerializeProviderUserId(result.Provider, result.ProviderUserId);
            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(result.Provider).DisplayName;
            ViewBag.ReturnUrl = returnUrl;

            return View("ExternalLoginConfirmation", new RegisterExternalLoginModel { UserName = externalLoginModel.UserName, ExternalLoginData = loginData, DisplayName = externalLoginModel.DisplayName, FbVerified = externalLoginModel.FbVerified, TwitterVerified = externalLoginModel.TwitterVerified});
        }
开发者ID:jknopp,项目名称:HypeTheFest,代码行数:85,代码来源:AccountController.cs


注:本文中的Twitter.VerifyCredentials方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。