Esempio n. 1
0
        private void SaveResources(CustomConfigurationDbContext ctx, ResourcesDataStorage storage)
        {
            // ApiResources
            ctx.ApiResources.AddRange(storage.ApiResources);
            SaveWithIdentityColumn(ctx, nameof(ctx.ApiResources));

            //1st level
            ctx.ApiClaims.AddRange(storage.ApiResourceClaims);
            SaveWithIdentityColumn(ctx, nameof(ctx.ApiClaims));

            ctx.ApiSecrets.AddRange(storage.ApiSecrets);
            SaveWithIdentityColumn(ctx, nameof(ctx.ApiSecrets));

            //2nd level
            ctx.ApiScopes.AddRange(storage.ApiScopes);
            SaveWithIdentityColumn(ctx, nameof(ctx.ApiScopes));

            ctx.ApiScopeClaims.AddRange(storage.ApiScopeClaims);
            SaveWithIdentityColumn(ctx, nameof(ctx.ApiScopeClaims));



            // IdentityResources
            ctx.IdentityResources.AddRange(storage.IdentityResources);
            SaveWithIdentityColumn(ctx, nameof(ctx.IdentityResources));

            ctx.IdentityClaims.AddRange(storage.IdentityClaims);
            SaveWithIdentityColumn(ctx, nameof(ctx.IdentityClaims));
        }
Esempio n. 2
0
        private void SaveWithIdentityColumn(CustomConfigurationDbContext ctx, string tableName)
        {
            // https://docs.microsoft.com/en-us/ef/core/saving/explicit-values-generated-properties
            ctx.Database.OpenConnection();
            try
            {
#pragma warning disable EF1000 // Possible SQL injection vulnerability.
                ctx.Database.ExecuteSqlCommand(new RawSqlString($"SET IDENTITY_INSERT dbo.{tableName} ON"));
                ctx.SaveChanges();
                ctx.Database.ExecuteSqlCommand(new RawSqlString($"SET IDENTITY_INSERT dbo.{tableName} OFF"));
#pragma warning restore EF1000 // Possible SQL injection vulnerability.
            }
            finally
            {
                ctx.Database.CloseConnection();
            }
        }
Esempio n. 3
0
        private void SaveClientsWithChildren(CustomConfigurationDbContext ctx, ClientDataStorage storage)
        {
            // Clients
            SaveWithIdentityColumn(ctx, nameof(ctx.Clients));

            // ClientClaims
            ctx.ClientClaims.AddRange(storage.Claims);
            SaveWithIdentityColumn(ctx, nameof(ctx.ClientClaims));

            // ClientRedirectUris
            ctx.ClientRedirectUris.AddRange(storage.RedirectUris);
            SaveWithIdentityColumn(ctx, nameof(ctx.ClientRedirectUris));

            // PostLogoutRedirectUris
            ctx.ClientPostLogoutRedirectUris.AddRange(storage.PostLogoutRedirectUris);
            SaveWithIdentityColumn(ctx, nameof(ctx.ClientPostLogoutRedirectUris));


            // ClientCorsOrigins
            ctx.ClientCorsOrigins.AddRange(storage.AllowedCorsOrigins);
            SaveWithIdentityColumn(ctx, nameof(ctx.ClientCorsOrigins));

            // ClientScopes
            ctx.ClientScopes.AddRange(storage.AllowedScopes);
            SaveWithIdentityColumn(ctx, nameof(ctx.ClientScopes));

            // AllowedGrantTypes
            ctx.ClientGrantTypes.AddRange(storage.AllowedGrantTypes);
            SaveWithIdentityColumn(ctx, nameof(ctx.ClientGrantTypes));

            // ClientSecrets
            ctx.ClientSecrets.AddRange(storage.ClientSecrets);
            SaveWithIdentityColumn(ctx, nameof(ctx.ClientSecrets));

            // Properties
            ctx.ClientProperties.AddRange(storage.Properties);
            SaveWithIdentityColumn(ctx, nameof(ctx.ClientProperties));

            // IdentityProviderRestrictions
            ctx.ClientIdPRestrictions.AddRange(storage.IdentityProviderRestrictions);
            SaveWithIdentityColumn(ctx, nameof(ctx.ClientIdPRestrictions));
        }