Exemplo 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.AddHttpContextAccessor();
            var connectionString = Configuration.GetConnectionString("LampShade");

            ShopManagementBootstrapper.Configuration(services, connectionString);
            DiscountManagementBootstrapper.Configuration(services, connectionString);
            InventoryManagementBootstrapper.Configuration(services, connectionString);
            BlogManagementBootstrapper.Configuration(services, connectionString);
            CommentManagementBootstrapper.Configuration(services, connectionString);
            AccountManagementBootstrapper.Configuration(services, connectionString);

            services.AddSingleton(HtmlEncoder.Create(UnicodeRanges.BasicLatin, UnicodeRanges.Arabic));
            services.AddSingleton <IPasswordHasher, PasswordHasher>();
            services.AddTransient <IAuthHelper, AuthHelper>();
            services.AddTransient <IZarinPalFactory, ZarinPalFactory>();
            services.AddTransient <ISmsService, SmsService>();
            services.AddTransient <IEmailService, EmailService>();

            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, o =>
            {
                o.LoginPath        = "/Account";
                o.LogoutPath       = "/Account/Logout";
                o.AccessDeniedPath = new PathString("/AccessDenied");
                o.ExpireTimeSpan   = TimeSpan.FromMinutes(43200);
            });

            services.AddRazorPages().
            AddApplicationPart(typeof(InventoryController).Assembly);
            // AddNewtonsoftJson();
        }
Exemplo n.º 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddHttpContextAccessor();

            var connectionString = Configuration.GetConnectionString("OHaidariehDb");

            HaidariehBootstrapper.Configure(services, connectionString);
            AccountManagementBootstrapper.Configure(services, connectionString);

            services.AddSingleton(HtmlEncoder.Create(UnicodeRanges.BasicLatin, UnicodeRanges.Arabic));
            services.AddSingleton <IPasswordHasher, PasswordHasher>();
            services.AddTransient <IFileUploader, FileUploader>();
            services.AddTransient <IAuthHelper, AuthHelper>();
            services.AddTransient <IEmailService, EmailService>();
            services.AddTransient <ISmsService, SmsService>();
            services.AddKendo();



            services.Configure <CookiePolicyOptions>(options =>
            {
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.Lax;
            });

            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, o =>
            {
                o.LoginPath        = new PathString("/Account");
                o.LogoutPath       = new PathString("/Account");
                o.AccessDeniedPath = new PathString("/AccessDenied");
            });
            services.AddAuthorization(options =>
            {
                options.AddPolicy("AdminArea",
                                  builder => builder.RequireRole(new List <string> {
                    Roles.Admin, Roles.Engineer
                }));
                options.AddPolicy("Ceremony",
                                  builder => builder.RequireRole(new List <string> {
                    Roles.Admin, Roles.Engineer
                }));
                options.AddPolicy("UserMng",
                                  builder => builder.RequireRole(new List <string> {
                    Roles.Admin
                }));
            });

            services.AddRazorPages()
            .AddMvcOptions(options => options.Filters.Add <SecurityPageFilter>())
            .AddRazorPagesOptions(options =>
            {
                options.Conventions.AuthorizeAreaFolder("Admin", "/", "AdminArea");
                options.Conventions.AuthorizeAreaFolder("Admin", "/Ceremonies", "Ceremony");
                options.Conventions.AuthorizeAreaFolder("Admin", "/Accounts", "UserMng");
                options.Conventions.AuthorizeAreaFolder("Admin", "/Roles", "UserMng");
            });
            //services.AddRazorPages();
        }
