【发布时间】:2022-10-13 23:38:21
【问题描述】:
我有 IdentityServer 项目和 API。我从 IdentityServer 获取 JWT 令牌以向我的 API 发送请求。
在我的 API 中,我不在任何地方使用 clientId 和 clientSecret。我不明白为什么???
在我研究的时候,API的Program.cs被很多人这样使用;
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options =>
{
options.Authority = "[identity server url]";
options.Audience = "[api resourse name]";
options.RequireHttpsMetadata = false;
});
我不明白的是,这里没有clientId和clientSecret。
有些人使用 [IdentityServer4.AccessTokenValidation] 通过使用this 来做我想做的事;
services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
.AddIdentityServerAuthentication(options =>
{
options.Authority = "https://demo.identityserver.io";
options.ApiName = "api1";
options.ApiSecret = "secret";
});
但是当我尝试这个时,即使我的 clientSecret 不正确,我的 api 也不会返回 401 Unauthorized 并返回 200 OK。
我怎么解决这个问题 ?
【问题讨论】:
-
您的客户端密码是否设置在 IdentityServer 的 Config.cs 文件中?我使用 OIDC 作为中间件没有任何问题。
标签: c# asp.net-core oauth-2.0 identityserver4