public static IServiceCollection AddEiSession(this IServiceCollection services,
                                                      IWebSessionSettings settings)
        {
            if (settings.SessionStorage == SessionStorageType.Redis)
            {
                services
                .AddDataProtection()
                .PersistKeysToStackExchangeRedis(
                    () => ConnectionMultiplexer.Connect(settings.RedisConnectionString().GetAwaiter().GetResult()).GetDatabase(),
                    "ProtectedSessionKeys");
                services.AddStackExchangeRedisCache(option =>
                {
                    option.Configuration = settings.RedisConnectionString().GetAwaiter().GetResult();
                    option.InstanceName  = CacheModule.RedisInstanceName;
                });
            }

            services.AddSession(opts =>
            {
                opts.IdleTimeout         = settings.SessionTimeout;
                opts.Cookie.HttpOnly     = true;
                opts.Cookie.IsEssential  = true;
                opts.Cookie.SecurePolicy = CookieSecurePolicy.Always;
            });
            return(services);
        }
 public static CookieAuthenticationOptions ConfigureSessionStorage(this CookieAuthenticationOptions opts, IWebSessionSettings settings)
 {
     if (settings.SessionStorage == SessionStorageType.InMemory)
     {
         opts.SessionStore = new InMemoryTicketStore(settings);
     }
     else if (settings.SessionStorage == SessionStorageType.Redis)
     {
         var connectionString = settings.RedisConnectionString().GetAwaiter().GetResult();
         opts.SessionStore = new RedisTicketStore(new RedisCacheOptions
         {
             Configuration = connectionString,
             InstanceName  = CacheModule.RedisInstanceName
         }, settings);
     }
     return(opts);
 }