Exemplo n.º 3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddRazorPages().AddMvcOptions(x => x.Filters.Add <SecurityPageFilter>()).AddRazorRuntimeCompilation().AddRazorPagesOptions(x =>
            {
                x.Conventions.AuthorizeAreaFolder("Admin", "/", "AdminArea");
                x.Conventions.AuthorizeAreaFolder("Admin", "/Discount", "Discounts");
                x.Conventions.AuthorizeAreaFolder("Admin", "/Accounts", "Accounts");
            });
            services.AddHttpContextAccessor();

            services.Configure <CookiePolicyOptions>(options =>
            {
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = Microsoft.AspNetCore.Http.SameSiteMode.Strict;
            });

            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options =>
            {
                options.LoginPath        = new PathString("/Account");
                options.LogoutPath       = new PathString("/Account");
                options.AccessDeniedPath = new PathString("/AccessDenied");
            });

            services.AddAuthorization(options =>
            {
                options.AddPolicy("AdminArea", builder => builder.RequireRole(new List <string> {
                    Roles.Admin, Roles.Operator
                }));
                options.AddPolicy("Discounts", builder => builder.RequireRole(new List <string> {
                    Roles.Admin
                }));
                options.AddPolicy("Accounts", builder => builder.RequireRole(new List <string> {
                    Roles.Admin
                }));
            });

            var connectionString = Configuration.GetConnectionString("ShopConnectionString");

            ShopManagementBootstraper.Configure(services, connectionString);
            DiscountManagementBootstrapper.Configure(services, connectionString);
            InventoryManagementBootstrapper.Configure(services, connectionString);
            AccountManagementBootstrapper.Configure(services, connectionString);

            services.AddTransient <IFileUploader, FileUploader>();
            services.AddSingleton <IPasswordHasher, PasswordHasher>();
            services.AddSingleton <IAuthHelper, AuthHelper>();
        }
Exemplo n.º 4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //services.Configure<CookiePolicyOptions>(options =>
            //{
            //    options.CheckConsentNeeded = context => true;
            //    options.MinimumSameSitePolicy = SameSiteMode.Lax;
            //});

            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, o =>
            {
                o.LoginPath        = new PathString("/Account");
                o.LogoutPath       = new PathString("/Account");
                o.AccessDeniedPath = new PathString("/AccessDenied");
            });


            services.AddHttpContextAccessor();

            var ConnectionString = Configuration.GetConnectionString("EShopDB");

            #region IOC

            ShopManagementBootstrapper.Configure(services, ConnectionString);
            DiscountManagemantBootstrapper.Configure(services, ConnectionString);
            InventoryManagemantBootstrapper.Configure(services, ConnectionString);
            blogManagementBootstrapper.Configure(services, ConnectionString);
            AccountManagementBootstrapper.Configure(services, ConnectionString);

            services.AddTransient <IFileUploader, FileUploade>();
            services.AddTransient <IAuthHelper, AuthHelper>();
            #endregion



            services.AddSingleton(
                HtmlEncoder.Create(UnicodeRanges.BasicLatin, UnicodeRanges.Arabic));


            services.AddRazorPages();
        }
Exemplo n.º 5
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddHttpContextAccessor();
            var connectionString = Configuration.GetConnectionString("LampshadeDb");

            ShopManagementBootstrapper.Configure(services, connectionString);
            DiscountManagementBootstrapper.Configure(services, connectionString);
            InventoryManagementBootstrapper.Configure(services, connectionString);
            BlogManagementBootstrapper.Configure(services, connectionString);
            CommentManagementBootstrapper.Configure(services, connectionString);
            AccountManagementBootstrapper.Configure(services, connectionString);

            services.AddSingleton(HtmlEncoder.Create(UnicodeRanges.BasicLatin, UnicodeRanges.Arabic));
            services.AddSingleton <IPasswordHasher, PasswordHasher>();
            services.AddTransient <IFileUploader, FileUploader>();
            services.AddTransient <IAuthHelper, AuthHelper>();
            services.AddTransient <IZarinPalFactory, ZarinPalFactory>();
            services.AddTransient <ISmsService, SmsService>();
            services.AddTransient <IEmailService, EmailService>();

            services.Configure <CookiePolicyOptions>(options =>
            {
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.Lax;
            });

            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, o =>
            {
                o.LoginPath        = new PathString("/Account");
                o.LogoutPath       = new PathString("/Account");
                o.AccessDeniedPath = new PathString("/AccessDenied");
            });

            services.AddAuthorization(options =>
            {
                options.AddPolicy("AdminArea",
                                  builder => builder.RequireRole(new List <string> {
                    Roles.Administrator, Roles.ContentUploader
                }));

                options.AddPolicy("Shop",
                                  builder => builder.RequireRole(new List <string> {
                    Roles.Administrator
                }));

                options.AddPolicy("Discount",
                                  builder => builder.RequireRole(new List <string> {
                    Roles.Administrator
                }));

                options.AddPolicy("Account",
                                  builder => builder.RequireRole(new List <string> {
                    Roles.Administrator
                }));
            });

            services.AddCors(options => options.AddPolicy("MyPolicy", builder =>
                                                          builder
                                                          .WithOrigins("https://localhost:5002")
                                                          .AllowAnyHeader()
                                                          .AllowAnyMethod()));

            services.AddRazorPages()
            .AddMvcOptions(options => options.Filters.Add <SecurityPageFilter>())
            .AddRazorPagesOptions(options =>
            {
                options.Conventions.AuthorizeAreaFolder("Administration", "/", "AdminArea");
                options.Conventions.AuthorizeAreaFolder("Administration", "/Shop", "Shop");
                options.Conventions.AuthorizeAreaFolder("Administration", "/Discounts", "Discount");
                options.Conventions.AuthorizeAreaFolder("Administration", "/Accounts", "Account");
            })
            .AddApplicationPart(typeof(ProductController).Assembly)
            .AddApplicationPart(typeof(InventoryController).Assembly)
            .AddNewtonsoftJson();
        }
