using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.Owin;
using Microsoft.Owin.Host.SystemWeb;
using Microsoft.Owin.Security.Cookies;
using Owin;
using System;
using System.Configuration;

[assembly: OwinStartup(typeof(OlympiaIntranet.App_Start.Startup))]

namespace OlympiaIntranet.App_Start
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            // Per gestire il timeout degli utenti guardare qui : https://www.jamessturtevant.com/posts/ASPNET-Identity-Cookie-Authentication-Timeouts/
            // Per implementare il single sign on : https://stackoverflow.com/questions/42229847/single-sign-on-using-asp-net-identity-between-2-asp-net-mvc-projects

            // Possibile soluzione da studiare per il mancanto login qui : https://stackoverflow.com/questions/20737578/asp-net-sessionid-owin-cookies-do-not-send-to-browser

            string cookieDomain = ConfigurationManager.AppSettings["cookieDomain"].ToString();
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                LoginPath = new PathString("/SignIn.aspx"),
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                CookieName = "OlympiaCookieAuth",
                CookieDomain = cookieDomain,
                CookieManager = new SystemWebCookieManager()
                //SlidingExpiration = false,
                //CookieHttpOnly = false,                    // aggiunto per risolvere problemi di login 
                //CookieSameSite = SameSiteMode.None,        // aggiunto per risolvere problemi di login 
                //CookieSecure = CookieSecureOption.Always,  // aggiunto per risolvere problemi di login
                //ExpireTimeSpan = TimeSpan.FromMinutes(240) // scadenza credenziali login 4 ore
            });
        }
    }
}
