title: Need to check of jwt token is valid/expired in asp.net core
body: <p>In order to generate JWT token I am using the following code:</p>
  <pre><code>  var tokenHandler = new JwtSecurityTokenHandler();
  
              var key = Encoding.ASCII.GetBytes(_consumerConfiguration.SecretKey);
              var tokenDescriptor = new SecurityTokenDescriptor
              {
                  Subject = new ClaimsIdentity(new Claim[]
                  {
                      new Claim(ClaimTypes.Name, &quot;ConsumerId&quot;)
                  }),
                  Expires = DateTime.Now.AddMinutes(1),
                  SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
              };
              var token = tokenHandler.CreateToken(tokenDescriptor);
              return tokenHandler.WriteToken(token);
  </code></pre>
  <p>This is my code in RegisterServices</p>
  <pre><code>  var appSettingsSection = configuration.GetSection(&quot;ConsumerConfiguration&quot;);
              services.Configure&lt;ConsumerConfiguration&gt;(appSettingsSection);
  
              var appSettings = appSettingsSection.Get&lt;ConsumerConfiguration&gt;();
  
              var key = Encoding.ASCII.GetBytes(appSettings.SecretKey);
              services.AddAuthentication(x =&gt;
              {
                  x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                  x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
              })
              .AddJwtBearer(x =&gt;
              {
                  x.RequireHttpsMetadata = false;
                  x.SaveToken = true;
                  x.TokenValidationParameters = new TokenValidationParameters
                  {
                      ValidateIssuerSigningKey = true,
                      IssuerSigningKey = new SymmetricSecurityKey(key),
                      ValidateIssuer = false,
                      ValidateAudience = false
                  };
              });
              services.AddScoped&lt;Microsoft.AspNetCore.Authorization.IAuthorizationHandler, ConsumerAuthorizationHandler&gt;();
  </code></pre>
  <p>I using this as a filter to register the custom authorization handler globally in the application:</p>
  <pre><code> var policy = new AuthorizationPolicyBuilder().RequireCustomClaim(ClaimTypes.Name).
                  AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme).Build();
  
  options.Filters.Add(new AuthorizeFilter(policy));
              })
  </code></pre>
  <p>and this is my custom authorization handler</p>
  <pre><code>    #region constructor
      public ConsumerAuthorizationHandler(IOptions&lt;ConsumerConfiguration&gt; consumerConfiguration)
      {
          _consumerConfiguration = consumerConfiguration.Value;
      }
      #endregion
      protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, CustomRequireClaim requirement)
      {
          if (!_consumerConfiguration.EnableAuthorizationFilter)
              context.Succeed(requirement);
  
          var hasClaim = context.User.Claims.Any(x =&gt; x.Type == requirement.ClaimType);
  
          if (hasClaim)
          {
              context.Succeed(requirement);
          }
  
          return Task.CompletedTask;
      }
  }
  
  public static class AuthorizationPolicyBuilderExtensions
  {
      public static AuthorizationPolicyBuilder RequireCustomClaim(this AuthorizationPolicyBuilder builder, string claimType)
      {
         return builder.AddRequirements(new CustomRequireClaim(claimType));
      }
  }
  
  </code></pre>
  <p>The problem is: How can I check if the JWT is expired? The token seems not to expire. What code do I have to add that it will check if the token is expired?</p>