Exemplo n.º 6
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddHttpContextAccessor();

            var connectionString = Configuration.GetConnectionString("LampshadeDb");

            ShopMangementBootstrapper.Configure(services, connectionString);
            DiscountManagementBootStrapper.Configure(services, connectionString);
            InventoryManagementBootstrapper.Configure(services, connectionString);
            BlogManagementBootstrapper.Configure(services, connectionString);
            CommentManagementBootstrapper.Configure(services, connectionString);
            AccountManagementBootstrapper.Configure(services, connectionString);


            services.AddSingleton(HtmlEncoder.Create(UnicodeRanges.BasicLatin, UnicodeRanges.Arabic));


            services.AddSingleton <IPasswordHasher, PasswordHasher>();
            services.AddTransient <IFileUploader, FileUploader>();
            services.AddTransient <IAuthHelper, AuthHelper>();
            services.AddTransient <IZarinPalFactory, ZarinPalFactory>();



            services.Configure <CookiePolicyOptions>(options =>
            {
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.Lax;
            });

            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, o =>
            {
                o.LoginPath        = new PathString("/Account");
                o.LogoutPath       = new PathString("/Account");
                o.AccessDeniedPath = new PathString("/AccessDenied");
            });


            services.AddAuthorization(options =>
            {
                options.AddPolicy("AdminArea",
                                  builder => builder.RequireRole(new List <string> {
                    Roles.Administrator, Roles.ContentUploader, Roles.AdminAssistant
                }));

                options.AddPolicy("Shop",
                                  builder => builder.RequireRole(new List <string> {
                    Roles.Administrator, Roles.AdminAssistant
                }));

                options.AddPolicy("Discount",
                                  builder => builder.RequireRole(new List <string> {
                    Roles.Administrator, Roles.AdminAssistant
                }));

                options.AddPolicy("Account",
                                  builder => builder.RequireRole(new List <string> {
                    Roles.Administrator, Roles.AdminAssistant
                }));

                options.AddPolicy("Inventory",
                                  builder => builder.RequireRole(new List <string> {
                    Roles.Administrator, Roles.AdminAssistant
                }));
            });


            services.AddRazorPages()
            .AddMvcOptions(options => options.Filters.Add <SecurityPageFilter>())
            .AddRazorPagesOptions(options =>
            {
                options.Conventions.AuthorizeAreaFolder("Adminstration", "/", "AdminArea");
                options.Conventions.AuthorizeAreaFolder("Adminstration", "/Shop", "Shop");
                options.Conventions.AuthorizeAreaFolder("Adminstration", "/Discount", "Discount");
                options.Conventions.AuthorizeAreaFolder("Adminstration", "/Accounts", "Account");
                options.Conventions.AuthorizeAreaFolder("Adminstration", "/Inventory", "Inventory");
            });
        }
