public static bool IsValidToken(this TokenDetails token, DateTimeOffset now) { if (token == null) { return(false); } if (token.Expires == DateTimeOffset.MinValue) { return(true); } return(!token.IsExpired(now)); }
/// <summary> /// Checks whether the token is valid. /// </summary> /// <param name="token"><see cref="TokenDetails"/>.</param> /// <param name="serverTime">the server time instance of now to compare with the token.</param> /// <returns>true / false.</returns> public static bool IsValidToken(this TokenDetails token, DateTimeOffset?serverTime) { if (token == null) { return(false); } // (RSA4b1) We can only check validity of the token if it is a full TokenDetails object // and we already have the server time if (serverTime is null || token.CanBeUsedToCheckExpiry == false) { return(true); } return(token.IsExpired(serverTime.Value) == false); }