Пример #1
0
        public void ConfigureServices(IServiceCollection services)
        {
            RepositoriesModule.RegisterDependencies(services, Configuration);
            ServicesModule.RegisterDependencies(services);

            services.AddCors(options =>
            {
                options.AddPolicy(RestaurantRaterPolicy, builder =>
                {
                    builder.WithOrigins("http://localhost:4200")
                    .AllowAnyHeader()
                    .AllowAnyMethod();
                });
            });

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options =>
            {
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ClockSkew                = TimeSpan.Zero,
                    ValidateIssuer           = true,
                    ValidateAudience         = true,
                    ValidateLifetime         = true,
                    ValidateIssuerSigningKey = true,
                    ValidIssuer              = Configuration["Jwt:Issuer"],
                    ValidAudience            = Configuration["Jwt:Issuer"],
                    IssuerSigningKey         = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:Secret"]))
                };
            });

            services.AddHttpContextAccessor();

            services.AddControllers().AddNewtonsoftJson(options =>
            {
                options.SerializerSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc;
                options.SerializerSettings.DateFormatString     = "yyyy-MM-dd HH:mm:ss";
            });
        }
Пример #2
0
        public void ConfigureServices(IServiceCollection services)
        {
            RepositoriesModule.RegisterDependencies(services, Configuration);
            ServicesModule.RegisterDependencies(services);

            services.AddCors(options =>
            {
                options.AddPolicy(BudgetPolicy, builder =>
                {
                    builder.WithOrigins("http://localhost:4200")
                    .AllowAnyHeader()
                    .AllowCredentials()
                    .AllowAnyMethod();
                });
            });

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options =>
            {
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ClockSkew                = TimeSpan.Zero,
                    ValidateIssuer           = true,
                    ValidateAudience         = true,
                    ValidateLifetime         = true,
                    ValidateIssuerSigningKey = true,
                    ValidIssuer              = Configuration["Jwt:Issuer"],
                    ValidAudience            = Configuration["Jwt:Issuer"],
                    IssuerSigningKey         = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:Secret"]))
                };
            });

            services.AddHttpContextAccessor();

            services.AddControllers().AddJsonOptions(options =>
            {
                options.JsonSerializerOptions.Converters.Add(new DateTimeConverter());
            });
        }
