Beispiel #1
0
        /// <summary>
        /// Configure ServiceStack Authentication plugin.
        /// </summary>
        /// <param name="container">The container.</param>
        private void ConfigureAuth(Container container)
        {
            Plugins.Add(new AuthFeature(() => new AuthUserSession(),
                                        new IAuthProvider[]
            {
                new CredentialsAuthProvider(AppSettings),
                new JwtAuthProvider(AppSettings)
                {
                    AuthKey = Convert.FromBase64String("3n/aJNQHPx0cLu/2dN3jWf0GSYL35QlMqgz+LH3hUyA="),
                    RequireSecureConnection = false,
                },
                new ApiKeyAuthProvider(AppSettings),
                new BasicAuthProvider(AppSettings),
            }));

            Plugins.Add(new RegistrationFeature());

            var authRepo = new OrmLiteAuthRepository(container.Resolve <IDbConnectionFactory>());

            container.Register <IAuthRepository>(c => authRepo);
            authRepo.InitSchema();

            authRepo.CreateUserAuth(new UserAuth
            {
                UserName    = "******",
                DisplayName = "Credentials",
                FirstName   = "First",
                LastName    = "Last",
                FullName    = "First Last",
            }, "test");
        }
        /// <summary>
        /// Configure ServiceStack Authentication plugin.
        /// </summary>
        /// <param name="container">The container.</param>
        private void ConfigureAuth(Container container)
        {
            Plugins.Add(new AuthFeature(() => new AuthUserSession(),
                                        new IAuthProvider[]
            {
                new CredentialsAuthProvider(AppSettings),
                new ApiKeyAuthProvider(AppSettings),
                new BasicAuthProvider(AppSettings),
            }));

            Plugins.Add(new RegistrationFeature());

            var authRepo = new OrmLiteAuthRepository(container.Resolve <IDbConnectionFactory>());

            container.Register <IAuthRepository>(c => authRepo);
            authRepo.InitSchema();

            authRepo.CreateUserAuth(new UserAuth
            {
                UserName    = "******",
                DisplayName = "Credentials",
                FirstName   = "First",
                LastName    = "Last",
                FullName    = "First Last",
            }, "test");
        }
Beispiel #3
0
    public override void Configure(Container container)
    {
        container.Register <IDbConnectionFactory>(new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider));
        var dbFactory = container.Resolve <IDbConnectionFactory>();

        this.Plugins.Add(new AuthFeature(() => new CustomUserSession(), new IAuthProvider[]
        {
            new TwitterAuthProvider(this.AppSettings),
            new GithubAuthProvider(this.AppSettings),
            new CredentialsAuthProvider(),
        }));

        var authRepo = new OrmLiteAuthRepository <CustomUserAuth, UserAuthDetails>(dbFactory);

        container.Register <IUserAuthRepository>(authRepo);
        authRepo.InitSchema();

        container.RegisterAs <OrmLiteCacheClient, ICacheClient>();
        container.Resolve <ICacheClient>().InitSchema();

        using (var db = dbFactory.OpenDbConnection())
        {
            db.CreateTableIfNotExists <TechnologyStack>();
            db.CreateTableIfNotExists <Technology>();
            db.CreateTableIfNotExists <TechnologyChoice>();
            db.CreateTableIfNotExists <UserFavoriteTechnologyStack>();
            db.CreateTableIfNotExists <UserFavoriteTechnology>();
        }

        this.Plugins.Add(new AutoQueryFeature {
            MaxLimit = 1000
        });
    }
        public override IUserAuthRepository CreateAuthRepo()
        {
            var dbFactory  = new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider);
            var sqliteRepo = new OrmLiteAuthRepository(dbFactory);

            sqliteRepo.InitSchema();
            InitTest(sqliteRepo);
            return(sqliteRepo);
        }
Beispiel #5
0
        public override IUserAuthRepository CreateAuthRepo()
        {
            var connStr          = @"Data Source=.\SQLEXPRESS;database=test;Integrated Security=True;";
            var sqlServerFactory = new OrmLiteConnectionFactory(connStr, SqlServerDialect.Provider);
            var sqlServerRepo    = new OrmLiteAuthRepository(sqlServerFactory);

            sqlServerRepo.InitSchema();
            InitTest(sqlServerRepo);
            return(sqlServerRepo);
        }
Beispiel #6
0
        public override IUserAuthRepository CreateAuthRepo()
        {
            var connStr          = @"Server=localhost;Database=test;User Id=test;Password=test;";
            var sqlServerFactory = new OrmLiteConnectionFactory(connStr, SqlServerDialect.Provider);
            var sqlServerRepo    = new OrmLiteAuthRepository(sqlServerFactory);

            sqlServerRepo.InitSchema();
            InitTest(sqlServerRepo);
            return(sqlServerRepo);
        }
Beispiel #7
0
        public override IUserAuthRepository CreateAuthRepo()
        {
            var sqlServerFactory = new OrmLiteConnectionFactory(
                TestsConfig.SqlServerConnString,
                SqlServerDialect.Provider);
            var sqlServerRepo = new OrmLiteAuthRepository(sqlServerFactory);

            sqlServerRepo.InitSchema();
            InitTest(sqlServerRepo);
            return(sqlServerRepo);
        }
Beispiel #8
0
        public void Register(IAppHost appHost)
        {
            //Pre init process

            // Dependency
            var container   = appHost.GetContainer();
            var appSettings = appHost.AppSettings;

            //Register all Authentication methods you want to enable for this web app.
            appHost.Plugins.Add(new AuthFeature(() => new AuthUserSession(),
                                                new IAuthProvider[] {
                new ApiKeyAuthProvider(appSettings),
                new CredentialsAuthProvider()
                {
                    SessionExpiry = new TimeSpan(0, 30, 0)
                },                  //Sign-in with UserName/Password credentials
                new BasicAuthProvider()
                {
                    SessionExpiry = new TimeSpan(0, 30, 0)
                },                        //Sign-in with HTTP Basic Auth
            }
                                                )
            {
                IncludeAssignRoleServices = true,
                MaxLoginAttempts          = 5,
                ServiceRoutes             = new Dictionary <Type, string[]> {
                    { typeof(AuthenticateService), new[] { "/auth", "/auth/{provider}" } },
                },
                GenerateNewSessionCookiesOnAuthentication = true,
                DeleteSessionCookiesOnLogout = true,
                IncludeAuthMetadataProvider  = false
            });

            //Store User Data into the referenced SQl server
            var repo = new OrmLiteAuthRepository(container.Resolve <IDbConnectionFactory>())
            {
                UseDistinctRoleTables = true
            };

            container.Register <IAuthRepository>(c => repo);
            container.Register <IUserAuthRepository>(c => repo);
            repo.InitSchema();

            //Custom validators
            appHost.Register <IValidator <CreateUser> >(new CreateUserValidator());

            //Custom services
            appHost.RegisterService <UserService>();
        }