Exemplo n.º 7
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddHttpContextAccessor();

            var connectionString = Configuration.GetConnectionString("NavidGhavami_PersonalWebsite");



            PersonalInformationBootstrapper.Configure(services, connectionString);
            BlogManagementBootstrapper.Configure(services, connectionString);
            ProjectBootstrapper.Configure(services, connectionString);
            ServiceBootstrapper.Configure(services, connectionString);
            AccountManagementBootstrapper.Configure(services, connectionString);



            services.AddSingleton(HtmlEncoder.Create(UnicodeRanges.BasicLatin, UnicodeRanges.Arabic));


            services.AddSingleton <IPasswordHasher, PasswordHasher>();
            services.AddTransient <IFileUploader, FileUploader>();
            services.AddTransient <IAuthHelper, AuthHelper>();


            services.Configure <CookiePolicyOptions>(options =>
            {
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.Lax;
            });

            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, o =>
            {
                o.LoginPath        = new PathString("/Account");
                o.LogoutPath       = new PathString("/Account");
                o.AccessDeniedPath = new PathString("/AccessDenied");
            });



            services.AddAuthorization(options =>
            {
                options.AddPolicy("AdminArea",
                                  builder => builder.RequireRole(new List <string> {
                    Roles.Administrator, Roles.ContentUploader
                }));

                options.AddPolicy("PersonalInformation",
                                  builder => builder.RequireRole(new List <string> {
                    Roles.Administrator
                }));

                options.AddPolicy("Projects",
                                  builder => builder.RequireRole(new List <string> {
                    Roles.Administrator
                }));

                options.AddPolicy("Services",
                                  builder => builder.RequireRole(new List <string> {
                    Roles.Administrator
                }));

                options.AddPolicy("Account",
                                  builder => builder.RequireRole(new List <string> {
                    Roles.Administrator
                }));
            });

            services.AddRazorPages()
            .AddRazorPagesOptions(options =>
            {
                options.Conventions.AuthorizeAreaFolder("Administration", "/", "AdminArea");
                options.Conventions.AuthorizeAreaFolder("Administration", "/Accounts", "Account");
                options.Conventions.AuthorizeAreaFolder("Administration", "/PersonalInformation", "PersonalInformation");
                options.Conventions.AuthorizeAreaFolder("Administration", "/Projects", "Projects");
                options.Conventions.AuthorizeAreaFolder("Administration", "/Services", "Services");
            });
        }
Exemplo n.º 8
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddHttpContextAccessor();

            var connectionString = Configuration.GetConnectionString("Auth-JWT");


            // --- Authentication
            var key = Encoding.ASCII.GetBytes("MY_BIG_SECRET_KEY_ASDWQEWEWWEQ@#@!#!@#QWE!@!#!@#!@#!@EWQE!@#!@#!@#QWE!@#!@#@!LKSHDJFLSDKFW@#($)(#)32234");

            services.AddAuthentication(x =>
            {
                x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(x =>
            {
                x.Events = new JwtBearerEvents
                {
                    OnChallenge = context =>
                    {
                        context.Response.OnStarting(async() =>
                        {
                            // Write to the response in any way you wish
                            await context.Response.WriteAsync("You are not authorized! (or some other custom message)");
                        });

                        return(Task.CompletedTask);
                    },
                    OnTokenValidated = context =>
                    {
                        //TODO
                        var claims = context.HttpContext.User.Claims.ToList();

                        return(Task.CompletedTask);
                    }
                };
                x.RequireHttpsMetadata      = false;
                x.SaveToken                 = true;
                x.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(key),
                    ValidateIssuer           = false,
                    ValidateAudience         = false
                };
            });


            // DB Bootstrappers
            AccountManagementBootstrapper.Configure(services, connectionString);


            // Custom Services
            services.AddSingleton(HtmlEncoder.Create(UnicodeRanges.BasicLatin, UnicodeRanges.Arabic));
            services.AddSingleton <IPasswordHasher, PasswordHasher>();
            services.AddTransient <IFileUploader, FileUploader>();
            services.AddTransient <IAuthHelper, AuthHelper>();



            services.AddControllers();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Auth_JWT", Version = "v1"
                });
            });
        }