Correct use of JwtTokens in C#

后端 未结 2 860
予麋鹿
予麋鹿 2021-01-04 10:32

I\'m playing a with JwtTokens and can\'t make them work properly. I\'m using http://www.nuget.org/packages/System.IdentityModel.Tokens.Jwt/ for it. I know the code is a mess

相关标签:
2条回答
  • 2021-01-04 10:51

    Found the issue. The validation parameters have a default clock skew of 5 minutes

    /// <summary>
    /// Default for the clock skew.
    /// 
    /// </summary>
    /// 
    /// <remarks>
    /// 300 seconds (5 minutes).
    /// </remarks>
    public static readonly TimeSpan DefaultClockSkew;
    

    Setting that to 0 make this work. Still don't understand why the skew is 5 minutes, if I set the expiry at some point!!!

    0 讨论(0)
  • 2021-01-04 11:04

    This will definitely works

    TimeSpan.FromSeconds(0) Resets ClockSkew Time to zero

    TokenValidationParameters parameters = new TokenValidationParameters()
    {
      RequireExpirationTime = true,
      ValidateIssuer = false,
      ValidateAudience = false,
      ClockSkew= TimeSpan.FromSeconds(0)
    };
    
    0 讨论(0)
提交回复
热议问题