简体   繁体   English

Asp.Net身份:用facebook登录

[英]Asp.Net Identity: Login with facebook

I just created an ASP.Net MVC project inside my solution, following these instructions 我按照these instructions在我的解决方案中创建了一个ASP.Net MVC项目

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: 在成功使用自定义IUserStore登录并创建用户IUserStore ,我按照these instructions进行these instructions以允许使用诸如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 编辑:我正在使用.net Framework 4.5,MVC v5和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: 如果您想从Facebook提供商处索取更多信息,只需在OwinStartup.cs中添加如下内容:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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