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

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

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

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

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

                context.Ticket.Properties.IssuedUtc = token.IssuedUtc;
                context.Ticket.Properties.ExpiresUtc = token.ExpiresUtc;

                token.ProtectedTicket = context.SerializeTicket();

                using (RefreshTokenRepository _repo = new RefreshTokenRepository(_uow))
                {
                    _repo.AddRefreshToken(token);
                    await _uow.SaveAsync();
                }

                context.SetToken(refreshTokenId);

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

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

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

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

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

                context.Ticket.Properties.IssuedUtc  = token.IssuedUtc;
                context.Ticket.Properties.ExpiresUtc = token.ExpiresUtc;

                token.ProtectedTicket = context.SerializeTicket();

                using (RefreshTokenRepository _repo = new RefreshTokenRepository(_uow))
                {
                    _repo.AddRefreshToken(token);
                    await _uow.SaveAsync();
                }

                context.SetToken(refreshTokenId);
            }
        }
        public async Task CreateAsync(AuthenticationTokenCreateContext context)
        {
            var clientid = context.Ticket.Properties.Dictionary["ou:client_id"];

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

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

            using (RefreshTokenRepository _refreshTokenRepository = new RefreshTokenRepository())
            {
                var refreshTokenLifeTime = context.OwinContext.Get <string>("ou:clientRefreshTokenLifeTime");

                var token = new RefreshToken()
                {
                    RefreshTokenId = Utility.GetHash(refreshTokenId),
                    ClientId       = clientid,
                    Subject        = context.Ticket.Identity.Name,
                    IssuedOn       = DateTime.UtcNow,
                    ExpiresOn      = DateTime.UtcNow.AddMinutes(Convert.ToDouble(refreshTokenLifeTime))
                };

                context.Ticket.Properties.IssuedUtc  = token.IssuedOn;
                context.Ticket.Properties.ExpiresUtc = token.ExpiresOn;
                token.ProtectedTicket = context.SerializeTicket();

                var result = await _refreshTokenRepository.AddRefreshToken(token);

                if (result)
                {
                    context.SetToken(refreshTokenId);
                }
            }
        }