예제 #1
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="cache"></param>
 /// <param name="aesCipher"></param>
 /// <param name="dexClient"></param>
 /// <param name="logger"></param>
 public SessionTransformer(
     IDistributedCache cache,
     AesCipher aesCipher,
     DexClient dexClient,
     INeonLogger logger,
     DistributedCacheEntryOptions cacheOptions)
 {
     this.cache        = cache;
     this.cipher       = aesCipher;
     this.dexClient    = dexClient;
     this.dexHost      = dexClient.BaseAddress.Host;
     this.logger       = logger;
     this.cacheOptions = cacheOptions;
 }
예제 #2
0
        /// <summary>
        /// Configures depdendency injection.
        /// </summary>
        /// <param name="services">The service collection.</param>
        public void ConfigureServices(IServiceCollection services)
        {
            if (NeonSsoSessionProxyService.InDevelopment)
            {
                services.AddDistributedMemoryCache();
            }
            else
            {
                services.AddStackExchangeRedisCache(options =>
                {
                    options.Configuration        = "neon-redis.neon-system";
                    options.InstanceName         = "neon-redis";
                    options.ConfigurationOptions = new ConfigurationOptions()
                    {
                        AllowAdmin  = true,
                        ServiceName = "master"
                    };

                    options.ConfigurationOptions.EndPoints.Add("neon-redis.neon-system:26379");
                });
            }
            services.AddSingleton <INeonLogger>(NeonSsoSessionProxyService.Log);
            services.AddHealthChecks();
            services.AddHttpForwarder();
            services.AddHttpClient();

            // Dex config
            var dexClient = new DexClient(new Uri($"http://{KubeService.Dex}:5556"), NeonSsoSessionProxyService.Log);

            // Load in each of the clients from the Dex config into the client.
            foreach (var client in NeonSsoSessionProxyService.Config.StaticClients)
            {
                dexClient.AuthHeaders.Add(client.Id, new BasicAuthenticationHeaderValue(client.Id, client.Secret));
            }

            services.AddSingleton(dexClient);

            // Http client for Yarp.

            var httpMessageInvoker = new HttpMessageInvoker(new SocketsHttpHandler()
            {
                UseProxy               = false,
                AllowAutoRedirect      = false,
                AutomaticDecompression = DecompressionMethods.None,
                UseCookies             = false
            });

            services.AddSingleton(httpMessageInvoker);

            // Cookie encryption cipher.

            var aesCipher = new AesCipher(NeonSsoSessionProxyService.GetEnvironmentVariable("COOKIE_CIPHER", AesCipher.GenerateKey(), redacted: !NeonSsoSessionProxyService.Log.IsLogDebugEnabled));

            services.AddSingleton(aesCipher);

            var cacheOptions = new DistributedCacheEntryOptions()
            {
                AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(15)
            };

            services.AddSingleton(cacheOptions);

            services.AddSingleton <SessionTransformer>(
                serviceProvider =>
            {
                return(new SessionTransformer(serviceProvider.GetService <IDistributedCache>(), aesCipher, dexClient, NeonSsoSessionProxyService.Log, cacheOptions));
            });

            services.AddControllers()
            .AddNeon();
        }