简体   繁体   English

使用身份服务器 3 和身份服务器 4 创建的令牌保护 API

[英]Securing API using Identity Server 3 with token created by identity server 4

I am using Identity Server 4 for validating the clients and generating the token.我正在使用 Identity Server 4 来验证客户端并生成令牌。 The website is created in Angular with.Net core but the API which was already developed is still in .NET framework 4.7.1 which is not supporting Identity Server 4.该网站是在 Angular 中创建的,带有 .Net 内核,但已经开发的 API 仍在 .NET 框架 4.7.1 中,不支持 Identity Server 4。

So to protect the API i have configured the API with Identity Server 3 which supports .NET framework 4.7.1 but the issue is it is not validating the token generated by Identity Server 4.因此,为了保护 API,我为 API 配置了支持 .NET 框架 4.7.1 的 Identity Server 3,但问题是它没有验证 Identity Server 4 生成的令牌。

app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
            {
                Authority = "http://localhost:5000",
                AuthenticationType = "Bearer",
                RequiredScopes = new[] { "api_to_be_protected" }
            });

is there any way we can validate the token and protect the API from unknown clients which is not authorized and also validates the token created by Identity Server 4有什么方法可以验证令牌并保护 API 免受未经授权的未知客户端的影响,还可以验证 Identity Server 4 创建的令牌

On your identity server, you should set the EmitLegacyResourceAudienceClaim option to true在您的身份服务器上,您应该将 EmitLegacyResourceAudienceClaim 选项设置为 true

var identityServerBuilder = services.AddIdentityServer(opt =>
            {
                opt.EmitLegacyResourceAudienceClaim = true;
            });

More information about this property can be found over here: https://identityserver4.readthedocs.io/en/latest/reference/options.html可以在此处找到有关此属性的更多信息: https://identityserver4.readthedocs.io/en/latest/reference/options.html

I also found the nuget package IdentityServer3.Contrib.AccessTokenValidation has a recent update to support IDSrv 4, i would recommend that you use that instead of IdentityServer3.AccessTokenValidation我还发现 nuget package IdentityServer3.Contrib.AccessTokenValidation最近更新以支持 IDSrv 4,我建议您使用它而不是IdentityServer3.AccessTokenValidation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM