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

相关内容

热门资讯

透视系统"aa po... 透视系统"aa poker透视软件"详细辅助解密教程(好像是真的有挂)是一款可以让一直输的玩家,快速...
透视计算"poker... 您好,pokernow辅助工具这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很...
透视ai"we po... 1、透视ai"we poker辅助器v3.3"详细辅助可靠技巧(固有是有挂)。2、we poker辅...
透视挂透视"有没有人... 透视挂透视"有没有人wepoker"详细辅助必胜教程(切实是真的有挂)关于有没有人wepoker机制...
透视有挂"哈糖大菠萝... 透视有挂"哈糖大菠萝有挂吗"详细辅助wepoke教程(固有真的有挂);支持2-10人实时对战,虚拟庄...
透视好友房"wepo... 透视好友房"wepoker钻石怎么看底牌"详细辅助安装教程(原来存在有挂);致您一封信;亲爱wepo...
透视ai"poker... 您好,pokerrrr2辅助这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多...
透视神器"德州真人透... 透视神器"德州真人透视脚本"详细辅助透视教程(竟然真的是有挂);致您一封信;亲爱德州真人透视脚本玩家...
透视透视"xpoke... 透视透视"xpoker怎么作弊"详细辅助黑科技教程(先前存在有挂)关于xpoker怎么作弊机制的,其...
透视代打"hhpok... 透视代打"hhpoker德州透视"详细辅助必备教程(确实是有挂);1分钟了解详细教程(微信 1367...