gpt4 book ai didi

c# - 获取简短声明类型名称

转载 作者:行者123 更新时间:2023-12-04 17:08:14 25 4
gpt4 key购买 nike

我正在使用Asp.Net Core和ASP.NET Identity,当我获得Claim类型时,我得到类似

"type":"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier",
"value":"123"

如何仅获取简单类型名称,例如:
"type":"nameidentifier",
"value":"123"

我知道有可能我只是找不到解决方案。

最佳答案

当我遇到this documentation时,我一直在寻找这个答案:

When you inspect the claims on the about page, you will notice two things: some claims have odd long type names and there are more claims than you probably need in your application.

The long claim names come from Microsoft’s JWT handler trying to map some claim types to .NET’s ClaimTypes class types. You can turn off this behavior with the following line of code (in Startup).

This also means that you need to adjust the configuration for anti-CSRF protection to the new unique sub claim type:

AntiForgeryConfig.UniqueClaimTypeIdentifier = Constants.ClaimTypes.Subject;
JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>();
我将此代码添加到客户的 Startup.cs中,从而缩短了 claim 类型。
更新:
对于较新版本的 IdentityModel,该属性称为 DefaultInboundClaimTypeMap:
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
确保在设置identt配置之前先运行 这一行

关于c# - 获取简短声明类型名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36315559/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com