ASP.NETMVC中的指标值类型显示为http://www.w3.org/2001/XMLSchema#string,而非JsonArray。
创始人
2024-09-19 09:01:04
0

可以通过自定义 ClaimSerializer 来解决。在 Startup.cs 中添加下面的代码:

services
    .AddAuthentication(options =>
    {
        options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
        options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
    })
    .AddJwtBearer(options =>
    {
        options.TokenValidationParameters = new TokenValidationParameters
        {
            ValidateIssuerSigningKey = true,
            IssuerSigningKey = YourSecurityKey,

            ValidateIssuer = true,
            ValidIssuer = "your-issuer",

            ValidateAudience = true,
            ValidAudience = "your-audience",

            ValidateLifetime = true,

            ClockSkew = TimeSpan.Zero
        };

        options.ClaimActions.MapJsonKey(ClaimTypes.Role, ClaimTypes.Role, "string");
        options.ClaimActions.MapJsonKey(ClaimTypes.Name, ClaimTypes.Name, "string");

        // Add this line to change the claim value type to JsonArray
        options.ClaimActions.Add(new JsonArrayClaimAction("your-claim", "value"));
    });

需要注意的是,在上面的代码中,我们通过添加 JsonArrayClaimAction 将指定的 Claim 的值类型更改为 JsonArray。您需要将 your-claimvalue 替换为您自己的 Claim 和值。

假设您的 JWT Token 包含 your-claim:["value1","value2"],那么现在您可以通过以下代码来获取该 Claim:

var claim = User.FindFirst("your-claim");
var values = JsonConvert.DeserializeObject(claim.Value);

相关内容

热门资讯

透视肯定!aapoker如何设... 透视肯定!aapoker如何设置胜率(透视)免费透视脚本(总是真的是有挂)1、玩家可以在aapoke...
透视好友!德州局透视,拱趴大菠... 透视好友!德州局透视,拱趴大菠萝挂(竟然有挂)1)拱趴大菠萝挂辅助挂:进一步探索拱趴大菠萝挂辅助透视...
透视科技!aapoker辅助怎... 透视科技!aapoker辅助怎么用(透视)透视脚本(竟然存在有挂)1、该软件可以轻松地帮助玩家将aa...
透视科技!pokemmo脚本辅... 透视科技!pokemmo脚本辅助器下载,德州私人局脚本(本来是真的有挂)1、全新机制【pokemmo...
透视规律!aapoker辅助软... 透视规律!aapoker辅助软件合法吗(透视)免费透视脚本(确实存在有挂)1、aapoker辅助软件...
透视系统!pokeplus脚本... 透视系统!pokeplus脚本,约局吧德州真的有透视挂吗(确实真的是有挂)1、约局吧德州真的有透视挂...
透视脚本!aapoker脚本(... 透视脚本!aapoker脚本(透视)脚本(果然真的是有挂);1、进入游戏-大厅左侧-新手福利-激活码...
透视安装!werplan辅助软... 透视安装!werplan辅助软件,智星德州可以透视吗(总是有挂)1、不需要AI权限,帮助你快速的进行...
透视真的!aapoker透视插... 透视真的!aapoker透视插件(透视)插件下载(都是是真的有挂)1、进入游戏-大厅左侧-新手福利-...
透视脚本!poker红龙辅助,... 透视脚本!poker红龙辅助,wepoker安装教程(总是真的有挂)1、下载好wepoker安装教程...