'SignInScheme' 必须提供选项
'SignInScheme' option must be provided
我正在创建一个 ASP.NET 5 MVC 6 应用程序,它将仅使用 Facebook/Google 身份验证。我还尝试在没有整个 ASP.NET Identity 的情况下使用 cookie 中间件——在这篇文章之后:
https://docs.asp.net/en/latest/security/authentication/cookie.html
所以我从一个没有身份验证的空白应用程序开始,然后添加了 Microsoft.AspNet.Authentication.Cookies 和 Microsoft.AspNet.Authentication.Facebook NuGet 包,以便采用非常简约的方法,我不包含任何我不包含的内容不需要。
我在 Startup.cs 中将以下代码添加到配置中,但出现 "SignInScheme option must be provided" 错误。知道我错过了什么吗?
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";
});
}
我正在创建一个 ASP.NET 5 MVC 6 应用程序,它将仅使用 Facebook/Google 身份验证。我还尝试在没有整个 ASP.NET Identity 的情况下使用 cookie 中间件——在这篇文章之后: https://docs.asp.net/en/latest/security/authentication/cookie.html
所以我从一个没有身份验证的空白应用程序开始,然后添加了 Microsoft.AspNet.Authentication.Cookies 和 Microsoft.AspNet.Authentication.Facebook NuGet 包,以便采用非常简约的方法,我不包含任何我不包含的内容不需要。
我在 Startup.cs 中将以下代码添加到配置中,但出现 "SignInScheme option must be provided" 错误。知道我错过了什么吗?
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";
});
}