本文整理汇总了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});
}