Beispiel #1
0
        public void Configuration(IAppBuilder app)
        {
            app.Map("/identity", idsrv =>
            {
                //Sökväg till certifikat och privat nyckel
                var certfile = AppDomain.CurrentDomain.BaseDirectory + @"\Certificates\OAuthSign.pfx";

                //Factory som konfigurerar typen av användare, clients och scopes
                var factory = new IdentityServerServiceFactory()
                              .UseInMemoryUsers(InMemory.GetUsers())
                              .UseInMemoryScopes(InMemory.GetScopes())
                              .UseInMemoryClients(InMemory.GetClients());

                //Optionsobjekt som används för att konfigurera identityserver middleware
                var options                = new IdentityServerOptions();
                options.Factory            = factory;
                options.SigningCertificate = new X509Certificate2(certfile, "password");
                options.IssuerUri          = Constants.IssuerURI;
                options.PublicOrigin       = Constants.UserProfileSTSOrigin;
                options.SiteName           = "Programme site";

                //kopplar in middlewaren i OWIN pipen
                idsrv.UseIdentityServer(options);
                Debug.Write(WebConfigurationManager.GetSection("system.webServer").ToString());
                Debug.Write("Andreas");
            });
        }
Beispiel #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddIdentityServer()
            .AddTestUsers(InMemory.GetUsers())
            .AddInMemoryClients(InMemory.GetClients())
            .AddInMemoryIdentityResources(InMemory.GetIdentityResources())
            .AddInMemoryApiResources(InMemory.GetApiResources())
            .AddDeveloperSigningCredential();

            services.AddMvc();
        }
Beispiel #3
0
        private static void SeedIdentityConfig(IServiceScope scope)
        {
            scope.ServiceProvider.GetRequiredService <PersistedGrantDbContext>()
            .Database.Migrate();

            var context = scope.ServiceProvider.GetRequiredService <ConfigurationDbContext>();

            context.Database.Migrate();

            if (!context.Clients.Any())
            {
                foreach (var client in InMemory.GetClients())
                {
                    context.Clients.Add(client.ToEntity());
                }

                context.SaveChanges();
            }

            if (!context.IdentityResources.Any())
            {
                foreach (var resource in InMemory.GetIdentityResources())
                {
                    context.IdentityResources.Add(resource.ToEntity());
                }

                context.SaveChanges();
            }

            if (!context.ApiResources.Any())
            {
                foreach (var resource in InMemory.GetApiResources())
                {
                    context.ApiResources.Add(resource.ToEntity());
                }

                context.SaveChanges();
            }

            if (!context.ApiScopes.Any())
            {
                foreach (var apiScope in InMemory.GetApiScopes())
                {
                    context.ApiScopes.Add(apiScope.ToEntity());
                }

                context.SaveChanges();
            }
        }
Beispiel #4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <MvcOptions>(options =>
            {
                options.Filters.Add(new RequireHttpsAttribute());
            });
            var idSrvConfig = Configuration.GetSection("IdSrv");

            services.AddIdentityServer()
            .AddTestUsers(InMemory.GetUsers(idSrvConfig))
            .AddInMemoryClients(InMemory.GetClients(idSrvConfig))
            .AddInMemoryIdentityResources(InMemory.GetIdentityResources())
            .AddInMemoryApiResources(InMemory.GetApiResources(idSrvConfig))
            .AddDeveloperSigningCredential();
            services.AddCors();
            services.AddMvc();
        }
Beispiel #5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            var assembly = typeof(Startup).Assembly.GetName().Name;
            var connectionString = _configuration.GetConnectionString("Default");

            services.AddDbContext<AppIdentityDbContext>(options =>
            {
                //options.UseSqlServer(connectionString);
                options.UseInMemoryDatabase("IdentityDB");
            });

            services.AddIdentity<IdentityUser, IdentityRole>(config =>
                {
                    config.Password.RequiredLength = 4;
                    config.Password.RequireDigit = false;
                    config.Password.RequireNonAlphanumeric = false;
                    config.Password.RequireUppercase = false;
                })
                .AddEntityFrameworkStores<AppIdentityDbContext>()
                .AddDefaultTokenProviders();

            services.ConfigureApplicationCookie(config =>
            {
                config.Cookie.Name = "IdentityServer.Cookie";
                config.LoginPath = "/Auth/Login";
                config.LogoutPath = "/Auth/Logout";
                config.AccessDeniedPath = "/Auth/AccessDenied";
            });


            services.AddIdentityServer()
                .AddAspNetIdentity<IdentityUser>()
                // this adds the operational data from DB (codes, tokens, consents)
                //.AddOperationalStore(options =>
                //{
                //    options.ConfigureDbContext = builder =>
                //        builder.UseSqlServer(connectionString, sql => sql.MigrationsAssembly(assembly));
                //    // this enables automatic token cleanup. this is optional.
                //    options.EnableTokenCleanup = true;
                //    options.TokenCleanupInterval = 30; // interval in seconds
                //})
                //.AddConfigurationStore(options =>
                //{
                //    options.ConfigureDbContext = builder =>
                //        builder.UseSqlServer(connectionString, sql => sql.MigrationsAssembly(assembly));
                //})
                .AddInMemoryIdentityResources(InMemory.GetIdentityResources())
                .AddInMemoryApiResources(InMemory.GetApiResources())
                .AddInMemoryClients(InMemory.GetClients())
                .AddInMemoryApiScopes(InMemory.GetApiScopes())
                .AddDeveloperSigningCredential(); 

            services.AddAuthorization();
            services.AddControllersWithViews();

            //services.AddCors(config =>
            //{
            //    config.AddPolicy("AllowAll", policy =>
            //    {
            //        policy.AllowAnyOrigin();
            //        policy.AllowAnyHeader();
            //        policy.AllowAnyMethod();
            //    });
            //});
        }