
[英]How can I add AspNetIdentity to my API with IdentityServer4
[英]How to add more than one IdentityServer4 Authentication in my project
我添加到我的项目 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 然后令牌将仅在一项服务中验证。
在这种情况下, 微软文档非常有用。 我只是在我的 Startup 中使用另一个方案名称添加新的 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"
),即使默认方案的响应是有效的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.