';SignInScheme';必须提供选项
本文关键字:选项 SignInScheme | 更新日期: 2023-09-27 18:29:13
我正在创建一个仅使用Facebook/Google身份验证的ASP.NET 5 MVC 6应用程序。我还试图在没有整个ASP.NET Identity的情况下使用cookie中间件——下面是本文:https://docs.asp.net/en/latest/security/authentication/cookie.html
因此,我从一个没有身份验证的空白应用程序开始,然后添加了Microsoft.AspNet.authentication.Cookies和Microsoft.AspNet.Authentications.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
全局设置它(它将配置每个身份验证中间件,这样您就不必设置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";
});
}