public async Task CreateAsync(AuthenticationTokenCreateContext context)
        {
            var clientid    = context.Ticket.Properties.Dictionary["as:client_id"];
            var userid      = context.Ticket.Properties.Dictionary["userid"];
            var securityKey = context.Ticket.Properties.Dictionary["securityKey"];

            if (string.IsNullOrEmpty(clientid) || string.IsNullOrEmpty(securityKey))
            {
                return;
            }

            var refreshTokenId = Guid.NewGuid().ToString("n");

            using (AuthRepository _repo = new AuthRepository())
            {
                var refreshTokenLifeTime = context.OwinContext.Get <string>("as:clientRefreshTokenLifeTime");

                //var token = new RefreshToken()
                //{
                //    Id = Helper.GetHash(refreshTokenId),
                //    ClientId = clientid,
                //    Subject = context.Ticket.Identity.Name,
                //    IssuedUtc = DateTime.UtcNow,
                //    ExpiresUtc = DateTime.UtcNow.AddMinutes(Convert.ToDouble(refreshTokenLifeTime))
                //};
                var token = new LoginCacheModel()
                {
                    userid      = userid,
                    userName    = context.Ticket.Identity.Name,
                    securityKey = securityKey,
                };
                //context.Ticket.Properties.IssuedUtc = token.IssuedUtc;
                //context.Ticket.Properties.ExpiresUtc = token.ExpiresUtc;

                //token.ProtectedTicket = context.SerializeTicket();

                var result = await _repo.AddRefreshToken(token);

                if (result)
                {
                    context.SetToken(refreshTokenId);
                }
            }
        }
        public async Task <bool> AddRefreshToken(LoginCacheModel token)
        {
            try
            {
                var RedisConnection = System.Configuration.ConfigurationManager.AppSettings["RedisConnection"];
                var redis           = RedisService <LoginCacheModel> .GetInstance(RedisConnection);

                LoginCacheModel RefreshToken;
                RefreshToken = redis.Get <LoginCacheModel>("AT:Login:"******"AT:Login:"******"AT:Login:" + token.userName, token);
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }