我正在使用带有 mvc6(测试版)的 asp.net 5,我想使用 microsoft owin 来允许我的用户使用他们的 facebook 帐户登录。在 Startup.cs 中,我无法在从 NuGet 安装 Microsoft.Owin.Security.Facebook 包后执行“app.UseFacebookAuthentication”。
有教程吗?是否可以在 MVC6 中使用声明?
谢谢。
最佳答案
设置 Facebook 应用: 登录 https://developers.facebook.com/apps 并为网站创建一个新应用程序。跳过快速启动。记下 App id 和 app secret。 转到设置并粘贴您的网站地址。按“添加平台”,然后选择网站。
安装 SecretManager 工具: 通过在您的应用程序文件夹中运行此命令来安装 SecretManager 工具:
dnu commands install Microsoft.Extensions.SecretManager
运行命令存储AppId和AppSecret:
user-secret set Authentication:Facebook:AppId 123123
user-secret set Authentication:Facebook:AppSecret 456456
在project.json中添加依赖:
"Microsoft.AspNet.Owin": "1.0.0-rc1-final",
"Microsoft.AspNet.Authentication.Facebook": "1.0.0-rc1-final"
在Configure部分向startup.cs添加行
// Use Facebook authentication ( see http://go.microsoft.com/fwlink/?LinkID=532715 ).
app.UseFacebookAuthentication(options =>
{
options.AppId = Configuration["Authentication:Facebook:AppId"];
options.AppSecret = Configuration["Authentication:Facebook:AppSecret"];
});
在本教程中阅读更多内容,它向您展示如何构建一个 ASP.NET 5 Web 应用程序,使用户能够使用来自外部身份验证提供商(例如 Facebook、Twitter、LinkedIn、Microsoft 或 Google)的凭据使用 OAuth 2.0 进行登录. http://aspnetmvc.readthedocs.org/en/latest/security/sociallogins.html
关于c# - Asp.net 5 MVC6 - 使用 owin 进行 facebook 登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27043485/