2016-04-06 30 views
0

Bugün projemde harici facebook giriş yapmayı denedim.C# - Owin Oauth harici giriş sayfasına yönlendirmiyor

Ama ExternalLogin yöntemini çağırarak giriş çalıştığınızda, bu yöntem Facebook giriş sayfasına dönmez bunu yapmaya çalıştım: https://coding.abel.nu/2014/06/understanding-the-owin-external-authentication-pipeline/

Ve benim bağlamını görünce AuthenticationResponseChallenge boş. ,

Startup.Auth.cs

 app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); 

     var fao = new FacebookAuthenticationOptions 
     { 
      AppId = APP_ID_FACEBOOK, //on Web.config 
      AppSecret = APP_SECRET_FACEBOOK //on Web.config 
     }; 

     fao.Scope.Add("email"); 
     fao.Scope.Add("basic_info"); 

     fao.Provider = new FacebookAuthenticationProvider() 
     { 
      OnAuthenticated = (context) => 
      { 
       context.Identity.AddClaim(new System.Security.Claims.Claim("urn:facebook:access_token", context.AccessToken, XmlSchemaString, "Facebook")); 
       foreach (var x in context.User) 
       { 
        var claimType = string.Format("urn:facebook:{0}", x.Key); 
        string claimValue = x.Value.ToString(); 
        if (!context.Identity.HasClaim(claimType, claimValue)) 
         context.Identity.AddClaim(new System.Security.Claims.Claim(claimType, claimValue, XmlSchemaString, "Facebook")); 

       } 
       return Task.FromResult(0); 
      } 
     }; 

     fao.SignInAsAuthenticationType = DefaultAuthenticationTypes.ExternalCookie; 
     app.UseFacebookAuthentication(fao); 

AccountController.cs

Ben facebook uygulaması kimlik bilgileriyle boş bir proje oluşturmak için çalıştı ve iyi çalıştı
public ActionResult ExternalLogin(string provider, string returnUrl) 
    { 

     var result = new ChallengeResult(provider, Url.Action("ExternalLoginCallback", "Conta", new { ReturnUrl = returnUrl })); 
     return result; 
    } 


    private const string XsrfKey = "XsrfId"; 

    internal class ChallengeResult : HttpUnauthorizedResult 
    { 
     public ChallengeResult(string provider, string redirectUri) 
      : this(provider, redirectUri, null) 
     { 
     } 

     public ChallengeResult(string provider, string redirectUri, string userId) 
     { 
      LoginProvider = provider; 
      RedirectUri = redirectUri; 
      UserId = userId; 
     } 

     public string LoginProvider { get; set; } 
     public string RedirectUri { get; set; } 
     public string UserId { get; set; } 

     public override void ExecuteResult(ControllerContext context) 
     { 
      var properties = new AuthenticationProperties { RedirectUri = RedirectUri }; 
      if (UserId != null) 
      { 
       properties.Dictionary[XsrfKey] = UserId; 
      } 

      context.HttpContext.GetOwinContext().Authentication.Challenge(properties, LoginProvider); 
     } 
    } 

:

yasalara uyun ama bu projede bu çalışmaz

Bana yardım edebilecek kimse yok mu?

+0

Ne demek, işe yaramıyor? Bunu açıklayabilir misin? –

+0

Challenger, facebook'ta oturum açmak için url oluşturmuyor ve ExternalLogin yanıtı 302 ve boş – aarcangelo

cevap

0

bir günün ardından, i challeger sonra formu göndermek facebook login yönlendirmek başladı ben

<authentication mode="None" /> 

değiştirildi zaman

Benim WebConfig

<authentication mode="Forms"> 
    <forms loginUrl="~/Login" name=".ASPXFORMSAUTH" /> 
</authentication> 

oldu çözüm buldu .

İlgili konular