2014-03-02 99 views
0

當我創建一個新的mvc網站時,它會自動創建AccountController.cs控制器。在這個課堂中,有一個動作可以從社交網絡登錄。如何獲得更多關於標準mvc應用程序的信息

[AllowAnonymous] 
    public ActionResult ExternalLoginCallback(string returnUrl) 
    { 
     AuthenticationResult result = OAuthWebSecurity.VerifyAuthentication(Url.Action("ExternalLoginCallback", new { ReturnUrl = returnUrl })); 
     if (!result.IsSuccessful) 
     { 
      return RedirectToAction("ExternalLoginFailure"); 
     } 

     if (OAuthWebSecurity.Login(result.Provider, result.ProviderUserId, createPersistentCookie: false)) 
     { 
      return RedirectToLocal(returnUrl); 
     } 

     if (User.Identity.IsAuthenticated) 
     { 
      // If the current user is logged in add the new account 
      OAuthWebSecurity.CreateOrUpdateAccount(result.Provider, result.ProviderUserId, User.Identity.Name); 
      return RedirectToLocal(returnUrl); 
     } 
     else 
     { 
      // User is new, ask for their desired membership name 
      string loginData = OAuthWebSecurity.SerializeProviderUserId(result.Provider, result.ProviderUserId); 
      ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(result.Provider).DisplayName; 
      ViewBag.ReturnUrl = returnUrl; 
      return View("ExternalLoginConfirmation", new RegisterExternalLoginModel { UserName = result.UserName, ExternalLoginData = loginData }); 
     } 
    } 

我已經添加了twitter secret和api id。但在回調中,我只有用戶名。但我也想要用戶的真實姓名信息。

同樣的事情也需要google和facebook登錄。

回答

0

大多數社交網絡API都有一個端點,用於在使用OAuth令牌進行身份驗證後獲取其他用戶信息。例如,對於Twitter,端點是https://dev.twitter.com/docs/api/1.1/get/account/verify_credentials - 您必須發送令牌和令牌密鑰(您通過身份驗證從OAuth提供程序獲得),並且您將收到Twitter提供的用戶信息。

相關問題