Beispiel #1
0
        private string GetConnectionString(DatabaseOptions databaseOptions)
        {
            SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();

            builder.DataSource = databaseOptions.Server;
            builder.UserID     = databaseOptions.UserId;
            builder.Password   = databaseOptions.Password;

            if (!string.IsNullOrEmpty(databaseOptions.Name))
            {
                builder.InitialCatalog = databaseOptions.Name;
            }

            return(builder.ToString());
        }
Beispiel #2
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <DatabaseOptions>(Configuration.GetSection("database"));
            DatabaseOptions dbOptions = services.BuildServiceProvider().GetService <DatabaseOptions>();

            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlite(GetConnectionString(dbOptions)));

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

            services.AddMvc();

            string connectionString   = GetConnectionString(dbOptions);
            string migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;

            IIdentityServerBuilder builder = services.AddIdentityServer(options =>
            {
                options.Events.RaiseErrorEvents       = true;
                options.Events.RaiseInformationEvents = true;
                options.Events.RaiseFailureEvents     = true;
                options.Events.RaiseSuccessEvents     = true;
                options.IssuerUri = "http://auth:5000";
            })
                                             .AddAspNetIdentity <ApplicationUser>()
                                             //this adds the config data from DB (clients, resources, CORS)
                                             .AddConfigurationStore(options =>
            {
                options.ConfigureDbContext = db =>
                                             db.UseSqlServer(connectionString,
                                                             sql => sql.MigrationsAssembly(migrationsAssembly));
            })
                                             // this adds the operational data from DB (codes, tokens, consents)
                                             .AddOperationalStore(options =>
            {
                options.ConfigureDbContext = db =>
                                             db.UseSqlServer(connectionString,
                                                             sql => sql.MigrationsAssembly(migrationsAssembly));

                // this enables automatic token cleanup. this is optional.
                options.EnableTokenCleanup = true;
                // options.TokenCleanupInterval = 15; // interval in seconds. 15 seconds useful for debugging
            });

            if (Environment.IsDevelopment())
            {
                builder.AddDeveloperSigningCredential();
            }
            else
            {
                throw new Exception("need to configure key material");
            }

            services.AddAuthentication()
            .AddGoogle(options =>
            {
                options.ClientId     = "141503743850-s534b38nqbi1aor5nbrc984ctpdcktnv.apps.googleusercontent.com";
                options.ClientSecret = "UG0I9uog8UVcjUQEYfumHbVO";
            });

            services.UseAdminUI();
        }