必须提供"SignInScheme"选项 [英] 'SignInScheme' option must be provided
问题描述
我正在创建一个仅使用Facebook/Google身份验证的ASP.NET 5 MVC 6应用程序.我还试图在不使用整个ASP.NET身份的情况下使用Cookie中间件-在本文之后: https://docs.asp.net/en/latest/security/authentication/cookie.html
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
因此,我从一个没有身份验证的空白应用程序开始,然后添加了Microsoft.AspNet.Authentication.Cookies和Microsoft.AspNet.Authentication.Facebook NuGet程序包,以便采用一种非常简约的方法,其中我不包含任何我要包含的内容不需要.
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.
我在Startup.cs的Configure中添加了以下代码,但出现"SignInScheme必须提供选项"错误.知道我想念什么吗?
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";
});
推荐答案
如您所看到的错误消息所示,您需要在Facebook中间件选项中设置options.SignInScheme
:
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";
});
或者,您也可以从ConfigureServices
全局设置它(它将配置每个身份验证中间件,因此您不必设置options.SignInScheme
):
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";
});
}
这篇关于必须提供"SignInScheme"选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!