Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'SignInScheme' option must be provided

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";
            });
like image 860
Sam Avatar asked Jan 07 '16 08:01

Sam


People also ask

What is authentication scheme .NET core?

Authentication is the process of determining a user's identity. Authorization is the process of determining whether a user has access to a resource. In ASP.NET Core, authentication is handled by the authentication service, IAuthenticationService, which is used by authentication middleware.

What is default Challenge scheme?

DefaultChallengeScheme : Sets the default scheme to use when challenging. DefaultForbidScheme : Sets the default scheme to use when access is forbidden. DefaultSignInScheme : Sets the default scheme to sign in.

What is the default type of authentication for ASP NET core MVC?

The windows Authentication provider lets you authenticates users based on their windows accounts. This provider uses IIS to perform the authentication and then passes the authenticated identity to your code. This is the default provided for ASP.net.


1 Answers

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";
    });
}
like image 186
Kévin Chalet Avatar answered Sep 30 '22 18:09

Kévin Chalet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!