Beispiel #9
0
        /// <summary>
        /// Configure ServiceStack Authentication plugin.
        /// </summary>
        /// <param name="container">The container.</param>
        private void ConfigureAuth(Container container)
        {
            Plugins.Add(new AuthFeature(() => new AuthUserSession(),
                                        new IAuthProvider[]
            {
                new CredentialsAuthProvider(AppSettings),
                new ApiKeyAuthProvider(AppSettings),
                new BasicAuthProvider(AppSettings),
            }));

            Plugins.Add(new RegistrationFeature());

            var authRepo = new OrmLiteAuthRepository(container.Resolve <IDbConnectionFactory>());

            container.Register <IAuthRepository>(c => authRepo);
            authRepo.InitSchema();
        }
Beispiel #10
0
        public void SetUp()
        {
            try
            {
                tests = new OAuthUserSessionTests();

                appHost = new BasicAppHost().Init();

                var inMemoryRepo = new InMemoryAuthRepository();
                inMemoryRepo.Clear();
                userAuthRepositorys.Add(inMemoryRepo);

                var appSettings = new AppSettings();
                var redisRepo   = new RedisAuthRepository(new BasicRedisClientManager(new[] { appSettings.GetString("Redis.Host") ?? "localhost" }));
                redisRepo.Clear();
                userAuthRepositorys.Add(redisRepo);

                if (OAuthUserSessionTestsBase.UseSqlServer)
                {
                    var connStr          = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\App_Data\auth.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
                    var sqlServerFactory = new OrmLiteConnectionFactory(connStr, SqlServerOrmLiteDialectProvider.Instance);
                    var sqlServerRepo    = new OrmLiteAuthRepository(sqlServerFactory);
                    sqlServerRepo.DropAndReCreateTables();
                }
                else
                {
                    var sqliteInMemoryRepo = new OrmLiteAuthRepository(dbFactory);

                    sqliteInMemoryRepo.InitSchema();
                    sqliteInMemoryRepo.Clear();
                    userAuthRepositorys.Add(sqliteInMemoryRepo);

                    var sqliteDbFactory = new OrmLiteConnectionFactory(
                        "~/App_Data/auth.sqlite".MapProjectPath());
                    var sqliteDbRepo = new OrmLiteAuthRepository(sqliteDbFactory);
                    sqliteDbRepo.InitSchema();
                    userAuthRepositorys.Add(sqliteDbRepo);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw;
            }
        }
        /// <summary>
        /// Configure ServiceStack Authentication plugin.
        /// </summary>
        /// <param name="container">The container.</param>
        private void ConfigureAuth(Container container)
        {
            Plugins.Add(new AuthFeature(() => new AuthUserSession(),
                                        new IAuthProvider[]
            {
                new BasicAuthProvider(AppSettings),
                new ApiKeyAuthProvider(AppSettings),
            })
            {
                ServiceRoutes = new Dictionary <Type, string[]> {
                    { typeof(AuthenticateService), new[] { "/api/auth", "/api/auth/{provider}" } },
                }
            });

            var authRepo = new OrmLiteAuthRepository(container.Resolve <IDbConnectionFactory>());

            container.Register <IAuthRepository>(c => authRepo);
            authRepo.InitSchema();
        }
Beispiel #12
0
        /// <summary>
        /// Configure ServiceStack Authentication plugin.
        /// </summary>
        /// <param name="container">The container.</param>
        private void ConfigureAuth(Container container)
        {
            Plugins.Add(new AuthFeature(() => new AuthUserSession(),
                                        new IAuthProvider[]
            {
                new BasicAuthProvider(AppSettings),
                new ApiKeyAuthProvider(AppSettings),
            }));

            var authRepo = new OrmLiteAuthRepository(container.Resolve <IDbConnectionFactory>());

            container.Register <IAuthRepository>(c => authRepo);
            authRepo.InitSchema();

            5.Times(x => authRepo.CreateUserAuth(new UserAuth {
                UserName = $"user{x}",
                Email    = $"user{x}@email.com",
            }, "test"));

            AfterInitCallbacks.Add(host =>
            {
                var authProvider = (ApiKeyAuthProvider)
                                   AuthenticateService.GetAuthProvider(ApiKeyAuthProvider.Name);
                using (var db = host.TryResolve <IDbConnectionFactory>().Open())
                {
                    var userWithKeysIds = db.Column <string>(db.From <ApiKey>()
                                                             .SelectDistinct(x => x.UserAuthId)).Map(int.Parse);

                    var userIdsMissingKeys = db.Column <string>(db.From <UserAuth>()
                                                                .Where(x => userWithKeysIds.Count == 0 || !userWithKeysIds.Contains(x.Id))
                                                                .Select(x => x.Id));

                    foreach (var userId in userIdsMissingKeys)
                    {
                        var apiKeys = authProvider.GenerateNewApiKeys(userId.ToString());
                        authRepo.StoreAll(apiKeys);
                    }
                }
            });
        }
Beispiel #13
0
        /// <summary>
        /// Application specific configuration
        /// This method should initialize any IoC resources utilized by your web service classes.
        /// </summary>
        /// <param name="container"></param>
        public override void Configure(Container container)
        {
            JsConfig.EmitCamelCaseNames = true;

            SetConfig(new HostConfig
            {
                DebugMode = AppSettings.Get("DebugMode", false),
                AddRedirectParamsToQueryString = true,
            });

            this.Plugins.Add(new RazorFormat());

            container.Register <IDbConnectionFactory>(new OrmLiteConnectionFactory(
                                                          AppSettings.GetString("ConnectionString"), PostgreSqlDialect.Provider));

            this.Plugins.Add(new AuthFeature(() => new CustomUserSession(),
                                             new IAuthProvider[] {
                new CredentialsAuthProvider(AppSettings),
            }));

            var dbFactory = container.Resolve <IDbConnectionFactory>();
            var authRepo  = new OrmLiteAuthRepository(dbFactory);

            container.Register <IUserAuthRepository>(authRepo);
            authRepo.InitSchema();

            container.RegisterAs <OrmLiteCacheClient, ICacheClient>();
            container.Resolve <ICacheClient>().InitSchema();
            container.Register(c => new ContentCache(new MemoryCacheClient()));

            using (var db = dbFactory.OpenDbConnection())
            {
                //db.DropAndCreateTable<AutoQueryService>();
                db.CreateTableIfNotExists <AutoQueryService>();
            }
        }
Beispiel #14
0
        private void ConfigureAuth(Container container, IAppSettings appSettings)
        {
            //Register all Authentication methods you want to enable for this web app.
            Plugins.Add(new AuthFeature(() => new AuthUserSession(),
                                        new IAuthProvider[] {
                new ApiKeyAuthProvider(appSettings),
                new CredentialsAuthProvider()
                {
                    SessionExpiry = new TimeSpan(0, 30, 0)
                },                  //Sign-in with UserName/Password credentials
                new BasicAuthProvider()
                {
                    SessionExpiry = new TimeSpan(0, 30, 0)
                },                        //Sign-in with HTTP Basic Auth
            }
                                        )
            {
                IncludeAssignRoleServices = true,
                MaxLoginAttempts          = 5,
                ServiceRoutes             = new Dictionary <Type, string[]> {
                    { typeof(AuthenticateService), new[] { "/auth", "/auth/{provider}" } },
                },
                GenerateNewSessionCookiesOnAuthentication = true,
                DeleteSessionCookiesOnLogout = true,
                IncludeAuthMetadataProvider  = false
            });

            Plugins.Add(new RegistrationFeature());

            //Store User Data into the referenced SQl server
            var repo = new OrmLiteAuthRepository(container.Resolve <IDbConnectionFactory>());

            container.Register <IAuthRepository>(c => repo);
            container.Register <IUserAuthRepository>(c => repo);
            repo.InitSchema();
        }
Beispiel #15
0
        /// <summary>
        /// Application specific configuration
        /// This method should initialize any IoC resources utilized by your web service classes.
        /// </summary>
        /// <param name="container"></param>
        public override void Configure(Container container)
        {
            SetConfig(new HostConfig {
                AddRedirectParamsToQueryString = true,
                WebHostUrl = "http://techstacks.io", //for sitemap.xml urls
            });

            JsConfig.DateHandler = DateHandler.ISO8601;

            if (AppSettings.GetString("OrmLite.Provider") == "Postgres")
            {
                container.Register <IDbConnectionFactory>(new OrmLiteConnectionFactory(AppSettings.GetString("OrmLite.ConnectionString"), PostgreSqlDialect.Provider));
            }
            else
            {
                container.Register <IDbConnectionFactory>(new OrmLiteConnectionFactory("~/App_Data/db.sqlite".MapHostAbsolutePath(), SqliteDialect.Provider));
            }

            var dbFactory = container.Resolve <IDbConnectionFactory>();

            this.Plugins.Add(new AuthFeature(() => new CustomUserSession(), new IAuthProvider[]
            {
                new TwitterAuthProvider(AppSettings),
                new GithubAuthProvider(AppSettings),
                new JwtAuthProvider(AppSettings)
                {
                    RequireSecureConnection = false
                },
            }));

            container.Register(new TwitterUpdates(
                                   AppSettings.GetString("WebStacks.ConsumerKey"),
                                   AppSettings.GetString("WebStacks.ConsumerSecret"),
                                   AppSettings.GetString("WebStacks.AccessToken"),
                                   AppSettings.GetString("WebStacks.AccessSecret")));

            var authRepo = new OrmLiteAuthRepository <CustomUserAuth, UserAuthDetails>(dbFactory);

            container.Register <IUserAuthRepository>(authRepo);
            authRepo.InitSchema();

            using (var db = dbFactory.OpenDbConnection())
            {
                db.CreateTableIfNotExists <TechnologyStack>();
                db.CreateTableIfNotExists <Technology>();
                db.CreateTableIfNotExists <TechnologyChoice>();
                db.CreateTableIfNotExists <UserFavoriteTechnologyStack>();
                db.CreateTableIfNotExists <UserFavoriteTechnology>();

                RawHttpHandlers.Add(req => req.PathInfo == "/robots.txt" ? new NotFoundHttpHandler() : null);

                Plugins.Add(new SitemapFeature
                {
                    SitemapIndex =
                    {
                        new Sitemap {
                            AtPath       = "/sitemap-techstacks.xml",
                            LastModified = DateTime.UtcNow,
                            UrlSet       = db.Select(db.From <TechnologyStack>().OrderByDescending(x => x.LastModified))
                                           .Map(x => new SitemapUrl
                            {
                                Location = new ClientTechnologyStack{
                                    Slug = x.Slug
                                }.ToAbsoluteUri(),
                                LastModified    = x.LastModified,
                                ChangeFrequency = SitemapFrequency.Weekly,
                            }),
                        },
                        new Sitemap {
                            AtPath       = "/sitemap-technologies.xml",
                            LastModified = DateTime.UtcNow,
                            UrlSet       = db.Select(db.From <Technology>().OrderByDescending(x => x.LastModified))
                                           .Map(x => new SitemapUrl
                            {
                                Location = new ClientTechnology{
                                    Slug = x.Slug
                                }.ToAbsoluteUri(),
                                LastModified    = x.LastModified,
                                ChangeFrequency = SitemapFrequency.Weekly,
                            })
                        },
                        new Sitemap
                        {
                            AtPath       = "/sitemap-users.xml",
                            LastModified = DateTime.UtcNow,
                            UrlSet       = db.Select(db.From <CustomUserAuth>().OrderByDescending(x => x.ModifiedDate))
                                           .Map(x => new SitemapUrl
                            {
                                Location = new ClientUser{
                                    UserName = x.UserName
                                }.ToAbsoluteUri(),
                                LastModified    = x.ModifiedDate,
                                ChangeFrequency = SitemapFrequency.Weekly,
                            })
                        }
                    }
                });
            }

            Plugins.Add(new RazorFormat());
            Plugins.Add(new ValidationFeature());
            Plugins.Add(new AutoQueryMetadataFeature
            {
                AutoQueryViewerConfig =
                {
                    ServiceDescription        = "Discover what technologies were used to create popular Websites and Apps",
                    ServiceIconUrl            = "/img/app/logo-76.png",
                    BackgroundColor           = "#0095F5",
                    TextColor                 = "#fff",
                    LinkColor                 = "#ffff8d",
                    BrandImageUrl             = "/img/app/brand.png",
                    BrandUrl                  = "http://techstacks.io",
                    BackgroundImageUrl        = "/img/app/bg.png",
                    IsPublic                  = true,
                    OnlyShowAnnotatedServices = true,
                }
            });
            Plugins.Add(new AutoQueryFeature {
                MaxLimit = 200
            });
            Plugins.Add(new AdminFeature());
            Plugins.Add(new OpenApiFeature());

            container.RegisterValidators(typeof(AppHost).Assembly);
            container.RegisterValidators(typeof(TechnologyServices).Assembly);

            RegisterTypedRequestFilter <IRegisterStats>((req, res, dto) =>
                                                        dbFactory.RegisterPageView(dto.GetStatsId()));

            Plugins.Add(new CorsFeature(
                            allowOriginWhitelist: new[] { "http://localhost", "http://localhost:8080", "http://localhost:56500", "http://test.servicestack.net", "http://null.jsbin.com" },
                            allowCredentials: true,
                            allowedHeaders: "Content-Type, Allow, Authorization"));
        }
Beispiel #16
0
    // Configure your AppHost with the necessary configuration and dependencies your App needs
    public override void Configure(Container container)
    {
//            LogManager.LogFactory = new ConsoleLogFactory(debugEnabled:true);
        log = LogManager.GetLogger(typeof(AppHost));

        SetConfig(new HostConfig {
            // UseSameSiteCookies = true,
            AddRedirectParamsToQueryString = true,
        });

        JsConfig.Init(new Config {
            DateHandler = DateHandler.ISO8601
        });

        var dbFactory = container.Resolve <IDbConnectionFactory>();

        // enable server-side rendering, see: https://sharpscript.net
        Plugins.Add(new SharpPagesFeature {
            HtmlExtension = "htm",
            ScriptMethods =
            {
                new AppScriptMethods(GetCacheClient(), dbFactory)
            }
        });

        Plugins.Add(new AuthFeature(() => new CustomUserSession(), new IAuthProvider[] {
            new TwitterAuthProvider(AppSettings),
            new GithubAuthProvider(AppSettings),
            new JwtAuthProvider(AppSettings)
            {
                RequireSecureConnection = false,
                UseTokenCookie          = true,
                CreatePayloadFilter     = (payload, session) => {
                    var githubAuth = session.ProviderOAuthAccess.Safe()
                                     .FirstOrDefault(x => x.Provider == "github");
                    payload["ats"] = githubAuth?.AccessTokenSecret;
                },
                PopulateSessionFilter = (session, obj, req) => {
                    session.ProviderOAuthAccess = new List <IAuthTokens> {
                        new AuthTokens {
                            Provider = "github", AccessTokenSecret = obj["ats"]
                        }
                    };
                }
            },
            new DiscourseAuthProvider {
                Provider     = "servicestack",
                DiscourseUrl = "https://forums.servicestack.net",
            },
        })
        {
            HtmlRedirect = "/"
        });

        container.Register <IMarkdownProvider>(c =>
                                               new GitHubApiMarkdownProvider(Environment.GetEnvironmentVariable("GITHUB_AUTH")));

        container.Register <ITwitterUpdates>(new TwitterUpdates(
                                                 AppSettings.GetString("WebStacks.ConsumerKey"),
                                                 AppSettings.GetString("WebStacks.ConsumerSecret"),
                                                 AppSettings.GetString("WebStacks.AccessToken"),
                                                 AppSettings.GetString("WebStacks.AccessSecret"))
        {
            BaseUrl = AppSettings.GetString("PublicBaseUrl"),
        });

        container.Register(new EmailProvider {
            UserName = Environment.GetEnvironmentVariable("TECHSTACKS_SMTP_USER") ??
                       AppSettings.GetString("smtp.UserName"),
            Password = Environment.GetEnvironmentVariable("TECHSTACKS_SMTP_PASS") ??
                       AppSettings.GetString("smtp.Password"),
            EnableSsl = true,
            Host      = AppSettings.GetString("smtp.Host"),
            Port      = AppSettings.Get <int>("smtp.Port"),
            Bcc       = AppSettings.GetString("smtp.Bcc"),
        });

        var authRepo = new OrmLiteAuthRepository <CustomUserAuth, UserAuthDetails>(dbFactory);

        container.Register <IUserAuthRepository>(authRepo);
        authRepo.InitSchema();

        using (var db = dbFactory.OpenDbConnection())
        {
            db.CreateTableIfNotExists <TechnologyStack>();
            db.CreateTableIfNotExists <Technology>();
            db.CreateTableIfNotExists <TechnologyChoice>();
            db.CreateTableIfNotExists <UserFavoriteTechnologyStack>();
            db.CreateTableIfNotExists <UserFavoriteTechnology>();

            Plugins.Add(CreateSiteMap(db, baseUrl: "https://techstacks.io"));
        }

        Plugins.Add(new CorsFeature(
                        allowOriginWhitelist: new[] {
            "https://techstacks.io", "https://www.techstacks.io",
            "http://localhost:3000", "http://localhost:16325", "http://localhost:8080", "http://null.jsbin.com",
            "http://run.plnkr.co"
        },
                        allowCredentials: true,
                        allowedHeaders: "Content-Type, Allow, Authorization",
                        maxAge: 60 * 60)); //Cache OPTIONS permissions

        Plugins.Add(new ValidationFeature());
        container.RegisterValidators(typeof(AppHost).Assembly);
        container.RegisterValidators(typeof(TechnologyServices).Assembly);

        Plugins.Add(new AutoQueryMetadataFeature {
            AutoQueryViewerConfig =
            {
                ServiceDescription        = "Discover what technologies were used to create popular Websites and Apps",
                ServiceIconUrl            = "/img/app/logo-76.png",
                BackgroundColor           = "#0095F5",
                TextColor                 = "#fff",
                LinkColor                 = "#ffff8d",
                BrandImageUrl             = "/img/app/brand.png",
                BrandUrl                  = "https://techstacks.io",
                BackgroundImageUrl        = "/img/app/bg.png",
                IsPublic                  = true,
                OnlyShowAnnotatedServices = true,
            }
        });
        Plugins.Add(new AutoQueryFeature {
            MaxLimit         = 500,
            StripUpperInLike = false,
            IncludeTotal     = true,
            ResponseFilters  =
            {
#if DEBUG
                ctx => ctx.Response.Meta["Cache"] = Stopwatch.GetTimestamp().ToString()
#endif
            }
        });
        Plugins.Add(new AdminFeature());
        Plugins.Add(new OpenApiFeature());

        RegisterTypedRequestFilter <IRegisterStats>((req, res, dto) =>
                                                    dbFactory.RegisterPageView(dto.GetStatsId()));

        if (Config.DebugMode)
        {
            Plugins.Add(new LispReplTcpServer {
                ScriptMethods =
                {
                    new DbScriptsAsync()
                },
                ScriptNamespaces =
                {
                    nameof(TechStacks),
                    $"{nameof(TechStacks)}.{nameof(ServiceInterface)}",
                    $"{nameof(TechStacks)}.{nameof(ServiceModel)}",
                },
            });
        }
    }
Beispiel #17
0
        // Configure your AppHost with the necessary configuration and dependencies your App needs
        public override void Configure(Container container)
        {
            #region Logger
            LogManager.LogFactory = new NLogFactory();

            Plugins.Add(new SharpPagesFeature
            {
                MetadataDebugAdminRole = RoleNames.Admin
            });

            ILog Log = LogManager.GetLogger("MyApp");
            #endregion

            SetConfig(new HostConfig
            {
                DefaultRedirectPath = "/index.html",
                DebugMode           = AppSettings.Get(nameof(HostConfig.DebugMode), false)
            });

            JsConfig.IncludeNullValues = false;
            JsConfig.ExcludeTypeInfo   = true;
            JsConfig.DateHandler       = DateHandler.ISO8601;
            JsConfig.TextCase          = TextCase.PascalCase;
            JsConfig.TimeSpanHandler   = TimeSpanHandler.StandardFormat;

            #region Database
            var connString = AppSettings.Get("dbConnectionString", "");
            if (connString == "%%CONN_STR%%")
            {
                connString = AppSettings.Get("dbConnectionStringDev", "");
            }
            IOrmLiteDialectProvider dbProvider;
            switch (AppSettings.Get("dbProvider", ""))
            {
            case "postgresql":
                dbProvider = PostgreSqlDialect.Provider;
                break;

            case "sqlserver2008":
                dbProvider = SqlServerDialect.Provider;
                break;

            case "sqlserver2012":
                dbProvider = SqlServer2012Dialect.Provider;
                break;

            case "sqlserver2014":
                dbProvider = SqlServer2014Dialect.Provider;
                break;

            case "sqlserver2016":
                dbProvider = SqlServer2016Dialect.Provider;
                break;

            case "sqlserver2017":
                dbProvider = SqlServer2017Dialect.Provider;
                break;

            default:
                dbProvider = SqlServerDialect.Provider;
                break;
            }

            var dbFactory = new OrmLiteConnectionFactory(connString, dbProvider);
            container.Register <IDbConnectionFactory>(dbFactory);

            // OrmLiteConfig.StringFilter = s => s.Trim();
            OrmLiteConfig.DialectProvider.StringSerializer = new JsonStringSerializer();
            MyNamingStrategy.AppSettings = AppSettings;
            dbProvider.NamingStrategy    = new MyNamingStrategy();
            #endregion

            #region Plugins
            Plugins.Add(new CorsFeature(
                            allowedHeaders: "Content-Type, Allow, Authorization"));

            Plugins.Add(new OpenApiFeature()
            {
                ApiDeclarationFilter = declaration =>
                {
                    declaration.Info.Title = "MDC";
                    // declaration.Info.Contact = new ServiceStack.Api.OpenApi.Specification.OpenApiContact()
                    // {
                    //    Email = "*****@*****.**",
                    //    Name = "Alfredo Pacheco"
                    // };
                    declaration.Info.Description = "";
                },
                OperationFilter = (verb, op) =>
                {
                    switch (verb)
                    {
                    case "POST":
                        op.Parameters.RemoveAll(p => p.Name == "Id");
                        op.Parameters.RemoveAll(p => p.Name == "RowVersion");
                        break;

                    default:
                        break;
                    }
                    op.Parameters.RemoveAll(p => p.Name == "EntityName");
                    op.Parameters.RemoveAll(p => p.Name == "EF_State");
                }
            });

            Plugins.Add(new AutoQueryFeature
            {
                // MaxLimit = 100
            });

            Plugins.Add(new RequestLogsFeature());

            Plugins.Add(new AdminFeature());

            Plugins.Add(new ServerEventsFeature());
            // var rollbarSettings = AppSettings.Get<RollbarSettings>("RollbarPluginSettings");
            // Plugins.Add(new RollbarLoggerPlugin
            // {
            //     ApiKey = rollbarSettings.ApiKey,
            //     Enabled = rollbarSettings.Enabled,
            //     EnableErrorTracking = rollbarSettings.EnableErrorTracking,
            //     EnableRequestBodyTracking = rollbarSettings.EnableRequestBodyTracking,
            //     EnableResponseTracking = rollbarSettings.EnableResponseTracking,
            //     EnableSessionTracking = rollbarSettings.EnableSessionTracking,
            //     Environment = rollbarSettings.Environment,
            //     // HideRequestBodyForRequestDtoTypes = new List<Type>(),
            //     // ExcludeRequestDtoTypes = new List<Type>
            //     // {
            //     //         // Might have to exclude the Swagger requests to get the two to play nicely
            //     //     typeof(RollbarLogConfigRequest),
            //     //     typeof(SwaggerResource),
            //     //     typeof(SwaggerApiDeclaration)
            //     // },
            //     RequiredRoles = rollbarSettings.RequiredRoles,
            //     SkipLogging = IsRequestSkippedDuringRequestLogging
            // });
            #endregion

            #region Auth
            var authProviders = new List <IAuthProvider>
            {
                new JwtAuthProvider(AppSettings)
                {
                    RequireSecureConnection = false,
                    AllowInQueryString      = true
                },
                new CredentialsAuthProvider(),
                new ApiKeyAuthProvider()
                {
                    RequireSecureConnection = false,
                    SessionCacheDuration    = TimeSpan.FromMinutes(30)
                }
            };
            var authFeature = new AuthFeature(SessionFactory, authProviders.ToArray());
            Plugins.Add(authFeature);

            var authRepo = new OrmLiteAuthRepository <Account, UserAuthDetails>(dbFactory);
            container.Register <IAuthRepository>(authRepo);

            authRepo.InitSchema();
            authRepo.InitApiKeySchema();

            Plugins.Add(new RegistrationFeature());

            var admin = authRepo.GetUserAuthByUserName("admin");
            if (admin == null)
            {
                authRepo.CreateUserAuth(new Account
                {
                    UserName = "******",
                    Roles    = new List <string> {
                        RoleNames.Admin
                    }
                }, "admin");
            }
            #endregion
            // TODO:
            // Cache.
            // Logging.
            // Batched requests.
            // Profiler.
            // Versioning.
            // stripe.com

            #region Cache
            // container.Register<ICacheClient>(new MemoryCacheClient());
            #endregion

            #region App
            AttachmentsIO.AppSettings = AppSettings;
            // container.Register(c => dbFactory.Open());
            // container.Register(c => c.Resolve<IDbConnectionFactory>().OpenDbConnection()).ReusedWithin(ReuseScope.Request);
            container.RegisterAutoWired <RevisionLogic>().ReusedWithin(ReuseScope.Request);
            EmailService.AppSettings = AppSettings;
            container.Register <IEmailService>(i => new EmailService()).ReusedWithin(ReuseScope.Request);
            container.RegisterAutoWired <CatalogLogic>().ReusedWithin(ReuseScope.Request);
            container.RegisterAutoWired <CatalogDefinitionLogic>().ReusedWithin(ReuseScope.Request);
            container.RegisterAutoWired <FieldLogic>().ReusedWithin(ReuseScope.Request);
            container.RegisterAutoWired <CatalogFieldValueLogic>().ReusedWithin(ReuseScope.Request);
            container.RegisterAutoWired <AccountLogic>().ReusedWithin(ReuseScope.Request);
            container.RegisterAutoWired <TokenLogic>().ReusedWithin(ReuseScope.Request);

            // This App:
            ///start:generated:di<<<
            container.RegisterAutoWired <ApproverLogic>().ReusedWithin(ReuseScope.Request);
            container.RegisterAutoWired <AttachmentFileCommentLogic>().ReusedWithin(ReuseScope.Request);
            container.RegisterAutoWired <MDCLogic>().ReusedWithin(ReuseScope.Request);
            container.RegisterAutoWired <MdcAttachmentFileLogic>().ReusedWithin(ReuseScope.Request);
            ///end:generated:di<<<
            #endregion

            #region Seed Data
            Sower.Seed(dbFactory);
            #endregion

            Log.Info("================= Application Started =================");
        } // Configure
Beispiel #18
0
        /// <summary>
        /// Application specific configuration
        /// This method should initialize any IoC resources utilized by your web service classes.
        /// </summary>
        /// <param name="container"></param>
        public override void Configure(Container container)
        {
            SetConfig(new HostConfig {
                AddRedirectParamsToQueryString = true,
                WebHostUrl = "http://techstacks.io", //for sitemap.xml urls
            });

            JsConfig.DateHandler = DateHandler.ISO8601;

            if (AppSettings.GetString("OrmLite.Provider") == "Postgres")
            {
                container.Register <IDbConnectionFactory>(new OrmLiteConnectionFactory(AppSettings.GetString("OrmLite.ConnectionString"), PostgreSqlDialect.Provider));
            }
            else
            {
                container.Register <IDbConnectionFactory>(new OrmLiteConnectionFactory("~/App_Data/db.sqlite".MapHostAbsolutePath(), SqliteDialect.Provider));
            }

            var dbFactory = container.Resolve <IDbConnectionFactory>();

            this.Plugins.Add(new AuthFeature(() => new CustomUserSession(), new IAuthProvider[]
            {
                new TwitterAuthProvider(AppSettings),
                new GithubAuthProvider(AppSettings)
            }));

            container.Register(new TwitterUpdates(
                                   AppSettings.GetString("WebStacks.ConsumerKey"),
                                   AppSettings.GetString("WebStacks.ConsumerSecret"),
                                   AppSettings.GetString("WebStacks.AccessToken"),
                                   AppSettings.GetString("WebStacks.AccessSecret")));

            var authRepo = new OrmLiteAuthRepository <CustomUserAuth, UserAuthDetails>(dbFactory);

            container.Register <IUserAuthRepository>(authRepo);
            authRepo.InitSchema();

            container.RegisterAs <OrmLiteCacheClient, ICacheClient>();
            container.Resolve <ICacheClient>().InitSchema();

            container.Register(c => new ContentCache(new MemoryCacheClient()));

            using (var db = dbFactory.OpenDbConnection())
            {
                db.CreateTableIfNotExists <TechnologyStack>();
                db.CreateTableIfNotExists <Technology>();
                db.CreateTableIfNotExists <TechnologyChoice>();
                db.CreateTableIfNotExists <UserFavoriteTechnologyStack>();
                db.CreateTableIfNotExists <UserFavoriteTechnology>();

                RawHttpHandlers.Add(req => req.PathInfo == "/robots.txt" ? new NotFoundHttpHandler() : null);

                Plugins.Add(new SitemapFeature
                {
                    SitemapIndex =
                    {
                        new Sitemap {
                            AtPath       = "/sitemap-techstacks.xml",
                            LastModified = DateTime.UtcNow,
                            UrlSet       = db.Select <TechnologyStack>(q => q.OrderByDescending(x => x.LastModified))
                                           .Map(x => new SitemapUrl
                            {
                                Location = new ClientTechnologyStack{
                                    Slug = x.Slug
                                }.ToAbsoluteUri(),
                                LastModified    = x.LastModified,
                                ChangeFrequency = SitemapFrequency.Weekly,
                            }),
                        },
                        new Sitemap {
                            AtPath       = "/sitemap-technologies.xml",
                            LastModified = DateTime.UtcNow,
                            UrlSet       = db.Select <Technology>(q => q.OrderByDescending(x => x.LastModified))
                                           .Map(x => new SitemapUrl
                            {
                                Location = new ClientTechnology{
                                    Slug = x.Slug
                                }.ToAbsoluteUri(),
                                LastModified    = x.LastModified,
                                ChangeFrequency = SitemapFrequency.Weekly,
                            })
                        },
                        new Sitemap
                        {
                            AtPath       = "/sitemap-users.xml",
                            LastModified = DateTime.UtcNow,
                            UrlSet       = db.Select <CustomUserAuth>(q => q.OrderByDescending(x => x.ModifiedDate))
                                           .Map(x => new SitemapUrl
                            {
                                Location = new ClientUser{
                                    UserName = x.UserName
                                }.ToAbsoluteUri(),
                                LastModified    = x.ModifiedDate,
                                ChangeFrequency = SitemapFrequency.Weekly,
                            })
                        }
                    }
                });
            }

            Plugins.Add(new RazorFormat());
            Plugins.Add(new AutoQueryFeature {
                MaxLimit = 200
            });
            Plugins.Add(new ValidationFeature());

            container.RegisterValidators(typeof(AppHost).Assembly);
            container.RegisterValidators(typeof(TechnologyServices).Assembly);
        }
Beispiel #19
0
        // Configure your AppHost with the necessary configuration and dependencies your App needs
        public override void Configure(Container container)
        {
//            LogManager.LogFactory = new ConsoleLogFactory(debugEnabled:true);
            log = LogManager.GetLogger(typeof(AppHost));

            // enable server-side rendering, see: http://templates.servicestack.net
            Plugins.Add(new TemplatePagesFeature {
            });
            GetPlugin <NativeTypesFeature>().MetadataTypesConfig.BaseUrl = "https://www.techstacks.io";

            var debugMode = AppSettings.Get(nameof(HostConfig.DebugMode), false);

            SetConfig(new HostConfig
            {
                AddRedirectParamsToQueryString = true,
                DebugMode = debugMode,
            });

            JsConfig.DateHandler = DateHandler.ISO8601;

            var dbFactory = new OrmLiteConnectionFactory(
                Environment.GetEnvironmentVariable("TECHSTACKS_DB") ?? AppSettings.GetString("OrmLite.ConnectionString"),
                PostgreSqlDialect.Provider);

            dbFactory.RegisterDialectProvider(nameof(PostgreSqlDialect), PostgreSqlDialect.Provider);

            container.Register <IDbConnectionFactory>(dbFactory);

            Plugins.Add(new AuthFeature(() => new CustomUserSession(), new IAuthProvider[]
            {
                new TwitterAuthProvider(AppSettings),
                new GithubAuthProvider(AppSettings),
                new JwtAuthProvider(AppSettings)
                {
                    RequireSecureConnection = false,
                    IncludeJwtInConvertSessionToTokenResponse = true,
                    CreatePayloadFilter = (payload, session) =>
                    {
                        var githubAuth = session.ProviderOAuthAccess.Safe()
                                         .FirstOrDefault(x => x.Provider == "github");
                        payload["ats"] = githubAuth?.AccessTokenSecret;
                    },
                    PopulateSessionFilter = (session, obj, req) =>
                    {
                        session.ProviderOAuthAccess = new List <IAuthTokens>
                        {
                            new AuthTokens {
                                Provider = "github", AccessTokenSecret = obj["ats"]
                            }
                        };
                    }
                },
                new DiscourseAuthProvider {
                    Provider     = "servicestack",
                    DiscourseUrl = "https://forums.servicestack.net",
                },
            })
            {
                HtmlRedirect = "/"
            });

            container.Register <IMarkdownProvider>(c =>
                                                   new GitHubApiMarkdownProvider(Environment.GetEnvironmentVariable("GITHUB_AUTH")));

            container.Register(new TwitterUpdates(
                                   AppSettings.GetString("WebStacks.ConsumerKey"),
                                   AppSettings.GetString("WebStacks.ConsumerSecret"),
                                   AppSettings.GetString("WebStacks.AccessToken"),
                                   AppSettings.GetString("WebStacks.AccessSecret"))
            {
                BaseUrl = AppSettings.GetString("PublicBaseUrl"),
            });

            container.Register(new EmailProvider {
                UserName  = Environment.GetEnvironmentVariable("TECHSTACKS_SMTP_USER") ?? AppSettings.GetString("smtp.UserName"),
                Password  = Environment.GetEnvironmentVariable("TECHSTACKS_SMTP_PASS") ?? AppSettings.GetString("smtp.Password"),
                EnableSsl = true,
                Host      = AppSettings.GetString("smtp.Host"),
                Port      = AppSettings.Get <int>("smtp.Port"),
                Bcc       = AppSettings.GetString("smtp.Bcc"),
            });

            var authRepo = new OrmLiteAuthRepository <CustomUserAuth, UserAuthDetails>(dbFactory);

            container.Register <IUserAuthRepository>(authRepo);
            authRepo.InitSchema();

            using (var db = dbFactory.OpenDbConnection())
            {
                db.CreateTableIfNotExists <TechnologyStack>();
                db.CreateTableIfNotExists <Technology>();
                db.CreateTableIfNotExists <TechnologyChoice>();
                db.CreateTableIfNotExists <UserFavoriteTechnologyStack>();
                db.CreateTableIfNotExists <UserFavoriteTechnology>();

                var baseUrl = "https://techstacks.io";

                Plugins.Add(new SitemapFeature
                {
                    SitemapIndex =
                    {
                        new Sitemap {
                            Location     = baseUrl + "/sitemap-techstacks.xml",
                            AtPath       = "/sitemap-techstacks.xml",
                            LastModified = DateTime.UtcNow,
                            UrlSet       = db.Select(db.From <TechnologyStack>().OrderByDescending(x => x.LastModified))
                                           .Map(x => new SitemapUrl
                            {
                                Location = baseUrl + new ClientTechnologyStack{
                                    Slug = x.Slug
                                }.ToAbsoluteUri(),
                                LastModified    = x.LastModified,
                                ChangeFrequency = SitemapFrequency.Weekly,
                            }),
                        },
                        new Sitemap {
                            Location     = baseUrl + "/sitemap-technologies.xml",
                            AtPath       = "/sitemap-technologies.xml",
                            LastModified = DateTime.UtcNow,
                            UrlSet       = db.Select(db.From <Technology>().OrderByDescending(x => x.LastModified))
                                           .Map(x => new SitemapUrl
                            {
                                Location = baseUrl + new ClientTechnology{
                                    Slug = x.Slug
                                }.ToAbsoluteUri(),
                                LastModified    = x.LastModified,
                                ChangeFrequency = SitemapFrequency.Weekly,
                            })
                        },
                        new Sitemap
                        {
                            Location     = baseUrl + "/sitemap-users.xml",
                            AtPath       = "/sitemap-users.xml",
                            LastModified = DateTime.UtcNow,
                            UrlSet       = db.Select(db.From <CustomUserAuth>().OrderByDescending(x => x.ModifiedDate))
                                           .Map(x => new SitemapUrl
                            {
                                Location = baseUrl + new ClientUser{
                                    UserName = x.UserName
                                }.ToAbsoluteUri(),
                                LastModified    = x.ModifiedDate,
                                ChangeFrequency = SitemapFrequency.Weekly,
                            })
                        },
                        new Sitemap {
                            Location     = baseUrl + "/sitemap-organizations.xml",
                            AtPath       = "/sitemap-organizations.xml",
                            LastModified = DateTime.UtcNow,
                            UrlSet       = db.Select(db.From <Organization>().Where(x => x.Deleted == null).OrderByDescending(x => x.Modified))
                                           .Map(x => new SitemapUrl
                            {
                                Location        = baseUrl + $"/{x.Slug}",
                                LastModified    = x.Modified,
                                ChangeFrequency = SitemapFrequency.Weekly,
                            })
                        },
                        new Sitemap {
                            Location     = baseUrl + "/sitemap-posts.xml",
                            AtPath       = "/sitemap-posts.xml",
                            LastModified = DateTime.UtcNow,
                            UrlSet       = db.Select(db.From <Post>().Where(x => x.Type != PostType.Question && x.Deleted == null && x.Hidden == null).Take(1000).OrderByDescending(x => x.Modified))
                                           .Map(x => new SitemapUrl
                            {
                                Location        = baseUrl + $"/posts/{x.Id}/{x.Slug}",
                                LastModified    = x.Modified,
                                ChangeFrequency = SitemapFrequency.Hourly,
                            })
                        }
                    }
                });
            }

            Plugins.Add(new ValidationFeature());
            Plugins.Add(new AutoQueryMetadataFeature
            {
                AutoQueryViewerConfig =
                {
                    ServiceDescription        = "Discover what technologies were used to create popular Websites and Apps",
                    ServiceIconUrl            = "/img/app/logo-76.png",
                    BackgroundColor           = "#0095F5",
                    TextColor                 = "#fff",
                    LinkColor                 = "#ffff8d",
                    BrandImageUrl             = "/img/app/brand.png",
                    BrandUrl                  = "http://techstacks.io",
                    BackgroundImageUrl        = "/img/app/bg.png",
                    IsPublic                  = true,
                    OnlyShowAnnotatedServices = true,
                }
            });
            Plugins.Add(new AutoQueryFeature
            {
                MaxLimit         = 500,
                StripUpperInLike = false,
                ResponseFilters  =
                {
                    ctx => ctx.Response.Meta["Cache"] = Stopwatch.GetTimestamp().ToString()
                }
            });
            Plugins.Add(new AdminFeature());
            Plugins.Add(new OpenApiFeature());

            container.RegisterValidators(typeof(AppHost).Assembly);
            container.RegisterValidators(typeof(TechnologyServices).Assembly);

            RegisterTypedRequestFilter <IRegisterStats>((req, res, dto) =>
                                                        dbFactory.RegisterPageView(dto.GetStatsId()));

            Plugins.Add(new CorsFeature(
                            allowOriginWhitelist: new[] { "https://techstacks.io", "https://www.techstacks.io",
                                                          "http://localhost:3000", "http://localhost:16325", "http://localhost:8080", "http://null.jsbin.com", "http://run.plnkr.co" },
                            allowCredentials: true,
                            allowedHeaders: "Content-Type, Allow, Authorization",
                            maxAge: 60 * 60)); //Cache OPTIONS permissions

            container.Register <IMessageService>(c => new BackgroundMqService());
            var mqServer = container.Resolve <IMessageService>();

            mqServer.RegisterHandler <SendNotification>(ExecuteMessage, 4);
            mqServer.RegisterHandler <SendSystemEmail>(ExecuteMessage);

            mqServer.Start();

            AfterInitCallbacks.Add(host => ExecuteService(new RetryPendingNotifications()));
        }
Beispiel #20
0
        // Configure your AppHost with the necessary configuration and dependencies your App needs
        public override void Configure(Container container)
        {
            #region Metadata
            SetConfig(new HostConfig
            {
                DefaultRedirectPath = "/metadata",
                DebugMode           = AppSettings.Get(nameof(HostConfig.DebugMode), false)
            });
            #endregion

            #region Plugins
            Plugins.Add(new ValidationFeature());
            container.RegisterValidators(
                typeof(CreatePlaceValidator).Assembly);

            Plugins.Add(new CorsFeature());

            Plugins.Add(new PostmanFeature());
            #endregion

            #region App
            container.RegisterAutoWiredAs <BasicOrmMessageRepository, IMessageRepository>();
            container.RegisterAutoWired <MyAppSettings>();
            var appSettings = container.Resolve <MyAppSettings>();
            #endregion

            #region Database
            var dbFactory = new OrmLiteConnectionFactory(
                appSettings.Get("sqlLiteConnectionString", "").MapHostAbsolutePath(),
                SqliteDialect.Provider);

            container.Register <IDbConnectionFactory>(dbFactory);

            using (var db = dbFactory.OpenDbConnection())
            {
                //db.DropAndCreateTable<UserGreeting>();
                db.DropAndCreateTable <UserLanguage>();
                db.DropAndCreateTable <GreetingUsage>();
            }

            using (var db = dbFactory.OpenDbConnection())
            {
                db.Insert(new UserLanguage {
                    Language = "English"
                });
                //db.Insert(new UserGreeting
                //{
                //    Greeting = "Hello, {0}",
                //    UserLanguageId = 1
                //});
                //db.Insert(new UserGreeting
                //{
                //    Greeting = "G'day, {0}"
                //});
                //db.Insert(new UserGreeting
                //{
                //    Greeting = "Howdy, {0}!"
                //});
            }
            OrmLiteConfig.StringFilter = s => s.Trim();
            #endregion

            #region Auth
            var authProviders = new List <IAuthProvider>();
            authProviders.Add(new CredentialsAuthProvider());

            var authFeature = new AuthFeature(SessionFactory, authProviders.ToArray());
            Plugins.Add(authFeature);

            var authRepo = new OrmLiteAuthRepository(dbFactory);
            container.Register <IUserAuthRepository>(authRepo);
            container.Register <ICacheClient>(new MemoryCacheClient());
            authRepo.DropAndReCreateTables();
            authRepo.InitSchema();

            Plugins.Add(new RegistrationFeature());
            //CreateUsers(userRep);

            authRepo.CreateUserAuth(new UserAuth
            {
                UserName = "******",
                Roles    = new List <string> {
                    RoleNames.Admin
                }
            }, "admin");
            #endregion

            //Plugins.Add(new OpenApiFeature());

            //TODO:
            //Logging.
            //Cache.
            //Global Response Filter: CommonResponse.
            //Batched requests.
            //transactions.
            //attachments
            //Profiler.
            //Versioning.
            //Compression.
            //Autoquery.
            //stripe.com
        }