未知的客户端或客户端未启用 Identity Server 4。

5

我一直遇到这个错误,已经在网上搜索了答案,几乎所有答案都涉及请求URI,我已经仔细检查过确保我的URI配置正确,但是没有找到任何线索。有什么想法吗?

在此输入图片描述

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之类的。 - Vidmantas Blazevicius
我不明白你在说什么,但是指定的URI是身份验证服务器主页/错误页面,它显示了一个错误消息。身份验证服务器使用自己的URI可以正常打开,但客户端却出现了这个错误。错误的URI为:https://localhost:44380/home/error?errorId= - Urgen
在Chrome或类似的工具中打开开发者工具,检查用于连接/授权的网络请求。 - Vidmantas Blazevicius
  1. 您已创建了一个混合客户端,但没有客户机密。
  2. 您正在使用隐式客户端代码。请选择一个。
- Linda Lawton - DaImTo
1个回答

4

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

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

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

1
看起来我错过了客户端密钥,不过我也设置了一些额外的设置。谢谢。 - Urgen

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接