Google身份验证例外-未配置身份验证处理程序来处理该方案:Cookies [英] Google Authentication Exception- No authentication handler is configured to handle the scheme: Cookies

查看:352
本文介绍了Google身份验证例外-未配置身份验证处理程序来处理该方案:Cookies的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在.net核心中使用google身份验证,但是从google重定向时会显示异常-InvalidOperationException:未配置身份验证处理程序来处理方案:Cookies

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

这是我的startup.cs设置

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",
        });

请建议我哪里错了

推荐答案

您可以使用AddCookieAuthentication扩展方法注册由ASP.NET Core提供的默认CookieAuthenticationHandler处理程序:

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.AddCookieAuthentication(); ... }

public void ConfigureServices(IServiceCollection services) { services.AddCookieAuthentication(); ... }

更新:

身份验证中间件中有一个重大更改.现在,ASP.NET Core只有一种AddAuthentication()扩展方法,并且所有配置都抛出对应的UseXXXAuthentication扩展方法.对于简单示例,请查看安全回购示例:

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
     });
}

在访问"部分的 authentication-cookie 部分中可用选项的文档

Look into authentication-cookie section in documentation for available options

这篇关于Google身份验证例外-未配置身份验证处理程序来处理该方案:Cookies的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