【问题标题】:Unknown client or client not enabled Identity Server 4未知客户端或客户端未启用 Identity Server 4
【发布时间】:2019-07-25 15:34:19
【问题描述】:

我遇到了这个错误,我在网上搜索了答案,几乎所有人都在谈论 requesturis,我仔细检查了以确保我的 uris 配置正确。我没有找到任何线索。任何想法。

Identity Server 4 设置:-

  public static IEnumerable<Client> GetClients()
        {
            return new List<Client>()
            {
                new Client
                {
                    ClientName="KtsWeb App",
                    ClientId="ktswebclient",
                    AllowedGrantTypes= GrantTypes.Hybrid,
                    AccessTokenType = AccessTokenType.Reference,
                    RedirectUris = new List<string>()
                    {
                        "https://localhost:44355/signin-oidc" //Client URL Address

                    },
                    AllowedScopes =
                    {
                        IdentityServerConstants.StandardScopes.OpenId,
                        IdentityServerConstants.StandardScopes.Profile
                    }
                }
            };            
        }

客户端设置:-

services.AddAuthentication(options =>
            {
                options.DefaultScheme = "Cookies";
                options.DefaultChallengeScheme = "oidc";
            }).AddCookie("Cookies",
              (options) =>
              {
                  options.AccessDeniedPath = "/Authorization/AccessDenied";
              })
              .AddOpenIdConnect("oidc", options =>
              {
                  options.SignInScheme = "Cookies";
                  options.Authority = "https://localhost:44380"; //Identity Server URL Address
                  options.ClientId = "ktswebclient";
                  options.ResponseType = "code id_token";
                  options.Scope.Add("openid");
                  options.Scope.Add("profile");
                  options.SaveTokens = true;
              });

【问题讨论】:

  • 粘贴重定向发生的 url,我敢打赌你的重定向 uri 略有不同或不是 https 或类似的东西。
  • 我没有明白你在说什么,但是定向 uri 是身份服务器主页/错误页面,它显示了错误消息。身份服务器可以使用自己的 uri 正常打开,但客户端会收到此错误。错误 uri:localhost:44380/home/error?errorId=
  • 在 chrome 或类似的工具中打开开发者工具并检查用于连接/授权的网络请求
  • 1.您创建了一个没有客户端密码的混合客户端。 2.您正在使用隐式客户端代码。选择一个。

标签: c# asp.net-mvc asp.net-core identityserver4


【解决方案1】:

您应该始终检查身份服务器日志,它会给您一个明确的错误消息,可能是不支持的授权类型。

您已创建混合客户端,但忘记添加密钥。

new Client
            {
                ClientId = "mvc",
                ClientName = "MVC Client",
                AllowedGrantTypes = GrantTypes.Hybrid,

                ClientSecrets =
                {
                    new Secret("secret".Sha256())
                },

                RedirectUris           = { "http://localhost:5002/signin-oidc" },
                PostLogoutRedirectUris = { "http://localhost:5002/signout-callback-oidc" },

                AllowedScopes =
                {
                    IdentityServerConstants.StandardScopes.OpenId,
                    IdentityServerConstants.StandardScopes.Profile,
                    "api1"
                },

                AllowOfflineAccess = true
            }
        };

你的代码没有提供秘密

        JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();

        services.AddAuthentication(options =>
            {
                options.DefaultScheme = "Cookies";
                options.DefaultChallengeScheme = "oidc";
            })
            .AddCookie("Cookies")
            .AddOpenIdConnect("oidc", options =>
            {
                options.SignInScheme = "Cookies";

                options.Authority = "http://localhost:5000";
                options.RequireHttpsMetadata = false;

                options.ClientId = "mvc";
                options.ClientSecret = "secret";
                options.ResponseType = "code id_token";

                options.SaveTokens = true;
                options.GetClaimsFromUserInfoEndpoint = true;

                options.Scope.Add("api1");
                options.Scope.Add("offline_access");

                options.ClaimActions.MapJsonKey("website", "website");
            });

【讨论】:

  • 似乎我错过了客户端密码,但我也设置了一些额外的设置。谢谢
猜你喜欢
  • 1970-01-01
  • 2020-01-11
  • 2016-10-06
  • 2020-05-01
  • 2016-07-20
  • 2021-12-22
  • 2021-08-07
  • 2020-03-22
  • 2018-12-04
相关资源
最近更新 更多