Exemple #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddScoped <WebAppDataContext>(provider => new WebAppDataContext(provider.GetService <IConfiguration>()));
            services.AddIdentity <ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores <WebAppDataContext>()
            .AddDefaultTokenProviders();

            services.ConfigureApplicationCookie(options => {
                options.LoginPath = "/Account/LogIn";
                // options.Cookie.Name = ".AuthCookie";
                options.Cookie.SameSite = SameSiteMode.Strict;
                options.Cookie.HttpOnly = true;
            });

            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme);

            services.AddMvc()
            .AddJsonOptions(options => {
                // Without this contract property names will change useing camelCase.
                options.SerializerSettings.ContractResolver = new DefaultContractResolver();
            });

            // Add application services.
            services.AddTransient <IEmailSender, AuthMessageSender>();
            services.AddTransient <ISmsSender, AuthMessageSender>();

            // Configure dependency abstructor.
            _di = services.UseMicrosoftDI(_serviceProvider);
            _di.AddSingletone(_configuration);
            //services.AddSingleton(typeof(IConfiguration), _configuration);
            _di.AddSingletone(_di);

            // Start registering services.
            _di.RegisterStorageServices(_hostingEnvironment);
            _di.RegisterMediaDataContextServices();
            _di.RegisterCoreServices();
            // End registering services.
        }
Exemple #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddAuthentication("MyAuth")
            .AddScheme <MyAuthSchemeOptions, MyAuthenticationHandler>("MyAuth", options => {
                var authSettings = _di.Resolve <IOptions <AuthSettings> >().Value;
                options.Scheme   = "MyAuth";
                options.AccessTokenKeyHeaderName  = authSettings.AccessTokenHeaderName;
                options.SessionInfoContextKeyName = authSettings.SessionInfoContextKeyName;
                options.Expiration = new TimeSpan((authSettings.ExpirationInMin - authSettings.ExpirationInMin % 60) / 60,
                                                  authSettings.ExpirationInMin % 60, 0);
            });

            services.AddMvc();
            services.AddMemoryCache();

            // Configure settings.
            services.AddOptions();
            services.Configure <GoogleDriveSettings>(_configuration.GetSection("MediaStorage:GoogleDrive"));
            services.Configure <LocalDriveSettings>(_configuration.GetSection("MediaStorage:Local"));
            services.Configure <AuthSettings>(_configuration.GetSection("Auth"));

            // Configure dependency abstructor.
            _di = services.UseMicrosoftDI(_serviceProvider);
            _di.AddSingletone(_configuration);
            _di.AddSingletone(_di);
            _di.AddPerThread <AuthenticationHandler <MyAuthSchemeOptions>, MyAuthenticationHandler>();

            // Start registering services.
            _di.RegisterStorageServices(_hostingEnvironment);
            _di.RegisterMediaDataContextServices();
            _di.RegisterStreamingDataContextServices();
            _di.RegisterCoreServices();
            // End registering services.

            return(_di.Build());
        }