问题
I am working with google authentication in .net core but when redirecting from google it showing me exception- InvalidOperationException: No authentication handler is configured to handle the scheme: Cookies
Here is my Setting for 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",
});
Please suggest me where I am wrong
回答1:
You may register the default CookieAuthenticationHandler
handler provided by ASP.NET Core by using AddCookieAuthentication
extension method:
using Microsoft.AspNetCore.Authentication.Cookies;
public void ConfigureServices(IServiceCollection services) { services.AddCookieAuthentication(); ... }
Update:
There was a breaking change in Authentication Middleware. Now ASP.NET Core has only one AddAuthentication()
extension method and all configuration goes throw corresponding UseXXXAuthentication
extension method. For simple example look into 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
});
}
Look into authentication-cookie section in documentation for available options
来源:https://stackoverflow.com/questions/43607514/google-authentication-exception-no-authentication-handler-is-configured-to-hand