public AuthenticationController(IUserService userService,
                                 IConfiguration configuration,
                                 ISteamIdConverter SteamIdConverter,
                                 HttpClient httpClient,
                                 ValidationTokenParameters validationParameters)
 {
     this.userService          = userService;
     this.configuration        = configuration;
     this.SteamIdConverter     = SteamIdConverter;
     this.httpClient           = httpClient;
     this.validationParameters = validationParameters;
 }
Beispiel #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <DataContext>(x => x.UseInMemoryDatabase("TestDb"));

            services.AddCors();

            services.AddAuthorization(options =>
            {
                options.AddPolicy("UserOnly", policy => policy.RequireRole("User"));
            });

            ValidationTokenParameters validationParameters = new ValidationTokenParameters(Configuration);

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                options.RequireHttpsMetadata      = false;
                options.SaveToken                 = false;
                options.TokenValidationParameters = validationParameters.GetTokenValidationParameters();
            });

            services.AddMvc();

            Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <UserDto, User>().ForMember(m => m.Roles, opt => opt.Ignore());
                cfg.CreateMap <SingleItemDto, Item>();
            });

            services.AddScoped <IUserService, UserService>();
            services.AddScoped <ISteamIdConverter, SteamIdConverter>();
            services.AddSingleton(Configuration);
            services.AddScoped <HttpClient>();
            services.AddSingleton(validationParameters);
            services.AddScoped <IAdminItemsService, AdminItemsService>();
            services.AddScoped <IItemsService, ItemsService>();
        }