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);

相关内容

热门资讯

2026版技巧!wepoker... 2026版技巧!wepoker软件辅助程序,德普之星透视辅助插件,都是是有挂(有挂解惑)1、德普之星...
有了最新消息!hhpoker德... 有了最新消息!hhpoker德州真的假的,德扑之星透视免费,原来存在有挂(有挂神器)1、进入到德扑之...
黑科技教程!德州透视是真的假的... 您好,德扑之星辅助器app这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很...
据公告内容!we poker辅... 据公告内容!we poker辅助器v3.3,德普辅助软件,真是是真的有挂(有挂方式)1、下载好德普辅...
攻略辅助挂!哈糖大菠萝怎么开挂... 攻略辅助挂!哈糖大菠萝怎么开挂,德扑软件,确实确实有挂(有挂规律)1、进入游戏-大厅左侧-新手福利-...
随着!hhpoker辅助挂是真... 随着!hhpoker辅助挂是真的吗,智星菠萝有挂吗,果然真的是有挂(有挂方略)亲,关键说明,智星菠萝...
近期!wepoker私人局有透... 近期!wepoker私人局有透视吗,德普之星透视辅助软件下载,其实真的有挂(有挂规律)一、德普之星透...
近期!hhpoker是真的假的... 近期!hhpoker是真的假的,德扑之心免费透视,好像是有挂(确实有挂)1)德扑之心免费透视有没有挂...
方法辅助挂!hhpoker的辅... 方法辅助挂!hhpoker的辅助是真的吗,德普之星辅助工具如何设置,好像存在有挂(证实有挂)暗藏猫腻...
2026版软件!约局吧能不能开... 2026版软件!约局吧能不能开挂,德普之星辅助工具如何打开,竟然存在有挂(有挂技巧)1、玩家可以在德...