我在.net核心中使用谷歌身份验证但是当从谷歌重定向时它显示异常 - InvalidOperationException:没有配置身份验证处理程序来处理该方案:Cookies
这是我的startup.cs设置
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
LoginPath = new PathString("/account/login"),
AuthenticationScheme = "MyCookieMiddlewareInstance",
AutomaticAuthenticate = true,
AutomaticChallenge = true,
AccessDeniedPath = new PathString("/Home/AccessDenied"),
});
app.UseGoogleAuthentication(new GoogleOptions
{
AuthenticationScheme = "Google",
DisplayName = "Google",
SignInScheme = "Cookies",
ClientId = "ClientId ",
ClientSecret = "ClientSecret ",
Scope = { "email", "openid" },
CallbackPath = "/home",
});
请建议我错在哪里
答案 0 :(得分:0)
您可以使用CookieAuthenticationHandler
扩展方法注册ASP.NET Core提供的默认AddCookieAuthentication
处理程序:
using Microsoft.AspNetCore.Authentication.Cookies;
public void ConfigureServices(IServiceCollection services) { services.AddCookieAuthentication(); ... }
更新:
身份验证中间件中有breaking change。现在ASP.NET Core只有一个AddAuthentication()
扩展方法,所有配置都抛出相应的UseXXXAuthentication
扩展方法。有关简单示例,请查看Security repo samples:
using Microsoft.AspNetCore.Authentication.Cookies;
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication();
}
public void Configure(IApplicationBuilder app)
{
...
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AutomaticAuthenticate = true
});
}
查看文档中authentication-cookie部分的可用选项