Ejemplo n.º 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <UserContext>(options =>
                                                options.UseNpgsql("Host=localhost;Database=Nakigoe;Username=postgres;Password=1234"));

            var key = Encoding.ASCII.GetBytes("//TODO: Change me");

            services.AddAuthentication(config =>
            {
                config.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                config.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            }).AddJwtBearer(options =>
            {
                options.RequireHttpsMetadata      = false;
                options.SaveToken                 = true;
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(key),
                    ValidateIssuer           = false,
                    ValidateAudience         = false
                };
            });

            services.AddScoped <IUSerService, UserService>();
            services.AddSingleton <IFileService>(FileServiceFactory.Create(Configuration["ProfilePicDir"]));

            services
            .AddControllers()
            .AddJsonOptions(options => // Output data as is rather than converting it to camel case
                            options.JsonSerializerOptions.PropertyNamingPolicy = null);

            services.AddCors(options =>
                             options.AddPolicy("Disable", builder =>
            {
                builder
                .AllowAnyHeader()
                .AllowAnyMethod()
                .AllowAnyOrigin();
            }));
        }