Пример #3
0
        public void ConfigureServices(IServiceCollection services)
        {
            SystemModule.RegisterDependencies(services);
            RepositoriesModule.RegisterDependencies(services, Configuration);
            ServicesModule.RegisterDependencies(services);

            services.AddAuthorization(options =>
            {
                // Categories
                options.AddPolicy(AccountPermissions.Categories.View, builder =>
                {
                    builder.AddRequirements(new AccountPermissionRequirement(AccountPermissions.Categories.View));
                });

                options.AddPolicy(AccountPermissions.Categories.Add, builder =>
                {
                    builder.AddRequirements(new AccountPermissionRequirement(AccountPermissions.Categories.Add));
                });

                options.AddPolicy(AccountPermissions.Categories.Edit, builder =>
                {
                    builder.AddRequirements(new AccountPermissionRequirement(AccountPermissions.Categories.Edit));
                });

                options.AddPolicy(AccountPermissions.Categories.Delete, builder =>
                {
                    builder.AddRequirements(new AccountPermissionRequirement(AccountPermissions.Categories.Delete));
                });

                // Invitations
                options.AddPolicy(AccountPermissions.Invitations.View, builder =>
                {
                    builder.AddRequirements(new AccountPermissionRequirement(AccountPermissions.Invitations.View));
                });

                options.AddPolicy(AccountPermissions.Invitations.Add, builder =>
                {
                    builder.AddRequirements(new AccountPermissionRequirement(AccountPermissions.Invitations.Add));
                });

                options.AddPolicy(AccountPermissions.Invitations.Edit, builder =>
                {
                    builder.AddRequirements(new AccountPermissionRequirement(AccountPermissions.Invitations.Edit));
                });

                options.AddPolicy(AccountPermissions.Invitations.Delete, builder =>
                {
                    builder.AddRequirements(new AccountPermissionRequirement(AccountPermissions.Invitations.Delete));
                });

                // Tags
                options.AddPolicy(AccountPermissions.Tags.View, builder =>
                {
                    builder.AddRequirements(new AccountPermissionRequirement(AccountPermissions.Tags.View));
                });

                options.AddPolicy(AccountPermissions.Tags.Add, builder =>
                {
                    builder.AddRequirements(new AccountPermissionRequirement(AccountPermissions.Tags.Add));
                });

                options.AddPolicy(AccountPermissions.Tags.Edit, builder =>
                {
                    builder.AddRequirements(new AccountPermissionRequirement(AccountPermissions.Tags.Edit));
                });

                options.AddPolicy(AccountPermissions.Tags.Delete, builder =>
                {
                    builder.AddRequirements(new AccountPermissionRequirement(AccountPermissions.Tags.Delete));
                });

                // Transactions
                options.AddPolicy(AccountPermissions.Transactions.View, builder =>
                {
                    builder.AddRequirements(new AccountPermissionRequirement(AccountPermissions.Transactions.View));
                });

                options.AddPolicy(AccountPermissions.Transactions.Add, builder =>
                {
                    builder.AddRequirements(new AccountPermissionRequirement(AccountPermissions.Transactions.Add));
                });

                options.AddPolicy(AccountPermissions.Transactions.Edit, builder =>
                {
                    builder.AddRequirements(new AccountPermissionRequirement(AccountPermissions.Transactions.Edit));
                });

                options.AddPolicy(AccountPermissions.Transactions.Delete, builder =>
                {
                    builder.AddRequirements(new AccountPermissionRequirement(AccountPermissions.Transactions.Delete));
                });

                // Account
                options.AddPolicy(AccountPermissions.Account.View, builder =>
                {
                    builder.AddRequirements(new AccountPermissionRequirement(AccountPermissions.Account.View));
                });

                options.AddPolicy(AccountPermissions.Account.Edit, builder =>
                {
                    builder.AddRequirements(new AccountPermissionRequirement(AccountPermissions.Account.Edit));
                });

                options.AddPolicy(AccountPermissions.Account.Delete, builder =>
                {
                    builder.AddRequirements(new AccountPermissionRequirement(AccountPermissions.Account.Delete));
                });

                // Account users
                options.AddPolicy(AccountPermissions.AccountUsers.View, builder =>
                {
                    builder.AddRequirements(new AccountPermissionRequirement(AccountPermissions.AccountUsers.View));
                });

                options.AddPolicy(AccountPermissions.AccountUsers.Delete, builder =>
                {
                    builder.AddRequirements(new AccountPermissionRequirement(AccountPermissions.AccountUsers.Delete));
                });
            });

            services.AddCors(options =>
            {
                options.AddPolicy(BudgetManagerPolicy, builder =>
                {
                    builder.WithOrigins("http://localhost:4200")
                    .AllowAnyHeader()
                    .AllowAnyMethod();
                });
            });

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options =>
            {
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ClockSkew                = TimeSpan.Zero,
                    ValidateIssuer           = true,
                    ValidateAudience         = true,
                    ValidateLifetime         = true,
                    ValidateIssuerSigningKey = true,
                    ValidIssuer              = Configuration["Jwt:Issuer"],
                    ValidAudience            = Configuration["Jwt:Issuer"],
                    IssuerSigningKey         = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:Secret"]))
                };
            });

            services.AddHttpContextAccessor();

            services.AddControllers().AddNewtonsoftJson(options =>
            {
                options.SerializerSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc;
                options.SerializerSettings.DateFormatString     = "yyyy-MM-dd";
            });
        }