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

相关内容

热门资讯

第五分钟辅助!德州透视插件,w... 第五分钟辅助!德州透视插件,wepoker私人局外卦,经验教程(有挂方法)1、下载好wepoker私...
九分钟辅助!aapoker辅助... 九分钟辅助!aapoker辅助软件合法吗,拱趴大菠萝挂哪里,指引教程(有挂头条)1、全新机制【aap...
六分钟辅助!wepoker免费... 六分钟辅助!wepoker免费透视脚本,wepoker安装教程,指南书教程(有挂分析)1、wepok...
3分钟辅助!wepoker私局... 3分钟辅助!wepoker私局代打,xpoker透视辅助,指南教程(有挂透明挂)1、wepoker私...
第九分钟辅助!pokemmo脚... 第九分钟辅助!pokemmo脚本辅助下载,wepoker透视器免费,资料教程(有挂教程)进入游戏-大...
第1分钟辅助!wpk透视辅助靠... 您好,wpk透视辅助靠谱吗这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很...
4分钟辅助!werplan透视... 4分钟辅助!werplan透视挂,pokernow辅助工具,策略教程(有挂详细)1、pokernow...
6分钟辅助!aapoker真的... 6分钟辅助!aapoker真的假的,wepoker开脚本视频,技法教程(有挂解惑)1、下载好wepo...
第一分钟辅助!we poker... 第一分钟辅助!we poker免费辅助器,wpk插件,绝活儿教程(有挂分享)1、we poker免费...
第一分钟辅助!wepoker辅... 第一分钟辅助!wepoker辅助器官方,wepoker游戏的安装教程,指南教程(新版有挂)wepok...