简体   繁体   中英

Asp.Net Identity: Login with facebook

I just created an ASP.Net MVC project inside my solution, following these instructions

After successfully being able to login and create users with a custom IUserStore , I followed these instructions to allow login with social networks like facebook:

Unfortunately, after doing this, I realized that the login does not work, since this code simply hangs:

private async Task SignInAsync(User user, bool isPersistent)
    {
        AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
        var identity = await UserManager.CreateIdentityAsync(user, 
                                DefaultAuthenticationTypes.ApplicationCookie);
        AuthenticationManager.SignIn(new AuthenticationProperties() { 
                           IsPersistent = isPersistent }, identity);
    }

I tried stepping into or looking for documentation about it, but I'm A bit lost...

identity = await UserManager.CreateIdentityAsync(user, 
                     DefaultAuthenticationTypes.ApplicationCookie);

Any ideas?

EDIT: I'm using .net Framework 4.5, MVC v5 and Visual Studio 2013

You can try this tutorial

It is simple and works pretty good for me.

If you want to claim additional info from Facebook provider, then simply add to your OwinStartup.cs something like that:

FacebookAuthenticationOptions facebookOptions = new FacebookAuthenticationOptions()
{
    AppId = "PutYourFacebookAppIdHere",
    AppSecret = "PutYourFacebookAppSecretHere"
};
facebookOptions.Scope.Add("email");
app.UseFacebookAuthentication(facebookOptions);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM