Пример #1
0
        public void ValidateTokenThrowsOnExpiredTokenInUTCTime()
        {
            var oldToken = new ValidatedJWTokenTestForgery(
                _sm,
                SecurityActionFactory.GetAll(),
                _ti,
                _cii,
                DateTime.UtcNow.AddMinutes((JWToken.AccessTokenExpirationMinutes + 1) * -1),
                true);
            var rawData = oldToken.RawTokenData;

            Assert.Throws <SecurityTokenExpiredException>(() => ValidatedJWToken.CreateWithValidation(rawData, _secKey));
        }
Пример #2
0
        public void CreateTokenSetsExpirationInUTCTime()
        {
            var timezones = TimeZoneInfo.GetSystemTimeZones();
            var utcNow    = DateTime.UtcNow;

            // Strip fractional seconds off utcNow
            utcNow = utcNow.AddTicks(-(utcNow.Ticks % TimeSpan.TicksPerSecond));
            var tokenHandler = new JwtSecurityTokenHandler();
            var localTZ      = TimeZoneInfo.Local;
            var localtimeNow = TimeZoneInfo.ConvertTimeFromUtc(utcNow, localTZ);
            var token        = new ValidatedJWTokenTestForgery(_sm,
                                                               SecurityActionFactory.GetAll(),
                                                               _ti,
                                                               _cii,
                                                               localtimeNow,
                                                               true);
            var expClaim = (tokenHandler.ReadToken(token.RawTokenData) as JwtSecurityToken);

            Assert.AreEqual(utcNow.AddMinutes(JWToken.AccessTokenExpirationMinutes),
                            expClaim.ValidTo, $"Create JWToken failed to render timezone into UTC time");
            Assert.AreEqual(DateTimeKind.Utc, expClaim.ValidTo.Kind);
        }