.net - 为什么我们有两个 JWT token 类 JwtSecurityTokenHandler 和 JsonWebTokenHandler?

标签 .net asp.net-core .net-core jwt

它总是令人困惑,并且没有提及使用哪个更好,我个人更喜欢 JsonWebTokenHandler 因为它是更合适的 ValidateToken 返回类型

命名空间的区别是Microsoft.IdentityModel.JsonWebTokens vs System.IdentityModel.Tokens.Jwt,这也很相似?

任何可用的指导方针?

最佳答案

JsonWebTokenHandler 是新的和改进的版本。

见:https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/issues/945

布伦特施马尔茨写道:

JwtSecurityTokenHandler was modeled after the existing System.IdentityModel.SecurityTokenHandler. There were some compromises that we had to make, such as using System.Security.ClaimsIdentity as the type to build the JWS or JWE when using SecurityTokenDescriptor. ValidateToken had an out parameter of type SecurityToken, which doesn't for async. A ClaimsPrincipal was returned, sometimes using claim type mapping to build the claims. This model new model, is much lighter weight and works with native Json.Net objects. We plan on layering on top, so that you can get back to the existing types, but we will allow users to control what is returned using injection and delegates.

We saw performance improvements of up to 100% in some scenarios.

关于.net - 为什么我们有两个 JWT token 类 JwtSecurityTokenHandler 和 JsonWebTokenHandler?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60455167/

相关文章:

c# - 从 ASP.NET CORE 2 获取当前用户

c# - Nuget 包 "Not available in this source"... 但 VS 仍然知道它?

c# - Swashbuckle 能否生成 OpenAPI 3.0?

c# - 如何使用多个 await 正确编写健壮的异步代码

c# - 两个相等性检查在一个 Where 中,反之亦然以提高效率

c# - ASP.NET Core Web API 自定义路由不起作用

c# - 如何使用 EF 为 ASP.NET Core 定义索引?

.net-core - 无法写入AOF

c# - 更改绑定(bind)到 DataGridView 的 DataTable 中的列顺序不会反射(reflect)在 View 中

c# - 平台特定代码中的 .NET MAUI 依赖注入(inject)