Exemple #1
0
 public CompiledPageRouteModelProvider(Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager applicationManager, Microsoft.Extensions.Options.IOptions <Microsoft.AspNetCore.Mvc.RazorPages.RazorPagesOptions> pagesOptionsAccessor, Microsoft.Extensions.Logging.ILogger <Microsoft.AspNetCore.Mvc.ApplicationModels.CompiledPageRouteModelProvider> logger)
 {
 }
 public DefaultViewCompilerProvider(Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager applicationPartManager, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory)
 {
 }
Exemple #3
0
 protected virtual Microsoft.AspNetCore.Mvc.Razor.Compilation.ViewsFeature GetViewFeature(Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager applicationManager)
 {
     throw null;
 }
Exemple #4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            // Work around for https://github.com/aspnet/Home/issues/3132
            var manager = new Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager();

            manager.ApplicationParts.Add(new Microsoft.AspNetCore.Mvc.ApplicationParts.AssemblyPart(typeof(Startup).Assembly));
            services.AddSingleton(manager);

            services.AddDbContext <ImperaContext>(options =>
            {
                string connection = Configuration["DBConnection"];

                if (!Startup.RunningUnderTest)
                {
                    options.UseSqlServer(connection,
                                         b => b
                                         .MigrationsAssembly("ImperaPlus.Web")
                                         .EnableRetryOnFailure());
                }

                options.UseOpenIddict();
            });

            services.AddCors(opts =>
            {
                var policy = new CorsPolicy()
                {
                    SupportsCredentials = false
                };

                policy.ExposedHeaders.Add("X-MiniProfiler-Ids");
                policy.Headers.Add("X-MiniProfiler-Ids");

                opts.AddPolicy(
                    opts.DefaultPolicyName,
                    policy);
            });

            // Auth
            services.AddIdentity <Domain.User, IdentityRole>(options =>
            {
                options.User.RequireUniqueEmail = true;

                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireUppercase       = false;
                options.Password.RequireDigit           = false;

                options.SignIn.RequireConfirmedEmail       = true;
                options.SignIn.RequireConfirmedPhoneNumber = false;

                if (this.Environment.IsDevelopment())
                {
                    options.SignIn.RequireConfirmedEmail = false;
                }

                // Ensure that we never redirect when user is not authorized, but only return 401 response
                // TODO: Fix for admin flow
                //options.Cookies.ApplicationCookie.AutomaticAuthenticate = false;
                //options.Cookies.ApplicationCookie.AutomaticChallenge = false;
                //options.Cookies.ApplicationCookie.Events = new Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationEvents
                //{
                //    OnRedirectToLogin = ctx =>
                //    {
                //        ctx.Response.StatusCode = (int)System.Net.HttpStatusCode.Unauthorized;
                //        return Task.CompletedTask;
                //    },

                //    OnValidatePrincipal = ctx =>
                //    {
                //        return Task.CompletedTask;
                //    }
                //};

                options.ClaimsIdentity.UserNameClaimType = OpenIdConnectConstants.Claims.Name;
                options.ClaimsIdentity.UserIdClaimType   = OpenIdConnectConstants.Claims.Subject;
                options.ClaimsIdentity.RoleClaimType     = OpenIdConnectConstants.Claims.Role;
            })
            .AddEntityFrameworkStores <ImperaContext>()
            .AddDefaultTokenProviders();

            services
            .AddOpenIddict(options =>
            {
                options.AddCore(x =>
                {
                    x.UseEntityFrameworkCore(c => c.UseDbContext <ImperaContext>());
                });

                options.AddServer(c =>
                {
                    if (this.Environment.IsDevelopment())
                    {
                        c.DisableHttpsRequirement();
                        c.AddEphemeralSigningKey();
                    }

                    c.AllowPasswordFlow();
                    c.AllowRefreshTokenFlow();
                    c.EnableTokenEndpoint("/Account/Token");

                    c.RegisterScopes(OpenIddictConstants.Scopes.Roles);

                    c.AcceptAnonymousClients();
                });

                // TODO: FIX: Is this still required?
                // options.AddMvcBinders();
            });

            services.AddAuthentication().AddOAuthValidation(config =>
            {
                config.Events = new AspNet.Security.OAuth.Validation.OAuthValidationEvents
                {
                    // Note: for SignalR connections, the default Authorization header does not work,
                    // because the WebSockets JS API doesn't allow setting custom parameters.
                    // To work around this limitation, the access token is retrieved from the query string.
                    OnRetrieveToken = context =>
                    {
                        context.Token = context.Request.Query["access_token"];
                        return(Task.CompletedTask);
                    }
                };
            });

            services.AddResponseCompression(options =>
            {
                options.Providers.Add <GzipCompressionProvider>();
            });

            services.AddMvc(config =>
            {
                config.EnableEndpointRouting = false;
                config.Filters.Add(new CheckModelForNull());
                config.Filters.Add(typeof(ApiExceptionFilterAttribute));
            })
            .AddNewtonsoftJson(opt =>
            {
                opt.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
                opt.SerializerSettings.DateFormatHandling   = DateFormatHandling.IsoDateFormat;
                opt.SerializerSettings.Converters.Add(new StringEnumConverter
                {
                    CamelCaseText      = false,
                    AllowIntegerValues = true
                });
                opt.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
            });

            services
            .AddMiniProfiler(config =>
            {
                (config.Storage as MemoryCacheStorage).CacheDuration = TimeSpan.FromMinutes(60);

                config.RouteBasePath = "/admin/profiler";
            })
            .AddEntityFramework();

            services.AddMemoryCache();

            // DataTables for the admin interface
            services.RegisterDataTables();

            // Set default authorization policy
            services.AddAuthorization(o =>
            {
                var builder = new AuthorizationPolicyBuilder();
                builder.AuthenticationSchemes.Add(AspNet.Security.OAuth.Validation.OAuthValidationDefaults.AuthenticationScheme);
                builder.RequireAuthenticatedUser();
                o.DefaultPolicy = builder.Build();
            });

            // Hangire
            services.AddHangfire(x =>
            {
                x.UseNLogLogProvider()
                .UseFilter(new JobExpirationTimeAttribute())
                .UseConsole();

                if (Startup.RunningUnderTest)
                {
                    x.UseMemoryStorage();
                }
                else
                {
                    x.UseSqlServerStorage(Configuration["DBConnection"]);
                }
            });

            services.AddSingleton(_ => new JsonSerializer
            {
                DateTimeZoneHandling = DateTimeZoneHandling.Utc,
                DateFormatHandling   = DateFormatHandling.IsoDateFormat
            });

            services
            .AddSignalR(options =>
            {
                options.EnableDetailedErrors = true;
            })
            .AddNewtonsoftJsonProtocol(options =>
            {
                options.PayloadSerializerSettings.ContractResolver     = new CamelCasePropertyNamesContractResolver();
                options.PayloadSerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
                options.PayloadSerializerSettings.DateFormatHandling   = DateFormatHandling.IsoDateFormat;
            });

            // Have SignalR use the name claim as user id
            services.AddSingleton <IUserIdProvider, NameUserIdProvider>();

            services.AddOpenApiDocument();

            return(this.RegisterDependencies(services));
        }