コード例 #1
0
ファイル: UserSessionStoreTests.cs プロジェクト: alexis-/BFF
        public UserSessionStoreTests()
        {
            var services = new ServiceCollection();

            services.AddBff()
            .AddEntityFrameworkServerSideSessions(options => options.UseInMemoryDatabase(Guid.NewGuid().ToString()));
            var provider = services.BuildServiceProvider();

            _subject  = provider.GetRequiredService <IUserSessionStore>();
            _database = provider.GetRequiredService <SessionDbContext>();
        }
コード例 #2
0
        protected static ISessionService GetSessionService(SettingsSource source)
        {
            ISessionService sessionService;

            switch (source)
            {
            case SettingsSource.Database:
                DbContext dbContext = new SessionDbContext("name=FrameworkConfigDb");
                IRepository <Session, Guid>    repository = new Repository <Session, Guid>(dbContext);
                IObjectService <Session, Guid> service    = new ObjectService <Session, Guid>(repository);
                sessionService = new SessionService(service);
                break;

            case SettingsSource.File:
                sessionService = SessionsManager.ConsumerSessionService;
                break;

            default:
                sessionService = SessionsManager.ConsumerSessionService;
                break;
            }

            return(sessionService);
        }
コード例 #3
0
        public static ISessionService CreateSessionService()
        {
            ISessionService sessionService;
            string          frameworkConfigSource =
                System.Configuration.ConfigurationManager.AppSettings["demo.frameworkConfigSource"];

            if ("Database".Equals(frameworkConfigSource, StringComparison.InvariantCultureIgnoreCase))
            {
                DbContext dbContext = new SessionDbContext("name=FrameworkConfigDb");
                IRepository <Session, Guid>    repository = new Repository <Session, Guid>(dbContext);
                IObjectService <Session, Guid> service    = new ObjectService <Session, Guid>(repository);
                sessionService = new SessionService(service);
            }
            else if ("File".Equals(frameworkConfigSource, StringComparison.InvariantCultureIgnoreCase))
            {
                sessionService = SessionsManager.ProviderSessionService;
            }
            else
            {
                sessionService = SessionsManager.ProviderSessionService;
            }

            return(sessionService);
        }
コード例 #4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            #region CORS
            app.UseCors(builder => builder.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin().AllowCredentials());
            //app.UseCors("CorsPolicy");
            #endregion

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseIdentity();

            // Temp not working
            app.UseGoogleAuthentication(new GoogleOptions()
            {
                ClientId     = Configuration.GetSection("Authentication")["Google:ClientId"].ToString(),
                ClientSecret = Configuration.GetSection("Authentication")["Google:ClientSecret"].ToString()
            });
#if DEBUG
            clientURL = Configuration.GetSection("ClientURL")["local"].ToString();
#endif
#if RELEASE
            clientURL = Configuration.GetSection("ClientURL")["cloud"].ToString();
#endif

            _sessionDbcontext = new SessionDbContext(Configuration);

            // Add external authentication middleware below. To configure them please see https://go.microsoft.com/fwlink/?LinkID=532715

            // Source: https://stormpath.com/blog/token-authentication-asp-net-core
            string secretKey = Configuration.GetSection("TokenConfiguration")["SecretKey"].ToString();
            SymmetricSecurityKey signingKey         = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(secretKey));
            SigningCredentials   signingCredentials = new SigningCredentials(signingKey, SecurityAlgorithms.HmacSha256);
            //---
            const string audience = "Audience";
            const string issuer   = "Issuer";
            //---
            TokenValidationParameters tokenValidationParameters = new TokenValidationParameters
            {
                ValidateIssuerSigningKey = true,
                IssuerSigningKey         = signingKey,

                ValidateIssuer = false,
                ValidIssuer    = issuer,

                ValidateAudience = true,
                ValidAudience    = audience,

                ValidateLifetime = true,

                ClockSkew          = TimeSpan.Zero,
                AuthenticationType = JwtBearerDefaults.AuthenticationScheme
            };
            app.UseJwtBearerAuthentication(new JwtBearerOptions
            {
                AutomaticAuthenticate     = true,
                AutomaticChallenge        = true,
                TokenValidationParameters = tokenValidationParameters,
                AuthenticationScheme      = JwtBearerDefaults.AuthenticationScheme,
            });


            var options = new TokenProviderOptions
            {
                SigningCredentials = new SigningCredentials(signingKey, SecurityAlgorithms.HmacSha256Signature),
            };

            app.UseMiddleware <TokenProviderMiddleware>(Options.Create(options));


            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
コード例 #5
0
 public UserSessionStore(IOptions <DataProtectionOptions> options, SessionDbContext sessionDbContext, ILogger <UserSessionStore> logger)
 {
     _applicationDiscriminator = options.Value.ApplicationDiscriminator;
     _sessionDbContext         = sessionDbContext;
     _logger = logger;
 }