public void Build(IApplicationBuilder app, CloudyAdminOptions options)
        {
            if (options.StaticFilesFileProvider != null)
            {
                app.UseStaticFiles(new StaticFileOptions
                {
                    RequestPath       = "/files",
                    FileProvider      = options.StaticFilesFileProvider,
                    OnPrepareResponse = context => context.Context.Response.Headers["Cache-Control"] = "no-cache"
                });
                ((StaticFilesBasePathProvider)app.ApplicationServices.GetRequiredService <IStaticFilesBasePathProvider>()).StaticFilesBasePath = "./files";
            }
            else
            {
                ((StaticFilesBasePathProvider)app.ApplicationServices.GetRequiredService <IStaticFilesBasePathProvider>()).StaticFilesBasePath = options.StaticFilesBaseUri;
            }

            app.UseRouting();
            app.UseAuthentication();

            if (options.AuthorizeOptions != null)
            {
                if (app.ApplicationServices.GetService <IAuthorizationService>() == null)
                {
                    throw new Exception($"Could not find {nameof(IAuthorizationService)} in DI container. Call services.{nameof(PolicyServiceCollectionExtensions.AddAuthorization)}() in ConfigureServices");
                }

                app.Map(new PathString("/Login"), branch => app.ApplicationServices.GetService <ILoginPipelineBuilder>().Build(branch, options));

                var policy =
                    options.AuthorizeOptions != null?
                    AuthorizationPolicy.CombineAsync(app.ApplicationServices.GetRequiredService <IAuthorizationPolicyProvider>(), new List <IAuthorizeData> {
                    options.AuthorizeOptions
                }).Result:
                    new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build();

                app.UseMiddleware <AuthorizeMiddleware>(policy);
            }

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapGet("/", async context =>
                {
                    if (!PathEndsInSlash(context.Request.Path))
                    {
                        RedirectToPathWithSlash(context);
                        return;
                    }

                    await context.RequestServices.GetRequiredService <IPortalPageRenderer>().RenderPageAsync(context);
                });
                endpoints.MapAreaControllerRoute(null, "Cloudy.CMS", "{controller}/{action}");
            });
        }
 public CloudyAdminConfigurator(CloudyAdminOptions options)
 {
     Options = options;
 }