Beispiel #1
0
        private void ConfigureOAuth(IAppBuilder app, IRohamConfigs rohamConfigs)
        {
            app.CreatePerOwinContext <ApplicationUserManager>(CreateUserManager);
            app.CreatePerOwinContext <ApplicationRoleManager>(CreateRoleManager);

            // Enable the application to use a cookie to store information for the signed in user
            // and to use a cookie to temporarily store information about a user logging in with a third party login provider
            // Configure the sign in cookie
            var cookieAuthOptions = new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath          = new PathString("/Login"),
            };

            app.UseCookieAuthentication(cookieAuthOptions);
            if (rohamConfigs.IsInstalled)
            {
                cookieAuthOptions.Provider = new CookieAuthenticationProvider
                {
                    // Enables the application to validate the security stamp when the user logs in.
                    // This is a security feature which is used when you change a password or add an external login to your account.
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <ApplicationUserManager, ApplicationUser, long>(
                        validateInterval: TimeSpan.FromMinutes(30),
                        regenerateIdentityCallback: (manager, user) => manager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie),
                        getUserIdCallback: c => c.GetUserId <long>())
                };
            }
            else
            {
                cookieAuthOptions.Provider = new CookieAuthenticationProvider();
            }

            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

            // Enables the application to remember the second login verification factor such as phone or email.
            // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
            // This is similar to the RememberMe option when you log in.
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "1",
            //    clientSecret: "1");

            app.UseTwitterAuthentication(
                consumerKey: "1",
                consumerSecret: "1");

            app.UseFacebookAuthentication(
                appId: "1",
                appSecret: "1");

            app.UseGoogleAuthentication(
                clientId: "104443523592-pdhb03d6bfg3m87n2c69ue3g6narugpf.apps.googleusercontent.com",
                clientSecret: "pChV00MKKcUtsnjvLg1Rwkvl");
        }
Beispiel #2
0
 public InstallPortalCommandHandler(
     Func <IPersistenceUnitOfWorkFactory> uowFactoryResolver,
     IRohamConfigs rohamConfigs,
     IDatabaseProviderFactory dbProviderFactory,
     ICacheProvider cacheProvider,
     ICommandDispatcher commandDispatcher) : base(uowFactoryResolver)
 {
     _rohamConfigs      = rohamConfigs;
     _dbProviderFactory = dbProviderFactory;
     CacheProvider      = cacheProvider;
     _commandDispatcher = commandDispatcher;
 }
Beispiel #3
0
 public InstallController(
     IRohamConfigs rohamConfigs,
     ICacheService cacheService,
     ICacheProvider cacheProvider,
     IDatabaseProviderFactory dbProviderFactory,
     ICommandDispatcher commandDispatcher)
 {
     _rohamConfigs      = rohamConfigs;
     _cacheService      = cacheService;
     _dbProviderFactory = dbProviderFactory;
     _commandDispatcher = commandDispatcher;
     CacheProvider      = cacheProvider;
 }
Beispiel #4
0
        private void ConfigureMiddlewares(IAppBuilder app, IRohamConfigs rohamConfigsParam, ICacheService cacheService)
        {
            var rohamConfigs = rohamConfigsParam;

            app.Use(async(context, next) =>
            {
                string requestPath = context.Request.Path.Value != null ? context.Request.Path.Value.Trim().ToLower() : "";
                bool isBrowserLink = requestPath.StartsWith("/__browserlink");
                if (!isBrowserLink)
                {
                    bool isErrorPage = requestPath.StartsWith("/error");

                    if (!isErrorPage)
                    {
                        bool isConfigMissing = rohamConfigs.IsConfigFileMissing;
                        bool appNotInstalled = !rohamConfigs.IsInstalled;
                        bool upgradeRequired = false; // TODO:
                        bool isInstall       = requestPath.StartsWith("/admin/install");
                        bool isUpgrade       = requestPath.StartsWith("/admin/upgrade");

                        if (isConfigMissing)
                        {
                            RedirectToError(context, cacheService, ErrorMessages.ConfigFileMissing);
                            return;
                        }
                        else if (appNotInstalled && !isInstall)
                        {
                            context.Response.Redirect("/admin/install");
                            return;
                        }
                        else if (upgradeRequired && !requestPath.StartsWith("/admin/upgrade"))
                        {
                            context.Response.Redirect("/admin/upgrade");
                            return;
                        }
                        else
                        {
                            if (!isInstall && !isUpgrade)
                            {
                                // check database is accessible?
                                var dbProvider = RohamDependencyResolver.Current.Resolve <IDatabaseProvider>();
                                string errorMessage;
                                if (!dbProvider.TryConnect(rohamConfigs.ConnectionString, out errorMessage))
                                {
                                    RedirectToError(context, cacheService, ErrorMessages.DatabaseIsDown);
                                    return;
                                }
                            }
                        }
                    }
                }

                try
                {
                    await next();
                }
                catch (Exception ex)
                {
                    Log.Error("An unhadled exception occured.", ex);
                    context.Response.Redirect("/error");
                }
            });
        }
 public MemCacheServiceSmokeTests()
 {
     _rohamConfigs  = new MemCacheConfigs();
     SubjectFactory = () => new CacheService(() => _rohamConfigs, () => _cacheProvider);
 }