protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); var remoteRazorLocationStore = new RemoteRazorLocationStore(); remoteRazorLocationStore.LoadRemoteDataAsync("https://rawgit.com/ghstahl/asset-repo/master/aspnet-mvc5/views.json").GetAwaiter().GetResult(); HostingEnvironment.RegisterVirtualPathProvider(new ViewPathProvider(remoteRazorLocationStore)); var remoteStaticExternalSpaStore = new RemoteStaticExternalSpaStore( "https://rawgit.com/ghstahl/asset-repo/master/aspnet-mvc5/external.spa.config.json"); var records = remoteStaticExternalSpaStore.GetRemoteDataAsync().GetAwaiter().GetResult(); foreach (var spa in records.Spas) { remoteStaticExternalSpaStore.AddRecord(spa); } var builder = new ContainerBuilder(); builder.RegisterControllers(typeof(MvcApplication).Assembly); builder.RegisterInstance(remoteStaticExternalSpaStore).As <IExternalSpaStore>(); var container = builder.Build(); DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); }
public async Task Invoke(CancellationToken cancellationToken) { var appConfig = new ExternalUrlsOptions(); _config.GetSection("externalViews").Bind(appConfig); var urlViewSchema = await RemoteJsonFetch.GetRemoteJsonContentAsync(appConfig.UrlViewSchema); var remoteViewUrls = await GetRemoteUrlsAsync(appConfig.Urls, true); foreach (var url in remoteViewUrls.Urls) { await RemoteRazorLocationStore.LoadRemoteDataAsync(url, urlViewSchema); } }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddIdentityServer() .AddDeveloperSigningCredential() .AddExtensionGrantValidator <PublicRefreshTokenExtensionGrantValidator>();; // needed to store rate limit counters and ip rules services.AddMemoryCache(); ConfigureRateLimitingServices(services); services.TryAddSingleton(typeof(IStringLocalizerFactory), typeof(ResourceManagerStringLocalizerFactory)); services.AddLocalization(); var inMemoryStore = new InMemoryStore <ApplicationUser, ApplicationRole>(); services.AddSingleton <IUserStore <ApplicationUser> >(provider => { return(inMemoryStore); }); services.AddSingleton <IUserRoleStore <ApplicationUser> >(provider => { return(inMemoryStore); }); services.AddSingleton <IRoleStore <ApplicationRole> >(provider => { return(inMemoryStore); }); services.AddIdentity <ApplicationUser, ApplicationRole>() .AddDefaultTokenProviders() .AddIdentityServer(); services.AddAuthentication <ApplicationUser>(Configuration); services .AddScoped <Microsoft.AspNetCore.Identity.IUserClaimsPrincipalFactory <ApplicationUser>, AppClaimsPrincipalFactory <ApplicationUser, ApplicationRole> >(); // Add application services. services.AddTransient <IEmailSender, EmailSender>(); services.AddAntiforgery(opts => opts.HeaderName = "X-XSRF-Token"); services.AddMyHealthCheck(Configuration); services.AddMvc(opts => { opts.Filters.AddService(typeof(AngularAntiforgeryCookieResultFilter)); }).AddJsonOptions(options => { options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); }); services.AddTransient <AngularAntiforgeryCookieResultFilter>(); var razorLocationStore = new RemoteRazorLocationStore(); services.AddSingleton <IRemoteRazorLocationStore>(razorLocationStore); services.AddSingleton <IRazorLocationStore>(razorLocationStore); services.AddSingleton <RemoteRazorLocationStore>(razorLocationStore); services.Configure <RazorViewEngineOptions>(opts => opts.FileProviders.Add( new RazorFileProvider(razorLocationStore) ) ); services.AddAuthorization(); services.AddLogging(); services.AddWebEncoders(); services.AddCors(options => { options.AddPolicy("CorsPolicy", builder => builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials()); }); services.AddDistributedMemoryCache(); services.AddSession(); services.AddTransient <ClaimsPrincipal>( s => s.GetService <IHttpContextAccessor>().HttpContext.User); services.AddAllConfigureServicesRegistrants(Configuration); services.AddDependenciesUsingAutofacModules(); services.AddScheduler((sender, args) => { Console.Write(args.Exception.Message); args.SetObserved(); }); var serviceProvider = services.BuildServiceProvider(Configuration); P7.Core.Global.ServiceProvider = serviceProvider; return(serviceProvider); }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { // https://identityserver4.readthedocs.io/en/release/quickstarts/0_overview.html // NOTE: AddTemporarySigningCredential generates new signing keys on restart, so access_tokens only work for the life of the app. var identityServerBuilder = services.AddIdentityServer() .AddTemporarySigningCredential() .AddSecretParser <ClientAssertionSecretParser>() .AddSecretValidator <PrivateKeyJwtSecretValidator>() .AddExtensionGrantValidator <PublicRefreshTokenExtensionGrantValidator>(); // .AddEndpoint<CustomTokenEndpoint>(EndpointName.Token); services.TryAddSingleton(typeof(IStringLocalizerFactory), typeof(ResourceManagerStringLocalizerFactory)); services.AddLocalization(); // Add framework services. services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services.AddIdentity <ApplicationUser, IdentityRole>() .AddEntityFrameworkStores <ApplicationDbContext>() .AddDefaultTokenProviders(); services .AddScoped <Microsoft.AspNetCore.Identity.IUserClaimsPrincipalFactory <ApplicationUser>, AppClaimsPrincipalFactory <ApplicationUser> >(); services.AddAntiforgery(opts => opts.HeaderName = "X-XSRF-Token"); services.AddMvc(opts => { opts.Filters.AddService(typeof(AngularAntiforgeryCookieResultFilter)); }).AddJsonOptions(options => { options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); }); services.AddTransient <AngularAntiforgeryCookieResultFilter>(); var razorLocationStore = new RemoteRazorLocationStore(); services.AddSingleton <IRazorLocationStore>(razorLocationStore); services.AddSingleton <RemoteRazorLocationStore>(razorLocationStore); services.Configure <RazorViewEngineOptions>(opts => opts.FileProviders.Add( new RazorFileProvider(razorLocationStore) ) ); services.AddAuthorization(); // Add application services. services.AddTransient <IEmailSender, AuthMessageSender>(); services.AddTransient <ISmsSender, AuthMessageSender>(); services.AddLogging(); services.AddWebEncoders(); services.AddCors(); services.AddDistributedMemoryCache(); services.AddSession(); services.AddTransient <ClaimsPrincipal>( s => s.GetService <IHttpContextAccessor>().HttpContext.User); // AutomaticChallenge = false, we own the logic via our filters what happens with the redirect // this is neccesary for the api work where we simply want to return a 401 and not get redirected to login services.Configure <IdentityOptions>(options => { options.Cookies.ApplicationCookie.LoginPath = new Microsoft.AspNetCore.Http.PathString("/Identity/Account/Login"); options.Cookies.ApplicationCookie.LogoutPath = new Microsoft.AspNetCore.Http.PathString("/Identity/Account/LogOff"); options.Cookies.ApplicationCookie.AutomaticChallenge = false; }); services.AddAllConfigureServicesRegistrants(Configuration); services.AddDependenciesUsingAutofacModules(); var serviceProvider = services.BuildServiceProvider(Configuration); P7.Core.Global.ServiceProvider = serviceProvider; return(serviceProvider); }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { // needed to store rate limit counters and ip rules services.AddMemoryCache(); ConfigureRateLimitingServices(services); services.TryAddSingleton(typeof(IStringLocalizerFactory), typeof(ResourceManagerStringLocalizerFactory)); services.AddLocalization(); var authenticationOptions = new ReferenceWebApp.Models.AuthenticationOptions(); Configuration.GetSection("authentication").Bind(authenticationOptions); // Add application services. services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(o => { o.Authority = authenticationOptions.JwtBearer.Authority; o.Audience = authenticationOptions.JwtBearer.Audience; o.RequireHttpsMetadata = authenticationOptions.JwtBearer.RequireHttpsMetadata; o.SaveToken = authenticationOptions.JwtBearer.SaveToken; }); services.AddAntiforgery(opts => opts.HeaderName = "X-XSRF-Token"); services.AddMyHealthCheck(Configuration); services.AddCors(options => { options.AddPolicy("CorsPolicy", builder => builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials()); }); services.AddMvc(opts => { opts.Filters.AddService(typeof(AngularAntiforgeryCookieResultFilter)); }).AddJsonOptions(options => { options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); }); services.AddTransient <AngularAntiforgeryCookieResultFilter>(); var razorLocationStore = new RemoteRazorLocationStore(); services.AddSingleton <IRemoteRazorLocationStore>(razorLocationStore); services.AddSingleton <IRazorLocationStore>(razorLocationStore); services.AddSingleton <RemoteRazorLocationStore>(razorLocationStore); services.Configure <RazorViewEngineOptions>(opts => opts.FileProviders.Add( new RazorFileProvider(razorLocationStore) ) ); services.AddAuthorization(); services.AddLogging(); services.AddWebEncoders(); services.AddDistributedMemoryCache(); services.AddSession(); services.AddTransient <ClaimsPrincipal>( s => s.GetService <IHttpContextAccessor>().HttpContext.User); services.AddAllConfigureServicesRegistrants(Configuration); services.AddDependenciesUsingAutofacModules(); services.AddScheduler((sender, args) => { Console.Write(args.Exception.Message); args.SetObserved(); }); var serviceProvider = services.BuildServiceProvider(Configuration); P7.Core.Global.ServiceProvider = serviceProvider; return(serviceProvider); }