必须提供"SignInScheme"选项

Sam*_*Sam 8 c# cookies facebook-authentication asp.net-core-mvc asp.net-core

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

所以我开始使用没有身份验证的空白应用程序然后添加了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";
            });
Run Code Online (Sandbox Code Playgroud)

Kév*_*let 10

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

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";
});
Run Code Online (Sandbox Code Playgroud)

或者,您也可以从全局设置它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";
    });
}
Run Code Online (Sandbox Code Playgroud)