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.º 2
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));
        }
Exemplo n.º 3
0
        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 consent = db.Consents.FirstOrDefault(c => c.ClientId == client.ClientId &&
                                                         c.Scopes == orderedScopes &&
                                                         c.Subject == subjectId);

                return(Task.FromResult(consent == null));
            }
        }