2017-04-13 46 views
1

我創建了啓用了個人身份驗證的MVC SPA應用程序。並將所有OWIN DLL更新到3.1.0版本。 'startup.cs(來自DeConsole)facebook oAuth外部身份驗證重定向網址在MVC中無效

已在登錄頁面啓用'Facebook'按鈕,並點擊它將我帶到FB登錄頁面以提供我的憑據。登錄後,它沒有任何確認,如谷歌問(應用程序嘗試訪問您的基本信息允許/拒絕),然後重定向回到應用程序。但沒有從FB獲得任何基本信息。我在這裏丟失了什麼 返回的網址總是localhost:33343 /帳戶/登錄#= _ ..

我以爲微軟 提供我們需要的一切,但實際上並非如此。

回答

0

您必須從OWIN中間件獲取acccess_denied。嘗試將調試器放入帳戶控制器操作「ExternalLoginCallback」中。

我假設你已經在facebook中添加了http://your_domain/signin-facebook作爲允許的redirect_uri。請注意,https在這裏不是強制性的,如果它是http,Facebook仍然提供憑據。

我還假設您已將您的nuget軟件包更新到Microsoft.Owin.Security.Facebook 3.1.0。 有用的鏈接:https://github.com/aspnet/AspNetKatana/issues/38

請參閱:https://developers.facebook.com/docs/facebook-login/permissions以查看允許的權限。詢問適當的範圍和領域,如下代碼:

var facebookAuthenticationOptions = new FacebookAuthenticationOptions() 
     { 
      AppId = "....", 
      AppSecret = "....", 

      AuthenticationType = "Facebook", 
      SignInAsAuthenticationType = DefaultAuthenticationTypes.ExternalCookie,     

      Provider = new FacebookAuthenticationProvider 
      { 
       OnAuthenticated = async ctx => 
       { 
        ctx.Identity.AddClaim(new Claim("FacebookAccessToken", ctx.AccessToken)); 
        foreach (var claim in ctx.User) 
        { 
         var claimType = string.Format("urn:facebook:{0}", claim.Key); 
         string claimValue = claim.Value.ToString(); 

         if (!ctx.Identity.HasClaim(claimType, claimValue)) 
         { 
          ctx.Identity.AddClaim(new Claim(claimType, claimValue, "XmlSchemaString", "Facebook")); 
         } 
        }     
       } 

      } 
     }; 

     // Set requested scope 
     facebookAuthenticationOptions.Scope.Add("email"); 
     facebookAuthenticationOptions.Scope.Add("public_profile"); 

     // Set requested fields 
     facebookAuthenticationOptions.Fields.Add("email"); 
     facebookAuthenticationOptions.Fields.Add("first_name"); 
     facebookAuthenticationOptions.Fields.Add("last_name");     

     app.UseFacebookAuthentication(facebookAuthenticationOptions); 
+0

謝謝!有效 – DevExpress