/// <summary>
        ///
        /// </summary>
        private void CreateToken_InvalidAudience(bool validateAudience)
        {
            TokenClaim  claim   = TestMsJwtProviderBase.CreateClaim();
            TestPayload payload = TestMsJwtProviderBase.CreatePayload();

            string token = GetProvider().CreateToken(claim, payload);

            MsJwtValidatorBase <TestPayload> validator = CreateValidator(TestConstants.Issuer, validateAudience ? "thisAudience" : null);

            if (validateAudience)
            {
                Assert.IsFalse(validator.ValidateToken(token, out ITokenClaim tokenClaim, out TestPayload tokenPayload, out TokenState state, out string errorMessage));
                Assert.AreEqual(state, TokenState.InvalidAudience);
            }
            else
            {
                Assert.IsTrue(validator.ValidateToken(token, out ITokenClaim tokenClaim, out TestPayload tokenPayload, out TokenState state, out string errorMessage));
                Assert.AreEqual(state, TokenState.Valid);
            }
        }
        public void CreateToken_NotBefore()
        {
            TokenClaim  claim   = TestMsJwtProviderBase.CreateClaim();
            TestPayload payload = TestMsJwtProviderBase.CreatePayload();

            claim.NotBefore = DateTimeOffset.UtcNow.AddSeconds(5);

            string token = GetProvider().CreateToken(claim, payload);

            MsJwtValidatorBase <TestPayload> validator = CreateValidator(TestConstants.Issuer, TestConstants.Audience);

            Assert.IsFalse(validator.ValidateToken(token, out ITokenClaim tokenClaim, out TestPayload tokenPayload, out TokenState state, out string errorMessage));

            Assert.AreEqual(state, TokenState.NotBefore);
        }
        public void CreateToken_NullPayload()
        {
            TokenClaim  claim   = TestMsJwtProviderBase.CreateClaim();
            TestPayload payload = null;

            string token = GetProvider().CreateToken(claim, payload);

            MsJwtValidatorBase <TestPayload> validator = CreateValidator(TestConstants.Issuer, TestConstants.Audience);

            Assert.IsTrue(validator.ValidateToken(token, out ITokenClaim tokenClaim, out TestPayload tokenPayload, out TokenState state, out string errorMessage));

            Assert.IsTrue(ValueEquals(claim, tokenClaim));
            Assert.IsNull(tokenPayload);
            Assert.AreEqual(state, TokenState.Valid);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="secondsBefore"></param>
        /// <returns></returns>
        private TokenManager CreateRefresher(int secondsBefore)
        {
            return(new TokenManager(token =>
            {
                if (!m_Validator.ValidateToken(token, out ITokenClaim claim, out TestPayload payload, out TokenState state, out string errorMessage))
                {
                    throw new ArgumentException(errorMessage);
                }

                TokenClaim newClaim = new TokenClaim()
                {
                    JwtID = claim.JwtID,
                    Audience = claim.Audience,
                    Expiration = DateTimeOffset.UtcNow.AddSeconds(TestConstants.AccessTokenLifetimeSeconds),
                };

                return GetToken(newClaim, payload);
            }
                                    , secondsBefore
                                    ));
        }