public static int Main(string[] args)
        {
            var servicName = "auth-service-db-up";
            DockerAuthServiceConfiguration configuration;

            configuration = new DockerAuthServiceConfiguration();
            var masterConnectionString = configuration.MasterCommandConnectionString;

            DeployChanges.To.SqlDatabase(masterConnectionString)
            .JournalToSqlTable("dbo", servicName)
            .WithScriptsFromFileSystem(@"localInit", s => s.Contains($"sql")).LogToConsole().Build()
            .PerformUpgrade();

            var connectionString = configuration.CommandConnectionString;

            Log.Information(connectionString);

            var upgrader = DeployChanges.To.SqlDatabase(connectionString).JournalToSqlTable("dbo", "Migrations")
                           .WithScriptsAndCodeEmbeddedInAssembly(
                Assembly.GetExecutingAssembly(), s => s.Contains($"sql"))
                           .WithTransactionPerScript()
                           .LogToConsole().WithExecutionTimeout(new TimeSpan(0, 0, 90)).Build();

            upgrader.TryConnect(out var message);
            Log.Information(message);
            var result = upgrader.PerformUpgrade();

            Log.Information(result?.Error?.Message);
            Log.Information("finished");

            return(result?.Error == null ? 0 : 1);
        }
Beispiel #2
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <ForwardedHeadersOptions>(options =>
            {
                options.ForwardedHeaders      = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
                options.RequireHeaderSymmetry = false;
                options.KnownNetworks.Clear();
                options.KnownProxies.Clear();
            });


            var sqlConf          = new DockerAuthServiceConfiguration();
            var connectionString = sqlConf.CommandConnectionString;

            var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;

            Console.WriteLine($"migration assembly: {migrationsAssembly}");
            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(connectionString));

            services.AddIdentity <ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores <ApplicationDbContext>()
            .AddDefaultTokenProviders();

            services.AddMvc().SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_1);


            var builder = services.AddIdentityServer(options =>
            {
                options.Events.RaiseErrorEvents       = true;
                options.Events.RaiseInformationEvents = true;
                options.Events.RaiseFailureEvents     = true;
                options.Events.RaiseSuccessEvents     = true;
            })
                          // this adds the config data from DB (clients, resources)
                          .AddConfigurationStore(options =>
            {
                options.ConfigureDbContext = b =>
                                             b.UseSqlServer(connectionString,
                                                            sql => sql.MigrationsAssembly(migrationsAssembly));
            })
                          // this adds the operational data from DB (codes, tokens, consents)
                          .AddOperationalStore(options =>
            {
                options.ConfigureDbContext = b =>
                                             b.UseSqlServer(connectionString,
                                                            sql => sql.MigrationsAssembly(migrationsAssembly));

                // this enables automatic token cleanup. this is optional.
                options.EnableTokenCleanup = true;
            })
                          .AddAspNetIdentity <ApplicationUser>();


            builder.AddCertificateFromFile();


            services.AddAuthentication()
            .AddGoogle(options =>
            {
                // register your IdentityServer with Google at https://console.developers.google.com
                // enable the Google+ API
                // set the redirect URI to http://localhost:5000/signin-google
                options.ClientId     = "copy client ID from Google here";
                options.ClientSecret = "copy client secret from Google here";
            });
        }