在Net Core 2.2中进行积极验证后,如何更新自己的令牌到期时间?

时间:2019-03-14 14:15:12

标签: c# validation .net-core jwt

我具有此配置来生成令牌:

var tokenHandler = new JwtSecurityTokenHandler();
        var key = Encoding.ASCII.GetBytes(_tokenSetting.Secret);
        var tokenDescriptor = new SecurityTokenDescriptor
        {
            Subject = new ClaimsIdentity(new Claim[] 
            {
                new Claim("User", JObject.FromObject(user).ToString())
            }),
            Issuer = "MyIssuer",

            /* Property to be renewed */
            Expires = DateTime.UtcNow.AddMinutes(5),  
            SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
        };
        var token = tokenHandler.CreateToken(tokenDescriptor);
        string realToken  = tokenHandler.WriteToken(token);

        return realToken;

这是为了验证ConfigureServices方法:

services.AddAuthentication(auth =>
            {
                auth.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                auth.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(bearer =>
            {
                bearer.RequireHttpsMetadata = false;
                bearer.SaveToken = true;
                bearer.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateLifetime = true,
                    ClockSkew = TimeSpan.Zero,
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey = new SymmetricSecurityKey(key),
                    ValidateIssuer = true,
                    ValidIssuer = "MyIssuer",
                    ValidateAudience = false
                };
            });

在积极验证之后,如何更新每个令牌上的“过期”属性?

0 个答案:

没有答案