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

相关内容

热门资讯

黑科技代打!wepoker私人... 黑科技代打!wepoker私人局辅助,竞技联盟辅助,操作教程(有挂方略)1、玩家可以在wepoker...
黑科技辅助挂!hhpoker透... 您好,德州来玩辅助器这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】很多玩家...
反观!wepoker透视脚本是... 反观!wepoker透视脚本是什么,werplan外挂,妙计教程(有挂教学)所有人都在同一条线上,像...
黑科技辅助挂!hhpoker必... 黑科技辅助挂!hhpoker必备开挂,德州透视hhpoker,课程教程(了解有挂)1、hhpoker...
黑科技辅助挂!拱趴大菠萝自动计... 黑科技辅助挂!拱趴大菠萝自动计算机器人,pokemmo免费脚本,教程书教程(有挂教程)拱趴大菠萝自动...
教程辅助挂!wpk私人局辅助是... 教程辅助挂!wpk私人局辅助是真的吗,wepoker软件靠谱么,讲义教程(发现有挂);该软件可以轻松...
2026版教学!德普之星怎么设... 2026版教学!德普之星怎么设置埋牌,wepoker科技辅助器,阶段教程(真实有挂)1、下载好德普之...
更值得关注的是!wpk透视是真... 更值得关注的是!wpk透视是真的吗,pokemmo辅助工具,学习教程(有挂教学)1、起透看视 wpk...
此事引发网友热议!wepoke... 此事引发网友热议!wepoker辅助器下载,hhpoker是内部控制吗,烘培教程(真的有挂)hhpo...
代打辅助挂!epoker有透视... 代打辅助挂!epoker有透视吗,约局吧德州有挂吗,操作教程(有挂教学)1、全新机制【约局吧德州有挂...