// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <HoyaConnectionDbContext>(options => options.UseNpgsql(Configuration.GetConnectionString("PostgresDocker"))); services.AddControllers(); services.AddScoped <IUserService, UserService>(); services.AddDefaultIdentity <HoyaConnectionUser>(options => { }).AddEntityFrameworkStores <HoyaConnectionDbContext>(); services.AddIdentityServer() .AddDeveloperSigningCredential() .AddApiAuthorization <HoyaConnectionUser, HoyaConnectionDbContext>(); services.AddAuthentication() .AddIdentityServerJwt(); var _loggerFactory = new LoggerFactory(); var cors = new DefaultCorsPolicyService(_loggerFactory.CreateLogger <DefaultCorsPolicyService>()) { AllowedOrigins = { "https://localhost:5001", "http://localhost:5000", "http://localhost:3000" } }; services.AddSingleton <ICorsPolicyService>(cors); //services.AddControllers(); }
public void ConfigureServices(IServiceCollection services) { // uncomment, if you want to add an MVC-based UI services.AddMvc().SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_1); var builder = services.AddIdentityServer() .AddInMemoryIdentityResources(Config.GetIdentityResources()) .AddInMemoryApiResources(Config.GetApis()) .AddInMemoryClients(Config.GetClients()) .AddTestUsers(Config.GetTestUsers()); if (Environment.IsDevelopment()) { builder.AddDeveloperSigningCredential(); } else { throw new Exception("need to configure key material"); } var cors = new DefaultCorsPolicyService(new LoggerFactory().CreateLogger <DefaultCorsPolicyService>()) { AllowAll = true }; services.AddSingleton <ICorsPolicyService>(cors); }
public void Configuration(IAppBuilder app) { app.Map("/identity", idsrvApp => { var corsPolicyService = new DefaultCorsPolicyService() { AllowAll = true }; var idServerServiceFactory = new IdentityServerServiceFactory() .UseInMemoryClients(Clients.Get()) .UseInMemoryScopes(Scopes.Get()) .UseInMemoryUsers(Users.Get()); idServerServiceFactory.CorsPolicyService = new Registration <IdentityServer3.Core.Services.ICorsPolicyService>(corsPolicyService); var options = new IdentityServerOptions { Factory = idServerServiceFactory, SiteName = "Notes Security Token Service", SigningCertificate = LoadCertificate(), IssuerUri = Constants.NotesIssuerUri, PublicOrigin = Constants.NotesStsOrigin }; idsrvApp.UseIdentityServer(options); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Add framework services. services.AddDbContext <ApplicationDbContext>(options => options.UseInMemoryDatabase()); services.AddIdentity <ApplicationUser, IdentityRole>() .AddEntityFrameworkStores <ApplicationDbContext>() .AddDefaultTokenProviders(); services.AddMvc(); // Add application services. services.AddTransient <IEmailSender, AuthMessageSender>(); services.AddTransient <ISmsSender, AuthMessageSender>(); var cors = new DefaultCorsPolicyService(null) { AllowAll = true }; services.AddSingleton <ICorsPolicyService>(cors); services.AddIdentityServer() .AddTemporarySigningCredential() .AddInMemoryPersistedGrants() .AddInMemoryIdentityResources(Config.GetIdentityResources()) .AddInMemoryApiResources(Config.GetApiResources()) .AddInMemoryClients(Config.GetClients()) .AddAspNetIdentity <ApplicationUser>(); }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddCors(); var cors = new DefaultCorsPolicyService(new Logger <DefaultCorsPolicyService>(new LoggerFactory())) { AllowAll = true }; services.AddSingleton <ICorsPolicyService>(cors); var connectionString = Configuration["ConnectionStrings:DBConnection"]; //Begin Identity Configuration services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer(connectionString)); services.AddIdentity <ApplicationUser, IdentityRole>() .AddEntityFrameworkStores <ApplicationDbContext>() .AddDefaultTokenProviders(); services.AddMvc(); services.AddIdentityServer() .AddDeveloperSigningCredential() .AddInMemoryApiResources(IdentityServerConfiguration.ApiResources()) .AddInMemoryClients(IdentityServerConfiguration.Clients()) .AddInMemoryIdentityResources(IdentityServerConfiguration.IdentityResources()) .AddTestUsers(TestUsers.GetUsers()); //End Identity Configuration var container = new WindsorContainer(); Bootstrapper.WireUp(container); UserManagementBootstrapper.Wireup(container, connectionString); var service = new WindsorServiceResolver(services, container).GetServiceProvider(); return(service); }
public static IdentityServerServiceFactory Configure() { var corsPolicyService = new DefaultCorsPolicyService() { AllowAll = true }; // var defaultViewServiceOptions = new DefaultViewServiceOptions(); // defaultViewServiceOptions.CacheViews = false; var idServerServiceFactory = new IdentityServerServiceFactory() .UseInMemoryClients(Clients.Get()) .UseInMemoryScopes(Scopes.Get()); // .UseInMemoryUsers(Users.Get()); idServerServiceFactory.CorsPolicyService = new Registration <IdentityServer3.Core.Services.ICorsPolicyService>(corsPolicyService); // idServerServiceFactory.ConfigureDefaultViewService(defaultViewServiceOptions); idServerServiceFactory.ViewService = new Registration <IViewService>(typeof(CustomViewService)); // use custom UserService //var customUserService = new CustomUserService(); // idServerServiceFactory.UserService = new Registration<IUserService>(resolver => customUserService); //idServerServiceFactory.Configure(connectionString); idServerServiceFactory.ConfigureUserService("AspId"); return(idServerServiceFactory); }
public void Configuration(IAppBuilder app) { app.Map("/identity", idsrvApp => { var corsPolicyService = new DefaultCorsPolicyService() { AllowAll = true }; var defaultViewServiceOptions = new DefaultViewServiceOptions(); defaultViewServiceOptions.CacheViews = false; var idServerServiceFactory = new IdentityServerServiceFactory() .UseInMemoryClients(Clients.Get()) .UseInMemoryScopes(Scopes.Get()); // .UseInMemoryUsers(Users.Get()); idServerServiceFactory.CorsPolicyService = new Registration <IdentityServer3.Core.Services.ICorsPolicyService>(corsPolicyService); idServerServiceFactory.ConfigureDefaultViewService(defaultViewServiceOptions); // use custom UserService var customUserService = new CustomUserService(); idServerServiceFactory.UserService = new Registration <IUserService>(resolver => customUserService); var options = new IdentityServerOptions { Factory = idServerServiceFactory, SiteName = "TripCompany Security Token Service", SigningCertificate = LoadCertificate(), IssuerUri = TripGallery.Constants.TripGalleryIssuerUri, PublicOrigin = TripGallery.Constants.TripGallerySTSOrigin, AuthenticationOptions = new AuthenticationOptions() { EnablePostSignOutAutoRedirect = true, LoginPageLinks = new List <LoginPageLink>() { new LoginPageLink() { Type = "createaccount", Text = "Create a new account", Href = "~/createuseraccount" } }, IdentityProviders = ConfigureAdditionalIdProviders }, CspOptions = new CspOptions() { Enabled = false // once available, leave Enabled at true and use: // FrameSrc = "https://localhost:44318 https://localhost:44316" // or // FrameSrc = "*" for all URI's. } }; idsrvApp.UseIdentityServer(options); }); }
public void InstallServices(IServiceCollection services, IConfiguration configuration) { services.AddIdentity <IdentityUser, IdentityRole>(config => { config.Password.RequireDigit = false; config.Password.RequireNonAlphanumeric = false; config.Password.RequireUppercase = false; config.Password.RequireLowercase = false; }) .AddEntityFrameworkStores <AppDbContext>() .AddDefaultTokenProviders(); services.ConfigureApplicationCookie(config => { config.Cookie.Name = "IdentityServer.Cookie"; }); services.AddIdentityServer() .AddAspNetIdentity <IdentityUser>() .AddInMemoryIdentityResources(Config.Ids) .AddInMemoryApiResources(Config.Apis) .AddInMemoryClients(Config.Clients) .AddDeveloperSigningCredential() .AddProfileService <ProfileService>(); services.AddLocalApiAuthentication(); var cors = new DefaultCorsPolicyService(new LoggerFactory().CreateLogger <DefaultCorsPolicyService>()) { AllowAll = true }; services.AddSingleton <ICorsPolicyService>(cors); }
/// <summary> /// Allow all CORS policy for Identity Server clients /// </summary> /// <param name="services"></param> /// <param name="loggerFactory"></param> /// <returns></returns> public static IServiceCollection AddIdentityServerCors(this IServiceCollection services, ILoggerFactory loggerFactory) { var cors = new DefaultCorsPolicyService(loggerFactory.CreateLogger <DefaultCorsPolicyService>()) { AllowAll = true }; services.AddSingleton <ICorsPolicyService>(cors); return(services); }
public void ConfigureServices(IServiceCollection services) { Microsoft.IdentityModel.Logging.IdentityModelEventSource.ShowPII = true; services.AddAuthentication() .AddGoogle("Google", options => { options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme; options.ClientId = "1032039370296-0a8p0eumo4pqet064m9g735beskfsfv1.apps.googleusercontent.com"; options.ClientSecret = "D2_moj6aTJ0cCIncyLa1sc5V"; }); services.AddCors(setup => { setup.AddDefaultPolicy(policy => { policy.AllowAnyHeader(); policy.AllowAnyMethod(); policy.WithOrigins("http://192.168.0.117:8080"); policy.AllowCredentials(); }); }); var builder = services.AddIdentityServer(options => { options.UserInteraction.LoginUrl = "http://192.168.0.117:8080/login.html"; options.UserInteraction.ErrorUrl = "http://192.168.0.117:8080/error.html"; options.UserInteraction.LogoutUrl = "http://192.168.0.117:8080/logout.html"; if (!string.IsNullOrEmpty(Configuration["Issuer"])) { options.IssuerUri = Configuration["Issuer"]; } }).AddInMemoryIdentityResources(Config.GetIdentityResources()) .AddInMemoryApiResources(Config.GetApis()) .AddInMemoryClients(Config.GetClients()) .AddTestUsers(Config.GetTestUsers()); builder.AddSigningCredential(new X509Certificate2(Path.Join(Environment.WebRootPath, "IdentityServer4Auth.pfx"), "ApnePassword")); //builder.AddCertificateFromFile(Configuration.GetSection("SigninKeyCredentials"), new LoggerFactory().CreateLogger<Startup>()); //builder.AddSigningCredential(new SigningCredentials(new RsaSecurityKey(new RSACryptoServiceProvider(2048)), SecurityAlgorithms.RsaSha256Signature)); var cors = new DefaultCorsPolicyService(new LoggerFactory().CreateLogger <DefaultCorsPolicyService>()) { AllowedOrigins = { "http://192.168.0.117:8080" }, AllowAll = true, }; services.AddControllers(); services.AddSingleton <ICorsPolicyService>(cors); services.AddTransient <IReturnUrlParser, ReturnUrlParser>(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name; services.Configure <CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddDbContext <UserDbContext>(options => options.UseNpgsql( Configuration.GetConnectionString("DatabaseConnection"))); services.AddIdentity <IdentityUser, IdentityRole>() .AddDefaultUI() .AddDefaultTokenProviders() .AddEntityFrameworkStores <UserDbContext>(); services.AddIdentityServer(options => { options.UserInteraction.LoginUrl = "/Identity/Account/Login"; options.UserInteraction.LogoutUrl = "/Identity/Account/Logout"; }) .AddDeveloperSigningCredential() .AddAspNetIdentity <IdentityUser>() // this adds the config data from DB (clients, resources) .AddConfigurationStore(options => { options.ConfigureDbContext = builder => builder.UseNpgsql(Configuration.GetConnectionString("DatabaseConnection"), sql => sql.MigrationsAssembly(migrationsAssembly)); }) // this adds the operational data from DB (codes, tokens, consents) .AddOperationalStore(options => { options.ConfigureDbContext = builder => builder.UseNpgsql(Configuration.GetConnectionString("DatabaseConnection"), sql => sql.MigrationsAssembly(migrationsAssembly)); // this enables automatic token cleanup. this is optional. options.EnableTokenCleanup = true; options.TokenCleanupInterval = 30; }); var cors = new DefaultCorsPolicyService(_loggerFactory.CreateLogger <DefaultCorsPolicyService>()) { AllowAll = true }; services.AddSingleton <ICorsPolicyService>(cors); services.AddTransient <IProfileService, ProfileService>(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); }
public void Configure(IApplicationBuilder app) { var settings = app.ApplicationServices.GetService <IOptions <AppSettings> >(); LogProvider.SetCurrentLogProvider(new DiagnosticsTraceLogProvider()); app.Map("/core", core => { var factory = InMemoryFactory.Create( users: Users.Get(), clients: Clients.Get(), scopes: Scopes.Get()); var cors = new DefaultCorsPolicyService { AllowAll = true }; factory.CorsPolicyService = new Registration <ICorsPolicyService>(cors); var idsrvOptions = new IdentityServerOptions { LoggingOptions = new LoggingOptions { IncludeSensitiveDataInLogs = true, //WebApiDiagnosticsIsVerbose = true, //EnableWebApiDiagnostics = true }, IssuerUri = settings.Options.IssuerUrl, SiteName = settings.Options.SiteTitle, Factory = factory, SigningCertificate = Certificate.Get(), RequireSsl = false, AuthenticationOptions = new AuthenticationOptions { } }; core.UseIdentityServer(idsrvOptions); }); app.Map("/api", api => { api.UseOAuthBearerAuthentication(options => { options.Authority = settings.Options.AuthorizationUrl; options.MetadataAddress = settings.Options.AuthorizationUrl + "/.well-known/openid-configuration"; options.TokenValidationParameters.ValidAudience = settings.Options.BaseUrl + "/resources"; }); // for web api api.UseMvc(); }); }
public void ConfigureServices(IServiceCollection services) { Microsoft.IdentityModel.Logging.IdentityModelEventSource.ShowPII = true; services.AddCors(setup => { setup.AddDefaultPolicy(policy => { policy.AllowAnyHeader(); policy.AllowAnyMethod(); policy.WithOrigins("http://localhost:8082", "http://localhost:8080"); policy.AllowCredentials(); }); }); services.AddMvcCore() .SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Latest); var builder = services.AddIdentityServer(options => { options.UserInteraction.LoginUrl = "http://localhost:8082/index.html"; options.UserInteraction.ErrorUrl = "http://localhost:8082/error.html"; options.UserInteraction.LogoutUrl = "http://localhost:8082/logout.html"; if (!string.IsNullOrEmpty(Configuration["Issuer"])) { options.IssuerUri = Configuration["Issuer"]; } }) .AddInMemoryIdentityResources(Config.GetIdentityResources()) .AddInMemoryApiResources(Config.GetApis()) .AddInMemoryClients(Config.GetClients()) .AddTestUsers(Config.GetTestUsers()); if (Environment.IsDevelopment()) { builder.AddDeveloperSigningCredential(); } else { throw new Exception("need to configure key material"); } var cors = new DefaultCorsPolicyService(new LoggerFactory().CreateLogger <DefaultCorsPolicyService>()) { AllowAll = true }; services.AddControllers(); services.AddSingleton <ICorsPolicyService>(cors); services.AddTransient <IReturnUrlParser, ReturnUrlParser>(); }
public void Configuration(IAppBuilder app) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .WriteTo.Trace() .CreateLogger(); AntiForgeryConfig.UniqueClaimTypeIdentifier = IdentityServer3.Core.Constants.ClaimTypes.Subject; JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary <string, string>(); app.Map("/identity", identityServer => { var corsPolicyService = new DefaultCorsPolicyService() { AllowAll = true }; var identityServerFactory = new IdentityServerServiceFactory() .UseInMemoryUsers(users: Users.Get()) .UseInMemoryClients(clients: Clients.Get()) .UseInMemoryScopes(scopes: Scopes.Get()); identityServerFactory.ClaimsProvider = new Registration <IClaimsProvider>(typeof(CustomClaimsProvider)); identityServerFactory.UserService = new Registration <IUserService>(typeof(CustomUserService)); identityServerFactory.CustomGrantValidators.Add( new Registration <ICustomGrantValidator>(typeof(CustomGrantValidator))); identityServerFactory.CorsPolicyService = new Registration <IdentityServer3.Core.Services.ICorsPolicyService>(corsPolicyService); var options = new IdentityServerOptions() { Factory = identityServerFactory, SiteName = "Patient Journey OAuth Identity Server", PublicOrigin = OAuthPJConstants.OAuthServerPublicOrigin, IssuerUri = OAuthPJConstants.OAuthServerURI, SigningCertificate = LoadCertificate(), RequireSsl = true, InputLengthRestrictions = new InputLengthRestrictions() { UserName = 10000, Password = 10000 } }; app.UseIdentityServer(options); }); }
public static IIdentityServerBuilder AddIdentityServerMongoDb( this IServiceCollection services, Action <IdentityServerOptions> identityServerOptions = null, Func <IServiceProvider, ICorsPolicyService> setupPolicy = null ) { var config = services.AddIdentityServerConfig(); services.TryAddTransient(typeof(IIdentityRepository <>), typeof(IdentityMongoRepository <>)); var provider = services.BuildServiceProvider(); var defaultPolicy = new DefaultCorsPolicyService(provider.GetService <ILogger <DefaultCorsPolicyService> >()) { AllowAll = true }; services.AddSingleton(setupPolicy?.Invoke(provider) ?? defaultPolicy); var builder = services .AddIdentityServer(options => { options.IssuerUri = config.Authority; var managementConfig = provider .GetRequiredService <IOptions <IdentityServerUserInteractionConfig> >() .Value; if (!string.IsNullOrWhiteSpace(managementConfig.UserInteractionEndpoints.LoginUrl)) { options.UserInteraction.LoginUrl = managementConfig.UserInteractionEndpoints.LoginUrl; } if (!string.IsNullOrWhiteSpace(managementConfig.UserInteractionEndpoints.LogoutUrl)) { options.UserInteraction.LogoutUrl = managementConfig.UserInteractionEndpoints.LogoutUrl; } options.UserInteraction.LoginReturnUrlParameter = "returnUrl"; identityServerOptions?.Invoke(options); options.Discovery.CustomEntries.Add("registration_endpoint", $"~{managementConfig.UserInteractionEndpoints.CreateUser}"); options.Discovery.CustomEntries.Add("login_endpoint", $"~{options.UserInteraction.LoginUrl}"); options.Discovery.CustomEntries.Add("logout_endpoint", $"~{options.UserInteraction.LogoutUrl}"); }) .AddMongoResources() .AddMongoClientStore() .AddMongoUserStore(); return(builder); }
public void ctor_UsesCorsPolicyCallback() { var wasCalled = false; var policy = new CorsPolicy(); Func <string, Task <bool> > func = s => { wasCalled = true; return(Task.FromResult(true)); }; policy.PolicyCallback = func; subject = new DefaultCorsPolicyService(policy); var result = subject.IsOriginAllowedAsync("http://foo").Result; result.Should().Be(true); wasCalled.Should().Be(true); }
public void ctor_CopiesCorsPolicyOrigins() { var policy = new CorsPolicy(); policy.AllowedOrigins.Add("http://foo"); policy.AllowedOrigins.Add("http://bar"); policy.AllowedOrigins.Add("http://baz"); Func <string, Task <bool> > func = s => Task.FromResult(true); policy.PolicyCallback = func; subject = new DefaultCorsPolicyService(policy); subject.AllowedOrigins.ShouldAllBeEquivalentTo(new string[] { "http://foo", "http://bar", "http://baz" }); }
public void ConfigureServices(IServiceCollection services) { var cors = new DefaultCorsPolicyService(new LoggerFactory().CreateLogger <DefaultCorsPolicyService>()) { AllowAll = true }; services.AddSingleton <ICorsPolicyService>(cors); var builder = services.AddIdentityServer() .AddInMemoryApiResources(Config.Apis) .AddInMemoryClients(Config.Clients) .AddTestUsers(Config.GetUsers()); builder.AddDeveloperSigningCredential(); }
public void Configuration(IAppBuilder app) { app.Map(string.Empty, idsrvApp => { Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .WriteTo.Trace() .CreateLogger(); var idServerServiceFactory = new IdentityServerServiceFactory() .UseInMemoryClients(Clients.Get()) .UseInMemoryScopes(Scopes.Get()) .UseInMemoryUsers(Users.Get()); var corsPolicyService = new DefaultCorsPolicyService() { AllowAll = true }; idServerServiceFactory.CorsPolicyService = new Registration <IdentityServer3.Core.Services.ICorsPolicyService>(corsPolicyService); var options = new IdentityServerOptions { Factory = idServerServiceFactory, SiteName = "Security Token Service", IssuerUri = IdentityConstants.IssuerUri, PublicOrigin = IdentityConstants.Origin, SigningCertificate = LoadCertificate(), AuthenticationOptions = new AuthenticationOptions { EnablePostSignOutAutoRedirect = true, PostSignOutAutoRedirectDelay = 5 }, LoggingOptions = new LoggingOptions() { WebApiDiagnosticsIsVerbose = true, EnableWebApiDiagnostics = true, EnableKatanaLogging = true, EnableHttpLogging = true } }; idsrvApp.UseIdentityServer(options); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var cors = new DefaultCorsPolicyService(LoggerFactory.CreateLogger <DefaultCorsPolicyService>()) { AllowAll = true }; services.AddSingleton <ICorsPolicyService>(cors); services.AddIdentityServer() .AddDeveloperSigningCredential(filename: "tempkey.rsa") .AddInMemoryApiResources(Config.GetApiResources()) .AddInMemoryIdentityResources(Config.GetIdentityResources()) .AddInMemoryClients(Config.GetClients(this.Configuration)) .AddTestUsers(Config.GetUsers()); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); var cors = new DefaultCorsPolicyService(_logger) { AllowAll = true }; services.AddSingleton <ICorsPolicyService>(cors); services.AddCors(options => { options.AddPolicy("CorsPolicy", builder => builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials()); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //services.AddCors(); var cors = new DefaultCorsPolicyService(_loggerFactory.CreateLogger <DefaultCorsPolicyService>()) { AllowedOrigins = { "*" } }; cors.AllowAll = true; services.AddSingleton <ICorsPolicyService>(cors); services.AddCors(); services.AddIdentityServer() .AddDeveloperSigningCredential() .AddInMemoryIdentityResources(Config.GetIdentityResources()) .AddInMemoryApiResources(Config.GetApis()) .AddInMemoryClients(Config.GetClients()); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); }
public static void ConfigureIdentityServer(this IServiceCollection services) { var serviceProvider = services.BuildServiceProvider(); var settings = serviceProvider.GetRequiredService <IOptions <IdentitySettings> >(); var config = new Config(settings.Value); services .AddIdentityServer() .AddDeveloperSigningCredential() .AddInMemoryIdentityResources(config.Ids) .AddInMemoryApiResources(config.Apis) .AddInMemoryClients(config.Clients); var cors = new DefaultCorsPolicyService(new LoggerFactory(new [] { new EventLogLoggerProvider() }).CreateLogger <DefaultCorsPolicyService>()) { AllowAll = true }; services.AddSingleton <ICorsPolicyService>(cors); services.AddTransient <IResourceOwnerPasswordValidator, ResourceOwnerPasswordValidator>(); services.AddTransient <IProfileService, ProfileService>(); services .AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme) .AddIdentityServerAuthentication(options => { options.JwtBearerEvents = new JwtBearerEvents { OnChallenge = context => { context.Response.StatusCode = 401; return(Task.CompletedTask); }, }; options.Authority = settings.Value.Authority; options.ApiName = settings.Value.Audience; options.RequireHttpsMetadata = false; }); }
private void ConfigureSecurity(IServiceCollection services) { var identityServer = services.AddIdentityServer(options => { // Use ONLY for developing! Never use this in production. Never. options.RequireSsl = false; options.IssuerUri = "http://localhost:5001/"; options.SigningCertificate = _certificate; }); identityServer.AddInMemoryClients(Clients.Get()); identityServer.AddInMemoryScopes(Scopes.Get()); identityServer.AddInMemoryUsers(Users.Get()); // Enable CORS on identity server identityServer.Services.AddTransient <ICorsPolicyService>(p => { var corsService = new DefaultCorsPolicyService(p.GetRequiredService <ILogger <DefaultCorsPolicyService> >()); corsService.AllowAll = true; return(corsService); }); }
public void Configuration(IAppBuilder app) { app.Map("/identity", idsrvApp => { var corsPolicyService = new DefaultCorsPolicyService { AllowAll = true }; var idServerServiceFactory = new IdentityServerServiceFactory { CorsPolicyService = new Registration <ICorsPolicyService>(corsPolicyService) } .UseInMemoryClients(Clients.Get()) .UseInMemoryScopes(Scopes.Get()) .UseInMemoryUsers(Users.Get()); idServerServiceFactory.ConfigureDefaultViewService( new DefaultViewServiceOptions { CacheViews = false }); idsrvApp.UseIdentityServer(new IdentityServerOptions { SiteName = "WsFederationDemo", SigningCertificate = LoadCertificate(), RequireSsl = false, Factory = idServerServiceFactory, AuthenticationOptions = new AuthenticationOptions { RememberLastUsername = true, IdentityProviders = ConfigureAdditionalIdProviders }, EnableWelcomePage = false, CspOptions = new CspOptions { Enabled = false } }); }); }
public void ConfigureServices(IServiceCollection services) { services.AddAutoMapper(typeof(RegisterIn).Assembly); var connectionString = Configuration.GetConnectionString("identity"); services .AddSingleton(i => new IdentityContext(connectionString)) .AddScoped <IIdentityRepository, IdentityRepository>() .AddScoped <IRegisterService, RegisterService>(); services .AddScoped <IResourceOwnerPasswordValidator, PasswordValidator>() .AddScoped <IProfileService, ProfileService>(); services .AddIdentityServer(o => { o.Authentication.CookieLifetime = new TimeSpan(360, 0, 0, 0); o.Authentication.CookieSlidingExpiration = false; }) .AddDeveloperSigningCredential() .AddInMemoryApiResources(Config.GetApis()) .AddInMemoryIdentityResources(Config.GetIdentityResources()) .AddInMemoryClients(Config.GetClients()) .Services.AddTransient <ICorsPolicyService>(p => { var corsService = new DefaultCorsPolicyService( p.GetRequiredService <ILogger <DefaultCorsPolicyService> >() ); corsService.AllowAll = true; return(corsService); }); services .AddBasicServices() .AddSwagger(SwaggerTitle); AddAuthentication(services); }
// 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.AddMvc(); services.Configure<IISOptions>(options => { options.AutomaticAuthentication = false; options.AuthenticationDisplayName = "Windows"; options.ForwardClientCertificate = false; }); var connectionString = Configuration["connectionStrings:IdentityServerData"]; string assembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name; services.AddIdentityServer() .AddDeveloperSigningCredential() .AddConfigurationStore(options => { options.ConfigureDbContext = builder => builder.UseSqlServer(connectionString, sql => sql.MigrationsAssembly(assembly)); }) .AddOperationalStore(options => { options.ConfigureDbContext = builder => builder.UseSqlServer(connectionString, sql => sql.MigrationsAssembly(assembly)); }); var cors = new DefaultCorsPolicyService(LoggerFactory.CreateLogger<DefaultCorsPolicyService>()) { AllowedOrigins = { "https://foo", "https://bar" } }; services.AddSingleton<ICorsPolicyService>(cors); }
public void ConfigureServices(IServiceCollection services) { string BDTConnection = configuraton.GetConnectionString("BDTConnection"); services.AddDbContext <BDTContext>(options => options.UseSqlServer(BDTConnection)); services.AddTransient <DbContext, BDTContext>(); ILoggerFactory _loggerFactory = new LoggerFactory(); var cors = new DefaultCorsPolicyService(_loggerFactory.CreateLogger <DefaultCorsPolicyService>()) { AllowedOrigins = { "http://127.0.0.1:5500" } }; services.AddSingleton <ICorsPolicyService>(cors); services.AddSession(options => options.Cookie.SameSite = SameSiteMode.None); string identityConnection = configuraton.GetConnectionString("IdentityConnection"); var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name; services.AddMvc(); services.AddDbContext <ApplicationDbContext>(builder => builder.UseSqlServer(identityConnection, sqlOptions => sqlOptions.MigrationsAssembly(migrationsAssembly))); services .AddIdentityServer() .AddConfigurationStore(options => options.ConfigureDbContext = builder => builder.UseSqlServer(identityConnection, sqlOptions => sqlOptions.MigrationsAssembly(migrationsAssembly))) .AddDeveloperSigningCredential() .AddOperationalStore(options => options.ConfigureDbContext = builder => builder.UseSqlServer(identityConnection, sqlOptions => sqlOptions.MigrationsAssembly(migrationsAssembly))) .AddCustomUserStore(); }
public DefaultCorsPolicyServiceTests() { subject = new DefaultCorsPolicyService(TestLogger.Create<DefaultCorsPolicyService>()); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { BuildConfig(); services.AddDbContext <AppIdentityDbContext>(options => options.UseSqlServer(Configuration["DB:CONNECTION"])); /* We'll play with this down the road... * services.AddAuthentication() * .AddGoogle("Google", options => * { * options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme; * * options.ClientId = "<insert here>"; * options.ClientSecret = "<insert here>"; * });*/ services.AddTransient <IProfileService, IdentityClaimsProfileService>(); services.AddCors(options => { options.AddPolicy("AllowSpecificOrigin", builder => builder .WithOrigins("http://localhost:4200", "https://my.it108.org") .AllowAnyHeader() .AllowAnyMethod() .AllowCredentials() ); }); services.AddIdentity <AppUser, IdentityRole>() .AddEntityFrameworkStores <AppIdentityDbContext>() .AddDefaultTokenProviders(); var authority = "https://auth.it108.org"; services.AddIdentityServer(options => { options.IssuerUri = authority; options.PublicOrigin = authority; }) .AddDeveloperSigningCredential() .AddTestUsers(TestUsers.Users) // this adds the operational data from DB (codes, tokens, consents) .AddOperationalStore(options => { options.ConfigureDbContext = builder => builder.UseSqlServer(Configuration["DB:CONNECTION"]); // this enables automatic token cleanup. this is optional. options.EnableTokenCleanup = true; options.TokenCleanupInterval = 30; // interval in seconds }) //.AddInMemoryPersistedGrants() .AddInMemoryIdentityResources(Config.GetIdentityResources()) .AddInMemoryApiResources(Config.GetApiResources()) .AddInMemoryClients(Config.GetClients()) .AddAspNetIdentity <AppUser>(); var cors = new DefaultCorsPolicyService(new LoggerFactory().CreateLogger <DefaultCorsPolicyService>()) { AllowAll = true }; services.AddSingleton <ICorsPolicyService>(cors); services.AddCors(options => options.AddDefaultPolicy(p => p.AllowAnyOrigin() .AllowAnyHeader() .AllowAnyMethod())); services.AddMvc(options => { options.EnableEndpointRouting = false; }).SetCompatibilityVersion(CompatibilityVersion.Latest); }