IdentityServer4官方文档代码配置unauthorized_client Invalid grant type for client错误

牧云@^-^@ 提交于 2019-11-30 09:52:47

今天按照IdentityServer4官方文档写了一下代码测试下来报错,官方文档配置ConfigureService代码如下图

官方配置Configure代码如下图

运行报错效果如下图

完全按照官方文档跑的,然后找了一圈原来是没有加上响应类型,代码如下

public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
            services.AddAuthentication(option =>
            {
                option.DefaultScheme = "Cookies";
                option.DefaultChallengeScheme = "oidc";
            })
            .AddCookie("Cookies")
            .AddOpenIdConnect("oidc", options =>
            {
                options.Authority = "http://localhost:5000";
                options.RequireHttpsMetadata = false;
                options.ClientId = "mvc client";
                options.SaveTokens = true;
                options.ResponseType = "code";
            });
        }

加上ResponseType以后不报错了,登录确实可以了,但是登录以后点击授权按钮又报错,如下图

额,无语了,找了一圈发现是少了设置秘钥代码加上以后如下

public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
            services.AddAuthentication(option =>
            {
                option.DefaultScheme = "Cookies";
                option.DefaultChallengeScheme = "oidc";
            })
            .AddCookie("Cookies")
            .AddOpenIdConnect("oidc", options =>
            {
                options.Authority = "http://localhost:5000";
                options.RequireHttpsMetadata = false;
                options.ClientId = "mvc client";
                options.ClientSecret = "mvc secret";
                options.SaveTokens = true;
                options.ResponseType = "code";
            });
        }

然后不报错了,官方文档感觉很不严谨啊。。。

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