public IdentityAdminCoreManagerTests()
        {
            _identityAdminManagerService = new IdentityAdminManagerService("IdSvr3ConfigAdmin");
            using (var db = new ClientConfigurationDbContext(ConnectionString))
            {
                var allClients = db.Clients.Where(p => true);
                foreach (var c in allClients  )
                {
                    db.Clients.Remove(c);
                }
                db.SaveChanges();
                var testClient = new Client
                {
                    ClientId = "IdToTest",
                    ClientName = _clientName,
                    Enabled = true,
                    Flow = Flows.Implicit,
                    RequireConsent = true,
                    AllowRememberConsent = true,
                    RedirectUris =new List<ClientRedirectUri>() {new ClientRedirectUri {Id = 1, Uri = "www.redirect.com"}},
                    PostLogoutRedirectUris = new List<ClientPostLogoutRedirectUri>(){new ClientPostLogoutRedirectUri{Id = 1, Uri = "www.postRedirectUri.com"}},
                    AllowedScopes = new List<ClientScope>() { new ClientScope { Scope = "read" ,Id = 1} },
                    AccessTokenType = AccessTokenType.Jwt,
                    ClientSecrets = new List<ClientSecret>{new ClientSecret{Id = 1,Description = "removeMe",Type = "ssssshhh", Value = "nothing to see here"}},
                    IdentityProviderRestrictions = new List<ClientIdPRestriction>(){new ClientIdPRestriction{Id = 1,Provider = "www.provideme.com"}},
                    AllowedCustomGrantTypes = new List<ClientCustomGrantType>{new ClientCustomGrantType{Id = 1, GrantType = "Authorization Grant"}},
                    Claims = new List<ClientClaim>{new ClientClaim{Id = 1,Value = "tester", Type = "role"}},
                    AllowedCorsOrigins = new List<ClientCorsOrigin> { new ClientCorsOrigin { Id = 1,Origin = "www.CrossOriginMe.com"} }
                };
                db.Clients.Add(testClient);
                db.SaveChanges();
                _clientSubject = testClient.Id.ToString();
            }

            using (var db = new ScopeConfigurationDbContext(ConnectionString))
            {
                var allScopes = db.Scopes.Where(p => true);
                foreach (var c in allScopes)
                {
                    db.Scopes.Remove(c);
                }
                db.SaveChanges();
                var testScope = new Scope { Name = _scopeName,ScopeClaims = new List<ScopeClaim>{new ScopeClaim{Id = 1,Description = "To Test", Name = "testScope"}}};
                db.Scopes.Add(testScope);
                db.SaveChanges();
                _scopeSubject = testScope.Id.ToString();
            }
        }
Ejemplo n.º 2
0
		public static void ConfigureClients(IEnumerable<Client> clients, EntityFrameworkServiceOptions options) {
			using(var db = new ClientConfigurationDbContext(options.ConnectionString, options.Schema)) {
				if(!db.Clients.Any()) {
					foreach(var c in clients) {
						var e = c.ToEntity();
						db.Clients.Add(e);
					}
					db.SaveChanges();
				}
			}
		}
        public void CanAddAndDeleteClientRedirectUri()
        {
            using (var db = new ClientConfigurationDbContext(ConfigConnectionStringName))
            {
                db.Clients.Add(new Client
                {
                    ClientId = "test-client",
                    ClientName = "Test Client"
                });

                db.SaveChanges();
            }

            using (var db = new ClientConfigurationDbContext(ConfigConnectionStringName))
            {
                var client = db.Clients.First();

                client.RedirectUris.Add(new ClientRedirectUri
                {
                    Uri = "https://redirect-uri-1"
                });

                db.SaveChanges();
            }

            using (var db = new ClientConfigurationDbContext(ConfigConnectionStringName))
            {
                var client = db.Clients.First();
                var redirectUri = client.RedirectUris.First();

                client.RedirectUris.Remove(redirectUri);

                db.SaveChanges();
            }

            using (var db = new ClientConfigurationDbContext(ConfigConnectionStringName))
            {
                var client = db.Clients.First();

                Assert.Equal(0, client.RedirectUris.Count());
            }
        }
        public void CanAddAndDeleteClientScopes()
        {
            using (var db = new ClientConfigurationDbContext(ConfigConnectionStringName))
            {
                db.Clients.Add(new Client
                {
                    ClientId = "test-client-scopes",
                    ClientName = "Test Client"
                });

                db.SaveChanges();
            }

            using (var db = new ClientConfigurationDbContext(ConfigConnectionStringName))
            {
                var client = db.Clients.First();

                client.AllowedScopes.Add(new ClientScope
                {
                    Scope = "test"
                });

                db.SaveChanges();
            }

            using (var db = new ClientConfigurationDbContext(ConfigConnectionStringName))
            {
                var client = db.Clients.First();
                var scope = client.AllowedScopes.First();

                client.AllowedScopes.Remove(scope);

                db.SaveChanges();
            }

            using (var db = new ClientConfigurationDbContext(ConfigConnectionStringName))
            {
                var client = db.Clients.First();

                Assert.Equal(0, client.AllowedScopes.Count());
            }
        }
Ejemplo 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();
                }
            }
        }