public async Task UpdateConsentAsync(Models.Client client, System.Security.Claims.ClaimsPrincipal user, IEnumerable<string> scopes)
        {
            if (client.AllowRememberConsent)
            {
                using (var db = new CoreDbContext(_connectionString))
                {
                    var clientId = client.ClientId;
                    var subject = user.GetSubjectId();

                    var consent = await db.Consents.FindAsync(subject, clientId);

                    if (scopes.Any())
                    {
                        if (consent == null)
                        {
                            consent = new Entities.Consent
                            {
                                ClientId = client.ClientId,
                                Subject = user.GetSubjectId(),
                            };
                            db.Consents.Add(consent);
                        }

                        consent.Scopes = string.Join(" ", scopes.OrderBy(s => s).ToArray());
                    }
                    else if (consent != null)
                    {
                        db.Consents.Remove(consent);
                    }

                    db.SaveChanges();
                }
            }
        }
        public Task<bool> RequiresConsentAsync(Models.Client client, System.Security.Claims.ClaimsPrincipal user, IEnumerable<string> scopes)
        {
            if (!client.RequireConsent)
            {
                return Task.FromResult(false);
            }

            var orderedScopes = string.Join(" ", scopes.OrderBy(s => s).ToArray());

            string subjectId = user.GetSubjectId();

            using (var db = new CoreDbContext(_connectionString))
            {
                var exists = db.Consents.Any(c => c.ClientId == client.ClientId &&
                                                c.Scopes == orderedScopes &&
                                                c.Subject == subjectId);

                return Task.FromResult(!exists);
            }
        }