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、免费脚本咨询教...
分享一款!拱趴大菠萝开挂方法(... 分享一款!拱趴大菠萝开挂方法(辅助挂)都是真的有挂(存在有挂辅助攻略)1、实时透视辅助更新:用户可以...
科技介绍!黑侠破解wepoke... 科技介绍!黑侠破解wepoker(辅助挂)确实是真的有挂(有挂详细辅助方法)1、模拟器是什么优化,俱...
最新技巧!德普之星app安卓版... 最新技巧!德普之星app安卓版破解版(辅助挂)竟然存在有挂(真的有挂辅助教程)1、每一步都需要思考,...
玩家交流!wepoker有没有... 您好,这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩家在这款游戏中打...
解密关于!wepoker插件功... 解密关于!wepoker插件功能辅助器(辅助挂)本来有挂(详细教程辅助器)1、任何透视是真的假的的玩...
科技揭秘!wpk俱乐部辅助器(... 科技揭秘!wpk俱乐部辅助器(辅助挂)好像真的是有挂(发现有挂辅助工具)1、全新机制【ai辅助工具激...
热点推荐!fishpoker透... 热点推荐!fishpoker透视(辅助挂)一直是真的有挂(有人有挂辅助app)1、不需要AI权限,帮...
让我来分享经验!xpoker辅... 让我来分享经验!xpoker辅助器(辅助挂)原来是真的有挂(的确有挂辅助攻略)1、每一步都需要思考,...
一分钟揭秘!xpoker辅助神... 一分钟揭秘!xpoker辅助神器(辅助挂)好像真的有挂(有挂辅助辅助器)1、脚本辅助下载、免费透视脚...