locked
Setting Token Expiration In Seconds or Minutes RRS feed

  • Question

  • User651658926 posted

    Hello:

    So this fails: 
    Expires = DateTime.Now.AddMinutes(30),

    This passes:
    Expires = DateTime.Now.AddHours(7),

    If I go below 7 hours or attempt to use seconds I get the following erros:

    IDX12401: Expires: 'System.DateTime' must be after NotBefore: 'System.DateTime'.

    I think I understand the error but I am not certain how to resolve it.

    Code:

    SigningCredentials signingCredentials = new SigningCredentials(key, SecurityAlgorithms.HmacSha512Signature);
    SecurityTokenDescriptor securityTokenDescriptor = new SecurityTokenDescriptor
    {
       Subject = new ClaimsIdentity(claims),
       Expires = DateTime.Now.AddHours(6),
       SigningCredentials = signingCredentials
    };


    Thanks!


    Saturday, November 21, 2020 5:24 AM

All replies

  • User1168500272 posted

    Amplitude

    If I go below 7 hours

    That would be because you're in UTC-7, ie somewhere in western/midwestern North America :D

    You need to use System.DateTime.UtcNow as opposed to System.DateTime.Now.

    Sunday, November 22, 2020 4:22 PM