public async Task UpdateConsentAsync(string client, string subject, IEnumerable <string> scopes)
        {
            using (var db = new CoreDbContext(_connectionString))
            {
                var consent = await db.Consents.FindAsync(subject, client);

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

                    consent.Scopes = GetOrderedScopes(scopes);
                }
                else if (consent != null)
                {
                    db.Consents.Remove(consent);
                }

                db.SaveChanges();
            }
        }
        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 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();
                }
            }
        }
Exemplo n.º 4
0
        public Task UpdateConsentAsync(Models.Client client, System.Security.Claims.ClaimsPrincipal user, IEnumerable <string> scopes)
        {
            if (client.AllowRememberConsent)
            {
                using (var db = new CoreDbContext(_connectionString))
                {
                    var consent = new Entities.Consent
                    {
                        ClientId = client.ClientId,
                        Subject  = user.GetSubjectId(),
                        Scopes   = string.Join(" ", scopes.OrderBy(s => s).ToArray())
                    };

                    db.Consents.Add(consent);
                    db.SaveChanges();
                }
            }

            return(Task.FromResult(0));
        }