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 UpdateAsync(IdentityServer3.Core.Models.Consent consent)
        {
            var item = await context.Consents.FindAsync(consent.Subject, consent.ClientId);
            if (item == null)
            {
                item = new Entities.ConsentEntity 
                { 
                    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 ClientConverter(IdentityServer3.Core.Services.IClientStore clientStore)
        {
            if (clientStore == null) throw new ArgumentNullException("clientStore");

            _clientStore = clientStore;
        }
        public ScopeConverter(IdentityServer3.Core.Services.IScopeStore scopeStore)
        {
            if (scopeStore == null) throw new ArgumentNullException("scopeStore");

            this.scopeStore = scopeStore;
        }
Esempio n. 5
0
        public static void ConfigureClients(IdentityServer3.Core.Models.Client client, EntityFrameworkServiceOptions options)
        {
            using (var db = new ClientConfigurationDbContext(options.ConnectionString, options.Schema))
            {
                if(db.Clients.Any()&&db.Clients.Where(x=>x.ClientId== SSOISConstants.LocalClientId).Count()>0)
                {
                    //Update Client
                    var dbClient = db.Clients.Where(x => x.ClientId == SSOISConstants.LocalClientId).First();

                    if(db.Clients.Where(x => x.ClientId == SSOISConstants.LocalClientId
                    && x.ClientUri== SSOISConstants.LocalClientUri).Count()==0)
                    {
                        var clt = db.Clients.Where(x => x.ClientId == SSOISConstants.LocalClientId).First();
                        clt.ClientUri = SSOISConstants.LocalClientUri;
                        db.Entry(clt).State = EntityState.Modified;
                    }

                    //Secret
                    string screct = SSOISConstants.LocalClientSecret.Sha256();
                    var lstOldSecret = db.Set<ClientSecret>().Where(x => x.Client.Id == dbClient.Id);
                    if (lstOldSecret.Where(x => x.Value == screct).Count() == 0)
                    {
                        db.Set<ClientSecret>().RemoveRange(lstOldSecret);
                        var lstNewSecret = new List<ClientSecret>() {
                        new ClientSecret() {
                            Value = SSOISConstants.LocalClientSecret.Sha256(),
                            Type = "SharedSecret",
                            Client = dbClient
                        } };
                        db.Set<ClientSecret>().AddRange(lstNewSecret);
                    }

                    //RedirectUris
                    var lstOldRed = db.Set<ClientRedirectUri>().Where(x => x.Client.Id == dbClient.Id);
                    var lstOldStrRed = lstOldRed.Select(x => x.Uri).ToList();
                    db.Set<ClientRedirectUri>().RemoveRange(lstOldRed.Where(x=> !SSOISConstants.LocalRedirectUris.Contains(x.Uri)));
                    var lstNewRed = new List<ClientRedirectUri>();
                    foreach (var sel in SSOISConstants.LocalRedirectUris)
                        if (!lstOldStrRed.Contains(sel))
                            lstNewRed.Add(new ClientRedirectUri() { Uri = sel, Client = dbClient });
                    db.Set<ClientRedirectUri>().AddRange(lstNewRed);

                    //PostLogoutRedirectUris
                    var lstOldPost = db.Set<ClientPostLogoutRedirectUri>().Where(x => x.Client.Id == dbClient.Id);
                    var lstOldStrPost = lstOldRed.Select(x => x.Uri).ToList();
                    db.Set<ClientPostLogoutRedirectUri>().RemoveRange(lstOldPost.Where(x => !SSOISConstants.LocalPostLogoutRedirectUris.Contains(x.Uri)));
                    var lstNewPost = new List<ClientPostLogoutRedirectUri>();
                    foreach (var sel in SSOISConstants.LocalPostLogoutRedirectUris)
                        if (!lstOldStrPost.Contains(sel))
                            lstNewPost.Add(new ClientPostLogoutRedirectUri() { Uri = sel, Client = dbClient });
                    db.Set<ClientPostLogoutRedirectUri>().AddRange(lstNewPost);

                    db.SaveChanges();
                }
                else
                {
                    var e = client.ToEntity();
                    db.Clients.Add(e);
                    db.SaveChanges();
                }
            }
        }