'SignInScheme' option must be provided

≯℡__Kan透↙ 提交于 2019-12-23 07:56:14

问题


I'm creating an ASP.NET 5 MVC 6 app that will use Facebook/Google authentication only. I'm also trying to use the cookie middleware without the whole ASP.NET Identity -- following this article: https://docs.asp.net/en/latest/security/authentication/cookie.html

So I started with an blank app with no authentication then added the Microsoft.AspNet.Authentication.Cookies and Microsoft.AspNet.Authentication.Facebook NuGet packages in order to have a very minimalistic approach where I don't include anything that I don't need.

I added the following code into Configure in Startup.cs but I'm getting "SignInScheme option must be provided" error. Any idea what I'm missing?

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";
            });

回答1:


As indicated by the error message you're seeing, you need to set options.SignInScheme in your Facebook middleware options:

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";
});

Alternatively, you can also set it globally from ConfigureServices (it will configure every authentication middleware so you don't have to set 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";
    });
}


来源:https://stackoverflow.com/questions/34650645/signinscheme-option-must-be-provided

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!