【问题标题】:Using Core MVC Client with IdentityServer v3 - The client application is not known or is not authorized将 Core MVC 客户端与 IdentityServer v3 一起使用 - 客户端应用程序未知或未经授权
【发布时间】:2016-10-08 19:18:14
【问题描述】:

我有一个非核心 webapi 和一个身份服务器 v3。现在我想实现一个asp核心网站。 asp核心测试网站运行在http://localhost:49946/ 是否可以将 asp 核心站点与 identityserver v3 sts 服务器一起使用?是否有任何已知问题?

我试过了,但我总是得到

客户端应用程序未知或未经授权。

我确保重定向 uri 和客户端 ID 匹配。

这是我在身份服务器中的客户端配置

  return new Client
            {
                Enabled = true,
                ClientId = "website",
                ClientName = "Site",
                Flow = Flows.Implicit,
                AllowedScopes = new List<string>
                {
                    Constants.StandardScopes.OpenId,
                    Constants.StandardScopes.Email,
                    Constants.StandardScopes.Profile,
                    Constants.StandardScopes.AllClaims,
                    Constants.StandardScopes.Roles,

                    "read","warehouseapi"

                },
                RedirectUris = new List<string>
                {"http://localhost:49946/"
                },
                PostLogoutRedirectUris = new List<string>
                {
                    "http://localhost:49946/"
                }
            };

这里是 asp core mvc 客户端的配置

 app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
            {
                AuthenticationScheme = "oidc",
                SignInScheme = "Cookies",

                Authority = "http://localhost:7890",
                RequireHttpsMetadata = false,

                ClientId = "website",

                ResponseType = "id_token token",
                Scope = { "openid profile email warehouseapi" },

                GetClaimsFromUserInfoEndpoint = true,
                SaveTokens = true,
                AutomaticAuthenticate = true,
                AutomaticChallenge = true,
            });

这里是客户端在进行身份验证时重定向到的 url。在那里你可以看到重定向uri设置为http://localhost:49946/

http://localhost:7890/connect/authorize?client_id=website&redirect_uri=http%3A%2F%2Flocalhost%3A49946%2Fsignin-oidc&response_type=id_token%20token&scope=openid%20profile%20openid%20profile%20email%20warehouseapi&response_mode=form_post&nonce=636115164423104247.ZjY0MjY4OTctZWY3Ny00MGE2LTg4NDAtOWEzZWQyMmQ0NDY5YzJiOWRiNDQtYWY4Yy00MjE2LWE5ZWEtNTA3ZmU3MThkNzBi&state=CfDJ8Faq7VwoA29ApMd_ECq59Rnz2OH_juBD61Mbr40-8VxMsE4i5s5i-jNyb4LdOBYcCAvojnXLPzGy5fvm3c0eNcCnALfy2M2Pl_k0eXcxwXIlF9D_GBmPH5EwsQTXXP5jNBaPuFuxpFM-5tbdSkiqQbdpeddgO7LBPqqxlHcu3MB7e0MOBcPsVOKcTfXwUMG_cWDCoUldgu4k-CjunCTsXOnS7VWpg8ICEP8fcMM8q5GY8KfZFHoOPzu5_24SOLhAeujPF2l_YkVQJRY-QMmv-IWThjk97ewZE8Pl8uIyof38B0lRtbYeE0ChBbM4Wx5O-3yFtTVaT46gtXxqdn4lny39Te1b0SFsG5-LqzZrtTw-RZ_EMZO9wbdd4uwXoifjXg

这只是一个兼容性问题吗?我在监督什么?

-- 更新

感谢最低权限的提示,我在日志中找到了解决方案。有一个意外的子路径/signin-oidc

在我看到的轨迹中

2016-10-08 13:07:41.450 +02:00 [Information] Start authorize request
2016-10-08 13:07:41.465 +02:00 [Information] Start authorize request protocol validation
2016-10-08 13:07:41.498 +02:00 [Error] "Invalid redirect_uri: http://localhost:49946/signin-oidc"
 "{
  \"ClientId\": \"website\",
  \"ClientName\": \"Pluto Site\",
  \"RedirectUri\": \"http://localhost:49946/signin-oidc\",
  \"AllowedRedirectUris\": [
    \"http://localhost:49946/\"
  ],
  \"SubjectId\": \"unknown\",
  \"Flow\": \"AuthorizationCode\",
  \"RequestedScopes\": \"\",
  \"Raw\": {
    \"client_id\": \"website\",
    \"redirect_uri\": \"http://localhost:49946/signin-oidc\",
    \"response_type\": \"id_token token\",
    \"scope\": \"openid profile openid profile email warehouseapi\",
    \"response_mode\": \"form_post\",
    \"nonce\": \"636115215901620557.ZTNkNmFmYjMtOTY4MC00ODE3LWExMmEtYTc0OWYzYzRkZmY4MDRlM2JjZjUtZGViNC00MjIyLWI1MTktOTM4Y2U2MWFkYzkw\",
    \"state\": \"CfDJ8Faq7VwoA29ApMd_ECq59RmXQrEZdMEoqQ9onYQLXRTRz-ge13paqnwmi_xjJMoVpaItur0ETX08PxoOzQ-YUn--7DR1pvaxqUngPYOiS44j4t9bS4_yiu7Gb1fjU_R5OiZU2cc-0T6PzT_WgUZ48rqC-unHdJqd_NgE7D_9H9ZT1a-2J3GBZEkfh4LOCHHtfcuG06lgXTPn85fkVKcWxbqn6pTrCLRhiRfH9h41e6bvKsGTOmzJ45G9HRpEAlyo7GkgtFgrrshKNo0xDsIxXjAhxp_me_tipBEpyHT8Mo7T9G4-HTtP8FSnb7YurSWjfywOpEG136-T7wvksCEwlMGrL8k90v6prM-bwefOhCFA-8vJO1hvtKkF3wPSgeMiYg\"
  }
}"

【问题讨论】:

  • 日志文件或从未发生过
  • 来自身份服务器或客户端?
  • @leastprivilege 感谢这个提示。我自己在日志中找到了它,请参阅帖子更新

标签: asp.net openid identityserver3 identityserver4


【解决方案1】:

在 asp 内核中,有一个静默附加的子路径

soo http://localhost:49946/signin-oidc 必须添加到重定向 uris

【讨论】:

  • 您应该接受自己的答案,因为它是有效的。
猜你喜欢
  • 2016-10-06
  • 2015-07-06
  • 1970-01-01
  • 2015-02-01
  • 2016-07-20
  • 1970-01-01
  • 2019-07-25
  • 1970-01-01
  • 2018-12-01
相关资源
最近更新 更多