Asp.net core Microsoft.AspNetCore.Authentication.OpenIdConnect抛出;无法将令牌响应正文解析为JSON;错误

Asp.net core Microsoft.AspNetCore.Authentication.OpenIdConnect抛出;无法将令牌响应正文解析为JSON;错误,asp.net-core,openid-connect,Asp.net Core,Openid Connect,我正在尝试实现对OpenIdConnect服务的登录。为此,我在Startup.cs中添加了以下代码: services.AddAuthentication(options => { options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; options.DefaultChallengeScheme = OpenIdConnectDe

我正在尝试实现对OpenIdConnect服务的登录。为此,我在Startup.cs中添加了以下代码:

services.AddAuthentication(options => {
                options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
            })
            .AddCookie()
            .AddOpenIdConnect(options => {
                options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                options.Authority = identityUrl.ToString();
                options.SignedOutRedirectUri = callBackUrl.ToString();
                options.ClientId = "xxx";
                options.ClientSecret = "yyy";
                options.AuthenticationMethod = OpenIdConnectRedirectBehavior.RedirectGet;
                options.ResponseType = OpenIdConnectResponseType.Code;
                options.ResponseMode = OpenIdConnectResponseMode.Query;
                options.SaveTokens = true;
                options.GetClaimsFromUserInfoEndpoint = true;
                options.CorrelationCookie = new Microsoft.AspNetCore.Http.CookieBuilder();

                options.Events = new OpenIdConnectEvents {
                    OnAuthenticationFailed = context => {
                        context.HandleResponse();
                        context.Response.Redirect("/");
                        return Task.CompletedTask;
                    }
                };
                options.Scope.Add("openid");
            });
我被重定向到外部登录页面,可以输入我的凭据。然后,触发事件“OnAuthenticationFailed”,并显示以下错误:

“无法将令牌响应正文解析为JSON。状态代码:400。内容类型:text/html”


经过一些“谷歌研究”,我仍然不知道如何解决这个问题。。。这就是我在这里寻求帮助的原因。提前感谢您的任何提示或提示。

我想明白了。如果有人面临同样的问题,以下是我的解决方案:

问题是,在服务提供商上,令牌端点身份验证模式设置为“client\u secret\u basic”,而不是“client\u secret\u post”。因此,令牌没有保存在主体中,因此解析失败。更改为“client\u secret\u post”后,错误消失,一切正常。

使用类似于捕获原始HTTP流量的工具,并在问题中发布失败请求的副本。