public static void SetUp(EntityFrameworkServiceOptions options) { using (var db = new ClientConfigurationDbContext(options.ConnectionString, options.Schema)) { if (!db.Clients.Any()) { foreach (var c in Clients.Get()) { var e = c.ToEntity(); db.Clients.Add(e); } db.SaveChanges(); } } using (var db = new ScopeConfigurationDbContext(options.ConnectionString, options.Schema)) { if (!db.Scopes.Any()) { foreach (var s in Scopes.Get()) { var e = s.ToEntity(); db.Scopes.Add(e); } db.SaveChanges(); } } }
/// Using EF6 public Ids3RootDTO GetIds3ClientsRoot() { using (ClientConfigurationDbContext clientCtx = new ClientConfigurationDbContext(Ids3ConnectiionString)) { var clients = clientCtx.Clients .Include(x => x.Claims) .Include(x => x.AllowedCorsOrigins) .Include(x => x.AllowedCustomGrantTypes) .Include(x => x.ClientSecrets) .Include(x => x.RedirectUris) .Include(x => x.PostLogoutRedirectUris) .Include(x => x.AllowedScopes) .Include(x => x.IdentityProviderRestrictions) .Include(x => x.AllowedCustomGrantTypes) //.Include(x => x.Properties) .AsNoTracking().ToArray(); // Assume that App uses 3 contexts in the same database using (ScopeConfigurationDbContext scopeCtx = new ScopeConfigurationDbContext(Ids3ConnectiionString)) { var scopes = scopeCtx.Scopes .Include(x => x.ScopeClaims) .Include(x => x.ScopeSecrets) .AsNoTracking().ToArray(); return(new Ids3RootDTO { Clients = clients, Scopes = scopes }); } } }
protected override void ProcessRecord() { var db = new ScopeConfigurationDbContext(this.ConnectionString, this.Schema); var entity = db.Scopes.Single(c => c.Name == this.Scope.Name); var currentId = entity.Id; var currentscope = entity.ToModel(); var attachedEntry = db.Entry(entity); var newentity = this.Scope.ToEntity(); newentity.Id = currentId; attachedEntry.CurrentValues.SetValues(newentity); // Synchronize scope claims nav property - FIXME ugly foreach (var scope in currentscope.Claims.Union(this.Scope.Claims).Distinct()) { if (currentscope.Claims.Any(x => x.Name == scope.Name) && !this.Scope.Claims.Any(x => x.Name == scope.Name)) { entity.ScopeClaims.Remove(entity.ScopeClaims.First(x => x.Name == scope.Name)); } else if (!currentscope.Claims.Any(x => x.Name == scope.Name) && this.Scope.Claims.Any(x => x.Name == scope.Name)) { entity.ScopeClaims.Add(new Thinktecture.IdentityServer.EntityFramework.Entities.ScopeClaim() { Name = scope.Name, Description = scope.Description, AlwaysIncludeInIdToken = scope.AlwaysIncludeInIdToken }); } } db.SaveChanges(); }
public static void InitClientAndScopeSampleDatas(EntityFrameworkServiceOptions options) { var clients = InMemoryClient.clients; 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(); } } var scopes = InMemoryScope.scopes; using (var db = new ScopeConfigurationDbContext(options.ConnectionString, options.Schema)) { if (!db.Scopes.Any()) { foreach (var s in scopes) { var e = s.ToEntity(); db.Scopes.Add(e); } db.SaveChanges(); } } }
protected override void ProcessRecord() { var db = new ScopeConfigurationDbContext(this.ConnectionString, this.Schema); var entity = db.Scopes.First(s => s.Name == this.ScopeName); db.Scopes.Remove(entity); db.SaveChanges(); }
public static void ConfigureScopes(IEnumerable <Scope> scopes, EntityFrameworkServiceOptions options) { using (var db = new ScopeConfigurationDbContext(options.ConnectionString, options.Schema)) { if (!db.Scopes.Any()) { foreach (var s in scopes) { var e = s.ToEntity(); db.Scopes.Add(e); } db.SaveChanges(); } } }
public void SetupScopes(IEnumerable <Scope> scopes, EntityFrameworkServiceOptions options) { using (var context = new ScopeConfigurationDbContext(options.ConnectionString, options.Schema)) { if (context.Scopes.Any()) { return; } foreach (var scope in scopes) { context.Scopes.Add(scope.ToEntity()); } context.SaveChanges(); } }
protected override void ProcessRecord() { //var db = new ClientConfigurationDbContext(this.ConnectionString, this.Schema); var db = new ScopeConfigurationDbContext(this.ConnectionString, this.Schema); if (!string.IsNullOrEmpty(ScopeName)) { var scope = db.Scopes.FirstOrDefault(s => s.Name == ScopeName); WriteObject(scope.ToModel()); } else { var dbscopes = db.Scopes.ToList(); var scopes = from c in dbscopes select c.ToModel(); WriteObject(scopes); } }
protected override void ProcessRecord() { var db = new ScopeConfigurationDbContext(this.ConnectionString, this.Schema); var scope = new Thinktecture.IdentityServer.Core.Models.Scope { Name = this.Name, DisplayName = this.DisplayName, Description = this.Description, Type = this.ScopeType, ShowInDiscoveryDocument = this.Discoverable, Emphasize = this.Emphasize, Required = this.Required, }; db.Scopes.Add(scope.ToEntity()); db.SaveChanges(); WriteObject(scope); }
public EntityFrameworkScopeReader(ScopeConfigurationDbContext context) { this.context = context ?? throw new ArgumentNullException(nameof(context)); }
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(); } }
public static void Configure(EntityFrameworkServiceOptions options) { using (var db = new ScopeConfigurationDbContext(options.ConnectionString, options.Schema)) { if (!db.Scopes.Any()) { foreach (var s in StandardScopes.All) { var e = s.ToEntity(); db.Scopes.Add(e); } foreach (var s in StandardScopes.AllAlwaysInclude) { var e = s.ToEntity(); db.Scopes.Add(e); } db.SaveChanges(); } } using (var db = new Context(options.ConnectionString)) { if (!db.Users.Any()) { using (var userManager = new UserManager(new UserStore(db))) { var defaultUserPassword = "******"; // Must be atleast 6 characters var user = new User { UserName = "******", FirstName = "Luke", LastName = "Skywalker", Email = "*****@*****.**", EmailConfirmed = true }; userManager.Create(user, defaultUserPassword); userManager.AddClaim(user.Id, new Claim(Core.Constants.ClaimTypes.WebSite, "https://www.johanbostrom.se/")); } db.SaveChanges(); } } using (var db = new ClientConfigurationDbContext(options.ConnectionString, options.Schema)) { if (!db.Clients.Any()) { var defaultHybridClient = new Client { ClientName = "Default Hybrid Client", ClientId = "default.hybrid", Flow = Flows.Hybrid, ClientSecrets = new List <Secret> { new Secret("default.hybrid.password".Sha256()) }, AllowedScopes = new List <string> { Core.Constants.StandardScopes.OpenId, Core.Constants.StandardScopes.Profile, Core.Constants.StandardScopes.Email, Core.Constants.StandardScopes.Roles, Core.Constants.StandardScopes.Address, Core.Constants.StandardScopes.Phone, Core.Constants.StandardScopes.OfflineAccess }, ClientUri = "https://localhost:44300/", RequireConsent = false, AccessTokenType = AccessTokenType.Reference, RedirectUris = new List <string>(), PostLogoutRedirectUris = new List <string> { "https://localhost:44300/" }, LogoutSessionRequired = true }; db.Clients.Add(defaultHybridClient.ToEntity()); db.SaveChanges(); } } }