c# - Facebook login returns Failure in ASP.NET MVC -


i trying implement facebook login in asp.net mvc app.

everytime tries run signinmanager.externalsigninasync(logininfo, ispersistent: false), returns failure

here's code-

startup.auth.cs

app.usefacebookauthentication(    appid: social_networkbll.facebook_appid,    appsecret: social_networkbll.facebook_secretid ); 

accountcontroller

[httppost] [allowanonymous] [validateantiforgerytoken] public actionresult externallogin(string provider, string returnurl) {     // request redirect external login provider     return new challengeresult(provider, url.action("externallogincallback", "account", new { returnurl = returnurl })); }  [allowanonymous] public async task<actionresult> externallogincallback(string returnurl) {     var logininfo = await authenticationmanager.getexternallogininfoasync();     if (logininfo == null)     {         return redirecttoaction("login");     }      // sign in user external login provider if user has login     var result = await signinmanager.externalsigninasync(logininfo, ispersistent: false);     switch (result)     {         case signinstatus.success:             return redirecttolocal(returnurl);         case signinstatus.lockedout:             return view("lockout");         case signinstatus.requiresverification:             return redirecttoaction("sendcode", new { returnurl = returnurl, rememberme = false });         case signinstatus.failure:             return redirecttoaction("login");         default:             // if user not have account, prompt user create account             viewbag.returnurl = returnurl;             viewbag.loginprovider = logininfo.login.loginprovider;             //return view("externalloginconfirmation", new externalloginconfirmationviewmodel { email = logininfo.email });              externalloginconfirmationviewmodel vm = new externalloginconfirmationviewmodel { email = logininfo.email };             //return redirecttoaction("externalloginconfirmation", new { model = vm, returnurl = returnurl });             return await externalloginconfirmation(vm, returnurl);     } } 

fb app settings enter image description here

signinstatus.failure indicates whether user registered on site or not. default asp.net mvc account controller's exernallogincallback looks this.

 //         // get: /account/externallogincallback         [allowanonymous]         public async task<actionresult> externallogincallback(string returnurl)         {             var logininfo = await authenticationmanager.getexternallogininfoasync();             if (logininfo == null)             {                 return redirecttoaction("login");             }              // sign in user external login provider if user has login             var result = await signinmanager.externalsigninasync(logininfo, ispersistent: false);             switch (result)             {                 case signinstatus.success:                     return redirecttolocal(returnurl);                 case signinstatus.lockedout:                     return view("lockout");                 case signinstatus.requiresverification:                     return redirecttoaction("sendcode", new { returnurl = returnurl, rememberme = false });                 case signinstatus.failure:                 default:                     // if user not have account, prompt user create account                     viewbag.returnurl = returnurl;                     viewbag.loginprovider = logininfo.login.loginprovider;                     return view("externalloginconfirmation", new externalloginconfirmationviewmodel { email = logininfo.email });             }         } 

in code above, redirecting login page on case signinstatus.failure. remove redirecttoaction("login");


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -