Google Authentication Exception- No authentication handler is configured to handle the scheme: Cookies

牧云@^-^@ 提交于 2019-12-11 06:14:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!