Exemple #1
0
        public async Task <IdentityServer3.Core.Models.Consent> LoadAsync(string subject, string client)
        {
            Consent found = null;

            if (options != null && options.SynchronousReads)
            {
                found = context.Consents.Find(subject, client);
            }
            else
            {
                found = await context.Consents.FindAsync(subject, client);
            }

            if (found == null)
            {
                return(null);
            }

            var result = new IdentityServer3.Core.Models.Consent
            {
                Subject  = found.Subject,
                ClientId = found.ClientId,
                Scopes   = ParseScopes(found.Scopes)
            };

            return(result);
        }
Exemple #2
0
        public async Task UpdateAsync(IdentityServer3.Core.Models.Consent consent)
        {
            Consent item = null;

            if (options != null && options.SynchronousReads)
            {
                item = context.Consents.Find(consent.Subject, consent.ClientId);
            }
            else
            {
                item = await context.Consents.FindAsync(consent.Subject, consent.ClientId);
            }

            if (item == null)
            {
                item = new Entities.Consent
                {
                    Subject  = consent.Subject,
                    ClientId = consent.ClientId
                };
                context.Consents.Add(item);
            }

            if (consent.Scopes == null || !consent.Scopes.Any())
            {
                context.Consents.Remove(item);
            }

            item.Scopes = StringifyScopes(consent.Scopes);

            await context.SaveChangesAsync();
        }
        public async Task<IdentityServer3.Core.Models.Consent> LoadAsync(string subject, string client)
        {
            Consent found = null;
            if (options != null && options.SynchronousReads)
            {
                found = context.Consents.Find(subject, client);
            }
            else
            {
                found = await context.Consents.FindAsync(subject, client);
            }

            if (found == null)
            {
                return null;
            }
                
            var result = new IdentityServer3.Core.Models.Consent
            {
                Subject = found.Subject,
                ClientId = found.ClientId,
                Scopes = ParseScopes(found.Scopes)
            };

            return result;
        }
        public async Task<IdentityServer3.Core.Models.Consent> LoadAsync(string subject, string client)
        {
            var found = await context.Consents.FindAsync(subject, client);
            if (found == null)
            {
                return null;
            }
                
            var result = new IdentityServer3.Core.Models.Consent
            {
                Subject = found.Subject,
                ClientId = found.ClientId,
                Scopes = ParseScopes(found.Scopes)
            };

            return result;
        }
Exemple #5
0
        public Task <IdentityServer3.Core.Models.Consent> LoadAsync(string subject, string client)
        {
            var found = _repo.GetConsentBySubjectAndClient(subject, client);

            if (found == null)
            {
                return(Task.FromResult <IdentityServer3.Core.Models.Consent>(null));
            }
            var result = new IdentityServer3.Core.Models.Consent
            {
                Subject  = found.Subject,
                ClientId = found.ClientId,
                Scopes   = ParseScopes(found.Scopes)
            };

            return(Task.FromResult <IdentityServer3.Core.Models.Consent>(result));
        }
Exemple #6
0
        public async Task <IdentityServer3.Core.Models.Consent> LoadAsync(string subject, string client)
        {
            var found = await context.Consents.FindAsync(subject, client);

            if (found == null)
            {
                return(null);
            }

            var result = new IdentityServer3.Core.Models.Consent
            {
                Subject  = found.Subject,
                ClientId = found.ClientId,
                Scopes   = ParseScopes(found.Scopes)
            };

            return(result);
        }
Exemple #7
0
        public async Task UpdateAsync(IdentityServer3.Core.Models.Consent consent)
        {
            ExecuteInTransaction(session =>
            {
                var item = session
                           .Query <Consent>()
                           .SingleOrDefault(c => c.Subject == consent.Subject && c.ClientId == consent.ClientId);

                if (item == null)
                {
                    if (consent.Scopes == null || !consent.Scopes.Any())
                    {
                        return;
                    }

                    item = new Consent
                    {
                        Subject  = consent.Subject,
                        ClientId = consent.ClientId,
                        Scopes   = StringifyScopes(consent.Scopes)
                    };

                    session.Save(item);
                }
                else
                {
                    if (consent.Scopes == null || !consent.Scopes.Any())
                    {
                        session.Delete(item);
                    }

                    item.Scopes = StringifyScopes(consent.Scopes);

                    session.SaveOrUpdate(item);
                }
            });

            await TaskExtensions.CompletedTask;
        }
