public override async Task StoreAsync(string key, RefreshToken value)
        {
            Entities.Token token = null;
            if (options != null && options.SynchronousReads)
            {
                token = context.Tokens.Find(key, tokenType);
            }
            else
            {
                token = await context.Tokens.FindAsync(key, tokenType);
            }

            if (token == null)
            {
                token = new Entities.Token
                {
                    Key       = key,
                    SubjectId = value.SubjectId,
                    ClientId  = value.ClientId,
                    TokenType = tokenType
                };
                context.Tokens.Add(token);
            }

            token.JsonCode = ConvertToJson(value);
            token.Expiry   = value.CreationTime.AddSeconds(value.LifeTime);

            await context.SaveChangesAsync();
        }
        public override async Task StoreAsync(string key, AuthorizationCode code)
        {
            var efCode = new Entities.Token
            {
                Key       = key,
                SubjectId = code.SubjectId,
                ClientId  = code.ClientId,
                JsonCode  = ConvertToJson(code),
                Expiry    = DateTimeOffset.UtcNow.AddSeconds(code.Client.AuthorizationCodeLifetime),
                TokenType = this.tokenType
            };

            context.Tokens.Add(efCode);
            await context.SaveChangesAsync();
        }
        public async Task RemoveAsync(string key)
        {
            Entities.Token token = null;
            if (options != null && options.SynchronousReads)
            {
                token = context.Tokens.Find(key, tokenType);
            }
            else
            {
                token = await context.Tokens.FindAsync(key, tokenType);
            }

            if (token != null)
            {
                context.Tokens.Remove(token);
                await context.SaveChangesAsync();
            }
        }
        public async Task <T> GetAsync(string key)
        {
            Entities.Token token = null;
            if (options != null && options.SynchronousReads)
            {
                token = context.Tokens.Find(key, tokenType);
            }
            else
            {
                token = await context.Tokens.FindAsync(key, tokenType);
            }

            if (token == null || token.Expiry < DateTimeOffset.UtcNow)
            {
                return(null);
            }

            return(ConvertFromJson(token.JsonCode));
        }
        public override async Task StoreAsync(string key, RefreshToken value)
        {
            var token = await context.Tokens.FindAsync(key, tokenType);

            if (token == null)
            {
                token = new Entities.Token
                {
                    Key       = key,
                    SubjectId = value.SubjectId,
                    ClientId  = value.ClientId,
                    JsonCode  = ConvertToJson(value),
                    TokenType = tokenType
                };
                context.Tokens.Add(token);
            }

            token.Expiry = DateTimeOffset.UtcNow.AddSeconds(value.LifeTime);
            await context.SaveChangesAsync();
        }