如何在我的项目中添加多个IdentityServer4身份验证



我将其添加到我的项目IdentityServer4中,并创建IExtensionGrantValidator的实现。此外,我们还有另一个项目,可以发布对我们的服务有效的代币。有一个计划。如何验证本地Identity starage和External中的令牌?这两本书都是我们团队写的。如果我添加

.AddIdentityServerAuthentication(options =>
{
options.SupportedTokens = SupportedTokens.Reference;
options.Authority = "http://localhost:5000";
options.RequireHttpsMetadata = false;
options.ApiName = "myApi";
options.ApiSecret = "userSecret";
})

进入我的Startup.cs,则令牌将仅在一个服务中进行验证。

在这种情况下,microsoft文档非常有用。我只是用另一个方案名称在我的启动中添加了新的IdentityServerAuthentication。示例:

services.AddAuthentication("Bearer")
.AddIdentityServerAuthentication("Bearer", options =>
{
options.SupportedTokens = SupportedTokens.Reference;
options.Authority = "http://localhost:5000";
options.RequireHttpsMetadata = false;
options.ApiName = "myApi";
options.ApiSecret = "mySecret";
})
.AddIdentityServerAuthentication("ExternalAuth",
options =>
{
options.SupportedTokens = SupportedTokens.Reference;
options.Authority = appSettings.IdentityServiceExternal;
options.RequireHttpsMetadata = false;
options.ApiName = "myApi";
options.ApiSecret = "mySecret";
}
)

但它发送了两个请求:第一个请求默认方案(在我的情况下是localhost:5000上的"Bearer"(,第二个请求附加方案("ExteralAuth"(,即使默认方案的响应有效。

最新更新