public UserService(IApiService api,
                    IHttpContextAccessor accessor, AliseeksJwtAuthentication auth)
 {
     this.auth = auth;
     this.api  = api;
     context   = accessor.HttpContext;
 }
Esempio n. 2
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(LogLevel.Warning);

            app.UseMiddleware <ExceptionHandler>();

            app.ApplyApiLogging();

            //Configure Hangfire
            app.UseHangfireServer();
            app.UseHangfireDashboard();

            var jwtOptions = app.ApplicationServices.GetService <IOptions <JwtOptions> >().Value;

            app.UseJwtBearerAuthentication(new JwtBearerOptions()
            {
                AutomaticAuthenticate     = true,
                AutomaticChallenge        = true,
                AuthenticationScheme      = JwtBearerDefaults.AuthenticationScheme,
                TokenValidationParameters = AliseeksJwtAuthentication.TokenValidationParameters(jwtOptions.SecretKey)
            });

            app.UseMvc();

            Jobs.JobScheduler.ScheduleJobs();
        }
Esempio n. 3
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();

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

            var options = app.ApplicationServices.GetService <IOptions <JwtOptions> >().Value;

            app.UseCookieAuthentication(new CookieAuthenticationOptions()
            {
                AutomaticAuthenticate = true,
                AutomaticChallenge    = true,
                AuthenticationScheme  = "AliseeksCookie",
                CookieName            = "access_token",
                TicketDataFormat      = new AliseeksJwtCookieAuthentication(AliseeksJwtAuthentication.TokenValidationParameters(options.SecretKey), app.ApplicationServices.GetRequiredService <IRavenClient>()),
                LoginPath             = "/login",
                LogoutPath            = "/logout"
            });

            app.UseStaticFiles(new StaticFileOptions()
            {
                OnPrepareResponse = (context) =>
                {
                    //Setup caching of static files
                    var headers          = context.Context.Response.GetTypedHeaders();
                    headers.CacheControl = new CacheControlHeaderValue()
                    {
                        MaxAge = TimeSpan.FromDays(7)
                    };
                }
            });

            app.UseSession();

            app.UseMiddleware <Logger>();



            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
Esempio n. 4
0
        public UserServiceTests()
        {
            var jwtOptions = new JwtOptions()
            {
                SecretKey = "notsosecrettestkeyofcoursedontuse"
            };

            hasher    = new SecurityHasher();
            dbMock    = new Mock <IUsersPostgres>();
            emailMock = new Mock <IEmailService>();
            auth      = new AliseeksJwtAuthentication(new Microsoft.Extensions.Options.OptionsWrapper <JwtOptions>(jwtOptions), new FakeRavenClient().Object);

            service = new UserService(auth, dbMock.Object, hasher, emailMock.Object, new FakeRavenClient().Object, null);
        }