必须提供“SignInScheme”选项

我正在创建一个仅使用Facebook / Google身份validation的ASP.NET 5 MVC 6应用程序。 我也试图在没有整个ASP.NET身份的情况下使用cookie中间件 – 遵循这篇文章: https : //docs.asp.net/en/latest/security/authentication/cookie.html

所以我开始使用没有身份validation的空白应用程序然后添加了Microsoft.AspNet.Authentication.Cookies和Microsoft.AspNet.Authentication.Facebook NuGet包,以便采用非常简约的方法,其中我不包含任何我不包含的内容需要。

我将以下代码添加到Startup.cs中的Configure中,但我得到“必须提供SignInScheme选项”错误。 知道我错过了什么吗?

app.UseCookieAuthentication(options => { options.AuthenticationScheme = "MyCookieMiddlewareInstance"; options.LoginPath = new PathString("/Accounts/Login/"); options.AccessDeniedPath = new PathString("/Error/Unauthorized/"); options.AutomaticAuthenticate = true; options.AutomaticChallenge = true; }); app.UseFacebookAuthentication(options => { options.AppId = "myFacebookAppIdGoesHere"; options.AppSecret = "myFacebookAppSecretGoesHere"; }); 

如您所看到的错误消息所示,您需要在Facebook中间件选项中设置options.SignInScheme

 app.UseFacebookAuthentication(options => { options.AppId = "myFacebookAppIdGoesHere"; options.AppSecret = "myFacebookAppSecretGoesHere"; // This value must correspond to the instance of the cookie // middleware used to create the authentication cookie. options.SignInScheme = "MyCookieMiddlewareInstance"; }); 

或者,您也可以从ConfigureServices全局设置它(它将配置每个身份validation中间件,因此您不必设置options.SignInScheme ):

 public void ConfigureServices(IServiceCollection services) { services.AddAuthentication(options => { // This value must correspond to the instance of the cookie // middleware used to create the authentication cookie. options.SignInScheme = "MyCookieMiddlewareInstance"; }); }