Esempio n. 1
0
        // This method is auto-detected by the OWIN pipeline. DO NOT RENAME IT!
        public static void Configuration(IAppBuilder app)
        {
            // Get config
            var config = Container.Kernel.Get<ConfigurationService>();
            var auth = Container.Kernel.Get<AuthenticationService>();

            // Configure logging
            app.SetLoggerFactory(new DiagnosticsLoggerFactory());

            if (config.Current.RequireSSL)
            {
                // Put a middleware at the top of the stack to force the user over to SSL
                // if authenticated.
                //app.UseForceSslWhenAuthenticated(config.Current.SSLPort);

                // Put a middleware at the top of the stack to force the user over to SSL always
                app.UseForceSslAlways(config.Current.SSLPort);
            }

            app.UseBasicAuthentication(new BasicAuthenticationOptions()
            {
                AuthenticationMode = AuthenticationMode.Active,
                AuthenticationType = AuthenticationTypes.LocalUser,
            });
            app.SetDefaultSignInAsAuthenticationType(AuthenticationTypes.LocalUser);

            if (config.Current.ForceAuth)
            {
                app.Authorize();
            }

            //// Get the local user auth provider, if present and attach it first
            //Authenticator localUserAuther;
            //if (auth.Authenticators.TryGetValue(Authenticator.GetName(typeof(LocalUserAuthenticator)), out localUserAuther))
            //{
            //    // Configure cookie auth now
            //    localUserAuther.Startup(config, app);
            //}

            //// Attach external sign-in cookie middleware
            //app.SetDefaultSignInAsAuthenticationType(AuthenticationTypes.External);
            //app.UseCookieAuthentication(new CookieAuthenticationOptions()
            //{
            //    AuthenticationType = AuthenticationTypes.External,
            //    AuthenticationMode = AuthenticationMode.Passive,
            //    CookieName = ".AspNet." + AuthenticationTypes.External,
            //    ExpireTimeSpan = TimeSpan.FromMinutes(5)
            //});

            //// Attach non-cookie auth providers
            //var nonCookieAuthers = auth
            //    .Authenticators
            //    .Where(p => !String.Equals(
            //        p.Key,
            //        Authenticator.GetName(typeof(LocalUserAuthenticator)),
            //        StringComparison.OrdinalIgnoreCase))
            //    .Select(p => p.Value);
            //foreach (var auther in nonCookieAuthers)
            //{
            //    auther.Startup(config, app);
            //}
        }