Exemple #8
0
        public Task UpdateAsync(IdentityServer3.Core.Models.Consent consent)
        {
            var  item         = _repo.GetConsentBySubjectAndClient(consent.Subject, consent.ClientId);
            bool needToInsert = false;

            if (item == null)
            {
                item = new Models.Consent
                {
                    Subject  = consent.Subject,
                    ClientId = consent.ClientId
                };
                needToInsert = true;
            }

            if (consent.Scopes == null || !consent.Scopes.Any())
            {
                if (!needToInsert)
                {
                    _repo.DeleteConsentBySubjectAndClient(consent.Subject, consent.ClientId);
                }
            }

            item.Scopes = StringifyScopes(consent.Scopes);

            if (needToInsert)
            {
                _repo.InsertConsent(item);
            }
            else
            {
                _repo.UpdateConsent(item);
            }

            return(Task.FromResult(0));
        }
Exemple #9
0
        public async Task <IdentityServer3.Core.Models.Consent> LoadAsync(string subject, string client)
        {
            var parameters        = new Dictionary <string, object>();
            var dynamicParameters = new DynamicParameters();

            var pg = new PredicateGroup {
                Operator = GroupOperator.And, Predicates = new List <IPredicate>()
            };

            pg.Predicates.Add(Predicates.Field <Consent>(t => t.Subject, Operator.Eq, subject));
            pg.Predicates.Add(Predicates.Field <Consent>(t => t.ClientId, Operator.Eq, client));

            var sql = options.SqlGenerator.Select(new ConsentMapper(options), pg, null, parameters);

            dynamicParameters = new DynamicParameters();
            foreach (var parameter in parameters)
            {
                dynamicParameters.Add(parameter.Key, parameter.Value);
            }

            var consent = await options.Connection.QueryFirstOrDefaultAsync <Consent>(sql, dynamicParameters);

            if (consent == null)
            {
                return(null);
            }

            var result = new IdentityServer3.Core.Models.Consent
            {
                Subject  = consent.Subject,
                ClientId = consent.ClientId,
                Scopes   = ParseScopes(consent.Scopes)
            };

            return(result);
        }
Exemple #10
0
        public async Task UpdateAsync(IdentityServer3.Core.Models.Consent consent)
        {
            var parameters        = new Dictionary <string, object>();
            var dynamicParameters = new DynamicParameters();

            var pg = new PredicateGroup {
                Operator = GroupOperator.And, Predicates = new List <IPredicate>()
            };

            pg.Predicates.Add(Predicates.Field <Consent>(t => t.Subject, Operator.Eq, consent.Subject));
            pg.Predicates.Add(Predicates.Field <Consent>(t => t.ClientId, Operator.Eq, consent.ClientId));

            var sql = options.SqlGenerator.Select(new ConsentMapper(options), pg, null, parameters);

            dynamicParameters = new DynamicParameters();
            foreach (var parameter in parameters)
            {
                dynamicParameters.Add(parameter.Key, parameter.Value);
            }

            var item = await options.Connection.QueryFirstOrDefaultAsync <Consent>(sql, dynamicParameters);

            if (item == null)
            {
                if (consent.Scopes == null || !consent.Scopes.Any())
                {
                    return;
                }

                item = new Entities.Consent
                {
                    Subject  = consent.Subject,
                    ClientId = consent.ClientId,
                    Scopes   = StringifyScopes(consent.Scopes)
                };

                sql = options.SqlGenerator.Insert(new ConsentMapper(options));
                await options.Connection.ExecuteAsync(sql, item);
            }
            else
            {
                if (consent.Scopes == null || !consent.Scopes.Any())
                {
                    parameters = new Dictionary <string, object>();
                    sql        = options.SqlGenerator.Delete(new ConsentMapper(options), pg, parameters);

                    dynamicParameters = new DynamicParameters();
                    foreach (var parameter in parameters)
                    {
                        dynamicParameters.Add(parameter.Key, parameter.Value);
                    }

                    await options.Connection.ExecuteAsync(sql, dynamicParameters);
                }
                else
                {
                    item.Scopes = StringifyScopes(consent.Scopes);

                    parameters = new Dictionary <string, object>();
                    sql        = options.SqlGenerator.Update(new ConsentMapper(options), pg, parameters, true);

                    dynamicParameters = new DynamicParameters();
                    foreach (var parameter in parameters)
                    {
                        dynamicParameters.Add(parameter.Key, parameter.Value);
                    }
                    dynamicParameters.Add("Scopes", item.Scopes);

                    await options.Connection.ExecuteAsync(sql, dynamicParameters);
                }
            }
        }