public void ValidateSessionKey_TimeoutTest()
        {
            var cfg  = GetConfig();
            var auth = new JwtAuthorizationService(cfg);

            var sessionKey = auth.GetSessionKey(testClaims, TimeSpan.FromMilliseconds(250));

            Thread.Sleep(15000);
            Assert.Throws <SecurityTokenExpiredException>(
                () => auth.ValidateSessionKey(sessionKey));
        }
        public void ValidateSessionKeyTest()
        {
            var cfg  = GetConfig();
            var auth = new JwtAuthorizationService(cfg);

            var sessionKey      = auth.GetSessionKey(testClaims, TimeSpan.FromMilliseconds(250));
            var recoveredClaims = auth.ValidateSessionKey(sessionKey);

            Assert.AreEqual(testClaims.Guid, recoveredClaims.Guid);

            sessionKey = new JwtAuthorizationService(cfg)
                         .GetSessionKey(testClaims, TimeSpan.FromMinutes(10));
            Assert.Throws <SecurityTokenInvalidSignatureException>(
                () => new JwtAuthorizationService(cfg).ValidateSessionKey(sessionKey));

            cfg        = GetConfig("testKeyWithALengthOfAtLeast32Bit");
            sessionKey = new JwtAuthorizationService(cfg)
                         .GetSessionKey(testClaims, TimeSpan.FromMinutes(10));
            recoveredClaims = new JwtAuthorizationService(cfg)
                              .ValidateSessionKey(sessionKey);
            Assert.AreEqual(testClaims.Guid, recoveredClaims.Guid);
        }
        public void GetSessionKeyTest()
        {
            var cfg  = GetConfig();
            var auth = new JwtAuthorizationService(cfg);

            var sessionKey1 = auth.GetSessionKey(testClaims, TimeSpan.FromMinutes(10));
            var sessionKey2 = auth.GetSessionKey(testClaims, TimeSpan.FromMinutes(10));
            var sessionKey3 = auth.GetSessionKey(new AuthClaims(), TimeSpan.FromMinutes(10));

            Assert.AreEqual(sessionKey1, sessionKey2);
            Assert.AreNotEqual(sessionKey1, sessionKey3);

            auth = new JwtAuthorizationService(cfg);
            var sessionKey4 = auth.GetSessionKey(testClaims, TimeSpan.FromMinutes(10));

            Assert.AreNotEqual(sessionKey1, sessionKey4);

            cfg         = GetConfig("testKeyWithALengthOfAtLeast32Bit");
            sessionKey1 = new JwtAuthorizationService(cfg)
                          .GetSessionKey(testClaims, TimeSpan.FromMinutes(10));
            sessionKey2 = new JwtAuthorizationService(cfg)
                          .GetSessionKey(testClaims, TimeSpan.FromMinutes(10));
            Assert.AreEqual(sessionKey1, sessionKey2);
        }