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游戏的安装教程,wpk免费辅助,其实是真的有挂(有挂教程)1、每一步都需要思...
每日必看推荐!拱趴大菠萝开挂方... 每日必看推荐!拱趴大菠萝开挂方法,hhpoker有作弊的吗,其实是有挂(有挂秘籍)1、实时透视辅助更...
交流学习经验!hhpoker软... 交流学习经验!hhpoker软件可以玩吗,aapoker透视脚本,真是是真的有挂(有挂实锤)1、玩家...
一分钟了解!wejoker辅助... 一分钟了解!wejoker辅助软件,wpk作弊,原来真的有挂(确实有挂)1、起透看视 辅助软件价格2...
重大来袭!fishpoker透... 重大来袭!fishpoker透视,htx矩阵wepoker辅助,竟然真的是有挂(详细教程)1、每一步...
终于知道!hh poker软件... 终于知道!hh poker软件,hhpoker透视工具,原来是真的有挂(有挂秘籍)1、公共底牌简单,...
必备教程!wepokerplu... 必备教程!wepokerplus外挂,wepoker透视脚本免费,好像有挂(有挂解惑)1、进入到是否...
一起来讨论!拱趴大菠萝怎么开挂... 一起来讨论!拱趴大菠萝怎么开挂,wepoker破解游戏盒子,都是是真的有挂(有挂方法)1、许多玩家不...
重大通报!wepoker安装教... 重大通报!wepoker安装教程,wejoker辅助软件,果然有挂(有挂技术)1、免费辅助多个强度级...
必备科技!德州局透视脚本下载安... 必备科技!德州局透视脚本下载安装最新版本,智星德州可以透视吗,竟然存在有挂(有挂透视)1、这是跨平台...