Beispiel #1
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options =>
     {
         options.LoginPath = "/Account/Login/";
         options.Events.OnRedirectToLogin = context =>
         {
             context.Response.StatusCode = 401;
             return(Task.CompletedTask);
         };
     });
     services.AddCors(Options =>
     {
         Options.AddPolicy("CorsDevPolicy", builder =>
         {
             builder
             .AllowAnyOrigin()
             .AllowAnyHeader()
             .AllowAnyMethod()
             .AllowCredentials();
         });
     });
     services.AddMvc();
     services.AddTransient <IDbConnection>(x => CreateDBContext());
     services.AddTransient <UserRepository>();
     services.AddTransient <VaultRepository>();
     services.AddTransient <KeepsRepository>();
     services.AddTransient <VaultKeepsRepository>();
 }
Beispiel #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Configure appsettings to use IOptions pattern
            services.Configure <AppConfig>(Configuration.GetSection("AppConfig"));

            string connectionString = Configuration.GetConnectionString("DefaultConnection");

            // Use DB context pooling to improve performance
            services.AddDbContextPool <AppDbContext>(options => options.UseSqlServer(connectionString));
            services.AddTransient <ResponseFactory>();
            services.AddScoped(typeof(ICommandRepository <>), typeof(CommandRepository <>));
            services.AddTransient <ICheapPaymentGateway, CheapPaymentGateway>();
            services.AddTransient <IExpensivePaymentGateway, ExpensivePaymentGateway>();
            services.AddTransient <IPaymentService, PaymentService>();
            services.AddControllers();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Filed.Payment", Version = "v1"
                });
            });

            // Set CORS policy
            services.AddCors(Options =>
            {
                Options.AddPolicy("CorsPolicy",
                                  builder =>
                                  builder
                                  .WithOrigins("https://filed.payment.com")
                                  .AllowAnyOrigin()
                                  .AllowAnyMethod()
                                  .AllowAnyHeader()
                                  );
            });
        }
Beispiel #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
            services.AddApiVersioning(o =>
            {
                o.ReportApiVersions = true;
                o.DefaultApiVersion = new ApiVersion(1, 0);
            });

            //Adding Swagger Generator
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "My API", Version = "v1"
                });
            });

            //Adding CORS
            // services.AddCors();
            services.AddCors(Options =>
            {
                Options.AddPolicy(MyAllowSpecificOrigins, builder =>
                                  builder.AllowAnyOrigin()
                                  .AllowAnyHeader()
                                  .AllowAnyMethod()
                                  );
            });
        }
Beispiel #4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <CurrentPriceContext>(
                Options => Options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            // Add framework services.
            services.AddCors(Options =>
            {
                Options.AddPolicy("AllowAnyOrigin",
                                  builder => builder
                                  .AllowAnyOrigin()
                                  .AllowAnyMethod()
                                  .AllowAnyHeader()
                                  );
            });

            services.AddMvc()
            .AddXmlDataContractSerializerFormatters();

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info {
                    Title = "Mining Prediction API Documentation", Version = "v1"
                });
            });
        }
Beispiel #5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            services.AddAuthentication("Bearer")
            .AddJwtBearer("Bearer", Options =>
            {
                Options.Authority = "http://localhost:5000";
                Options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters
                {
                    ValidateAudience = false
                };
                Options.RequireHttpsMetadata = false;
                Options.TokenValidationParameters.ClockSkew             = TimeSpan.FromMinutes(1);
                Options.TokenValidationParameters.RequireExpirationTime = true;
            });

            services.AddAuthorization(Options =>
            {
                Options.AddPolicy("ApiScope", policy =>
                {
                    policy.RequireAuthenticatedUser();
                    policy.RequireClaim("scope", "api1");
                });
            });
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton <IConfiguration>(
                new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile($"appsettings.json")
                .Build()
                );

            #region Add DbContext

            services.AddApplicationDbContext(Configuration);
            services.AddScoped(typeof(IGenericRepository <>), typeof(GenericRepository <>));

            #endregion

            #region Application Services

            services.AddScoped <IUserService, UserService>();
            services.AddScoped <ISliderService, SliderService>();
            services.AddScoped <IProductService, ProductService>();
            services.AddScoped <IPasswordHelper, PasswordHelper>();
            services.AddScoped <IOrderService, OrderService>();
            //services.AddScoped<IMailSender, SendEmail>();
            //services.AddScoped<IViewRenderService, RenderViewToString>();

            #endregion

            #region Authentication

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer           = true,
                    ValidateAudience         = false,
                    ValidateLifetime         = true,
                    ValidateIssuerSigningKey = true,
                    ValidIssuer      = "https://localhost:44318",
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("MohammadSTEshopJwtBearer"))
                };
            });

            #endregion

            #region CORS

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

            #endregion

            services.AddApplicationDbContext(Configuration);

            services.AddControllers();
        }
Beispiel #7
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <OutletContext>
                (options => options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection")));

            services.AddControllers();


            services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
            // services.AddScoped<IOutletRepo, MockOutletRepo>();

            services.AddScoped <IOutletRepo, OutletDataRepo>();
            services.AddCors(c =>
            {
                c.AddPolicy("AllowOrigin", options => options.AllowAnyOrigin());
            });


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



            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "WebsiteAPI", Version = "v1"
                });
            });
        }
Beispiel #8
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var ConnectionString = @"Data Source=DESKTOP-JLDRL27\SQL2014;Initial Catalog=Map;Integrated Security=True";

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
            services.AddDbContext <MapDbContext>(options => options.UseSqlServer(ConnectionString));
            services.AddDbContext <UserDbContext>(options => options.UseSqlServer(ConnectionString));
            services.AddIdentity <IdentityUser, IdentityRole>().AddEntityFrameworkStores <UserDbContext>();
            services.AddCors(Options => Options.AddPolicy("Cors", builder =>
            {
                builder
                .AllowAnyOrigin()
                .AllowAnyHeader()
                .AllowAnyMethod();
            }));
            var signingKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("This is secret phrase"));

            services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            }).AddJwtBearer(cfg =>
            {
                cfg.RequireHttpsMetadata      = false;
                cfg.SaveToken                 = true;
                cfg.TokenValidationParameters = new TokenValidationParameters()
                {
                    IssuerSigningKey         = signingKey,
                    ValidateAudience         = false,
                    ValidateIssuer           = false,
                    ValidateLifetime         = false,
                    ValidateIssuerSigningKey = true
                };
            });
        }
Beispiel #9
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });


            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);


            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(Options =>
            {
                //Options.AccessDeniedPath = "/Index/Home";
                Options.LoginPath  = "/AspDotNetCoreSecurityManager/ClaimUserIdentity";
                Options.LogoutPath = "/AspDotNetCoreSecurityManager/ClaimUserIdentity";
            }
                       );

            services.AddAuthorization(Options =>
            {
                Options.AddPolicy("RequiredAdminAccess", _policy => _policy.RequireAuthenticatedUser().RequireRole("admin"));
            });

            services.AddAuthorization(Options =>
            {
                Options.AddPolicy("UserAccessible", _policy => _policy.RequireAuthenticatedUser().RequireRole("user"));
            });
        }
Beispiel #10
0
        public static IServiceCollection AddApiConfig(this IServiceCollection services)
        {
            services.AddControllers();

            services.AddApiVersioning(options =>
            {
                options.AssumeDefaultVersionWhenUnspecified = true;
                options.DefaultApiVersion = new ApiVersion(1, 0);
                options.ReportApiVersions = true;
            });

            services.AddVersionedApiExplorer(options =>
            {
                options.GroupNameFormat           = "'v'VVV";
                options.SubstituteApiVersionInUrl = true;
            });

            services.Configure <ApiBehaviorOptions>(options =>
            {
                options.SuppressModelStateInvalidFilter = true;
            });

            services.AddCors(Options =>
            {
                Options.AddPolicy("Development", builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
                Options.AddPolicy("Production", builder => builder.WithMethods("GET").WithOrigins("http://desenvolvedor.io").SetIsOriginAllowedToAllowWildcardSubdomains().AllowAnyHeader());
            });

            return(services);
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
            services.AddDbContext <DbContextSistema>(options =>
                                                     options.UseSqlServer(Configuration.GetConnectionString("Conexion")));
            services.AddCors(Options => {
                Options.AddPolicy(
                    "Todos",
                    builder => builder.WithOrigins("*").WithHeaders("*").WithMethods("*"));
            });

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer           = true,
                    ValidateAudience         = true,
                    ValidateLifetime         = true,
                    ValidateIssuerSigningKey = true,
                    ValidIssuer      = Configuration["Jwt:Issuer"],
                    ValidAudience    = Configuration["Jwt:Issuer"],
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:Key"]))
                };
            });
        }
Beispiel #12
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddResponseCaching();
            services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
            services.AddControllers(
                setupoptions =>
            {
                setupoptions.ReturnHttpNotAcceptable = true;
                setupoptions.CacheProfiles.Add("90SecondsCacheProfile",
                                               new CacheProfile {
                    Duration = 90
                });
            })
            .AddNewtonsoftJson(setupAction => {
                setupAction.SerializerSettings.ContractResolver =
                    new CamelCasePropertyNamesContractResolver();
            })
            .AddXmlDataContractSerializerFormatters();
            services.AddCors(
                Options => {
                Options.AddDefaultPolicy(Builder => Builder.WithOrigins("http://localhost:3000"));
                Options.AddPolicy("mypolicy", Builder => Builder.WithOrigins("http://192.168.1.38:3000"));
            }

                );

            services.AddScoped <IBandAlbumnRepo, BandAlbumnRepo>();
            services.AddScoped <IpropertyValidationService, propertyValidationService>();
            services.AddScoped <IPropertyMappingService, PropertyMappingService>();
            services.AddDbContext <DataContext>(options =>
            {
                options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection"));
            });
        }
Beispiel #13
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(Options => Options.AddPolicy("AllowEverything",
                                                          Builder => Builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()));

            services.AddDbContext <PetAppDBContext>(
                optionsAction: opt =>
            {
                opt.UseSqlite("Data Source=petApp.db");
            }
                );
            services.AddScoped <IPetRepository, PetRepository>();
            services.AddScoped <IPetService, PetService>();
            services.AddControllers();
            services.AddSwaggerGen(option =>
            {
                option.SwaggerDoc("1", new OpenApiInfo
                {
                    Title       = "Swagger PetFood",
                    Description = "Swagger for Petfood",
                    Version     = "V1"
                }
                                  );
            });
        }
Beispiel #14
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
            services.AddDbContext <CatalogContext>(options =>
            {
                options.UseSqlServer(Configuration.GetConnectionString("CatalogContext"));
            }, ServiceLifetime.Scoped);
            services.AddDbContext <IntegrationEventLogContext>(options =>
            {
                options.UseSqlServer(Configuration.GetConnectionString("CatalogContext"),
                                     sqlServerOptionsAction: sqlOptions => sqlOptions.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name));
            }, ServiceLifetime.Scoped);

            RegisterEventBus(services);
            services.AddTransient <ICatalogIntegrationEventService, CatalogIntegrationEventService>();
            services.AddTransient <IIntegrationEventLogService, IntegrationEventLogService>(sp =>
            {
                return(new IntegrationEventLogService(Configuration.GetConnectionString("CatalogContext")));
            });
            services.AddElasticSearch(Configuration);
            services.AddTransient <Models.ISearchRepository <CatalogItem>, Models.ElasticSearchRepository>();
            services.AddCors(Options => { Options.AddPolicy("myPolicy",
                                                            builder =>
                {
                    builder.AllowAnyOrigin()
                    .AllowAnyHeader()
                    .AllowAnyMethod().AllowCredentials();
                }); });
        }
        public void InstallServices(IServiceCollection services, IConfiguration configuration)
        {
            var jwtSettings = new JwtSettings();

            configuration.Bind(nameof(JwtSettings), jwtSettings);
            services.AddSingleton(jwtSettings);


            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            services.AddSwaggerGen(x => {
                x.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo {
                    Title = "Identity API", Version = "v1"
                });
            });
            services.ConfigureSwaggerGen(options => {
            });

            //Enble CORS
            services.AddCors(Options =>
            {
                Options.AddPolicy("EnableCORS", builder =>
                                  builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod().AllowCredentials().Build());
            });
        }
Beispiel #16
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 =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddDbContext <RentKendaraanContext>(options =>
                                                         options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            //service.AddDefaultIdentity<IdentityUser>()
            //  .AddEntityFrameworkStores<RentKendaraanContext>();
            services.AddIdentity <IdentityUser, IdentityRole>().AddDefaultUI()
            .AddEntityFrameworkStores <RentKendaraanContext>().AddDefaultTokenProviders();

            services.AddAuthorization(Options =>
            {
                Options.AddPolicy("readonlypolicy",
                                  builder => builder.RequireRole("Admin", "Manager", "Kasir"));
                Options.AddPolicy("writepolicy",
                                  builder => builder.RequireRole("Admin", "Kasir"));
                Options.AddPolicy("editpolicy",
                                  builder => builder.RequireRole("Admin", "Kasir"));
                Options.AddPolicy("deletepolicy",
                                  builder => builder.RequireRole("Admin", "Kasir"));
            });

            services.AddScoped <Peminjaman>();
        }
Beispiel #17
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(Options => Options.AddPolicy("Cors", builder =>
            {
                builder.AllowAnyOrigin()
                .AllowAnyMethod()
                .AllowAnyHeader();
            }));
            services.AddDbContext <QuizContext>(opt => opt.UseInMemoryDatabase("quiz"));
            services.AddDbContext <UserDbContext>(opt => opt.UseInMemoryDatabase("user"));
            services.AddIdentity <IdentityUser, IdentityRole>().AddEntityFrameworkStores <UserDbContext>();
            var signingKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("this is the secret phrase"));

            services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            }).AddJwtBearer(cfg =>
            {
                cfg.RequireHttpsMetadata      = false;
                cfg.SaveToken                 = true;
                cfg.TokenValidationParameters = new TokenValidationParameters()
                {
                    IssuerSigningKey         = signingKey,
                    ValidateAudience         = false,
                    ValidateIssuer           = false,
                    ValidateLifetime         = false,
                    ValidateIssuerSigningKey = true
                };
            });
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        }
Beispiel #18
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            {
                Options options = new Options();
                Configuration.Bind("Options", options);
                services.AddSingleton(options);
            }

            {
                /*services.AddScoped(sp => new DbContextOptionsBuilder<DataContext>()
                 *  .UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
                 * services.AddScoped(sp => sp.GetRequiredService<DbContextOptionsBuilder<DataContext>>().Options);*/

                services.AddDbContext <DataContext>(options =>
                                                    options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

                services.AddScoped <IPostRepository, AcBlog.Data.Repositories.SQLServer.PostRepository>();
                services.AddScoped <ICategoryRepository, AcBlog.Data.Repositories.SQLServer.CategoryRepository>();
                services.AddScoped <IKeywordRepository, AcBlog.Data.Repositories.SQLServer.KeywordRepository>();
                services.AddScoped <IUserRepository, AcBlog.Data.Repositories.SQLServer.UserRepository>();
            }
            {
                services.AddDbContext <IdentityDbContext>(options =>
                                                          options.UseSqlServer(Configuration.GetConnectionString("IdentityConnection")));

                services.AddDefaultIdentity <ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = false)
                .AddEntityFrameworkStores <IdentityDbContext>();

                services.AddIdentityServer(options =>
                {
                    options.PublicOrigin = Configuration.GetValue <string>("BaseAddress");
                })
                .AddApiAuthorization <ApplicationUser, IdentityDbContext>();

                services.AddAuthentication()
                .AddIdentityServerJwt();
            }

            services.AddControllersWithViews();
            services.AddRazorPages();

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

            services.AddCors(options =>
            {
                options.AddPolicy(DefaultCorsPolicy,
                                  builder =>
                {
                    builder.AllowAnyMethod();
                    builder.AllowAnyHeader();
                    builder.WithOrigins(Configuration.GetSection("Cors").Get <string[]>());
                });
            });
        }
Beispiel #19
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.UseLoggerFactory(DataContext.MyLoggerFactory).UseSqlite(Configuration.GetConnectionString("Default")));
            //AddNewtonsoftJson: use new json format to return, It's slight different than it recently
            services.AddControllers().AddNewtonsoftJson(
                options => {
                options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            }
                );
            //create limitation
            IdentityBuilder builder = services.AddIdentityCore <User> (opt => {
                opt.Password.RequireUppercase       = false;
                opt.Password.RequireNonAlphanumeric = false;
                opt.Password.RequireDigit           = false;
                opt.Password.RequiredLength         = 4;
            });

            //all configuration in Identity
            builder = new IdentityBuilder(builder.UserType, typeof(Role), builder.Services);
            builder.AddEntityFrameworkStores <DataContext> ();
            builder.AddRoleValidator <RoleValidator <Role> > ();
            builder.AddRoleManager <RoleManager <Role> > ();
            builder.AddSignInManager <SignInManager <User> > ();
            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(Options =>
                                                                                            Options.TokenValidationParameters = new TokenValidationParameters {
                ValidateIssuerSigningKey = true,
                IssuerSigningKey         = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(Configuration.GetSection("AppSettings:token").Value)),
                ValidateIssuer           = false,
                ValidateAudience         = false
            }
                                                                                            );

            //add role policy to authorization
            services.AddAuthorization(Options =>
            {
                Options.AddPolicy("RequireAdminRole", policy => policy.RequireRole("Admin"));
                Options.AddPolicy("ModeratePhotoRole", policy => policy.RequireRole("Admin", "Moderator"));
                Options.AddPolicy("VipOnly", policy => policy.RequireRole("VIP"));
            });

            //add authorFilter : by default => this is going to add every Authoriztion in every method
            services.AddControllers(Options => {
                var police = new AuthorizationPolicyBuilder().
                             RequireAuthenticatedUser().Build();
                Options.Filters.Add(new AuthorizeFilter(police));
            }).AddNewtonsoftJson(opt => {
                opt.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
            });

            services.AddCors();
            //auto map content from configuration("X") to <Y>
            services.Configure <CloudinarySettings> (Configuration.GetSection("CloudinarySettings"));
            //what is assembly means? which asembly you are look in for profiles.
            services.AddAutoMapper(typeof(DatingApp.api.Helpers.AutoMapperProfiles).Assembly);
            services.AddScoped <IAuthRepository, AuthRepository> ();
            services.AddScoped <IDatingRepository, DatingRepository> ();
            //add instance in one request
            services.AddScoped <LogUserActivity> ();
        }
Beispiel #20
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(Configuration.GetConnectionString("IdentityContext")));

            services.AddIdentity <ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores <ApplicationDbContext>()
            .AddDefaultTokenProviders();

            services.AddMvc().SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_1);
            services.AddTransient <IProfileService, ProfileService>();
            services.Configure <IISOptions>(iis =>
            {
                iis.AuthenticationDisplayName = "Windows";
                iis.AutomaticAuthentication   = false;
            });

            var builder = services.AddIdentityServer(options =>
            {
                options.Events.RaiseErrorEvents       = true;
                options.Events.RaiseInformationEvents = true;
                options.Events.RaiseFailureEvents     = true;
                options.Events.RaiseSuccessEvents     = true;
            })
                          .AddInMemoryIdentityResources(Config.GetIdentityResources())
                          .AddInMemoryApiResources(Config.GetApis())
                          .AddInMemoryClients(Config.GetClients())
                          .AddAspNetIdentity <ApplicationUser>()
                          .AddProfileService <ProfileService>();

            if (Environment.IsDevelopment())
            {
                builder.AddDeveloperSigningCredential();
            }
            else
            {
                throw new Exception("need to configure key material");
            }

            services.AddAuthentication()
            .AddGoogle(options =>
            {
                // register your IdentityServer with Google at https://console.developers.google.com
                // enable the Google+ API
                // set the redirect URI to http://localhost:5000/signin-google
                options.ClientId     = "copy client ID from Google here";
                options.ClientSecret = "copy client secret from Google here";
            });

            services.AddCors(Options => { Options.AddPolicy("myPolicy",
                                                            corsBuilder =>
                {
                    corsBuilder.AllowAnyOrigin()
                    .AllowAnyHeader()
                    .AllowAnyMethod()
                    .AllowCredentials();
                }); });
        }
Beispiel #21
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddCors(Options =>
     {
         Options.AddPolicy("CorsPolicy",
                           builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().AllowCredentials());
     });
     services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
 }
Beispiel #22
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddControllers();
     services.AddDbContextPool <TaskDbcontext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
     services.AddScoped(typeof(IUnitOfWork), typeof(UnitOfWork));
     services.AddScoped(typeof(Ireposatory <>), typeof(GenaricReposatoery <>));
     services.AddCors(Options => {
         Options.AddPolicy("allowany", x => x.AllowAnyHeader().AllowAnyMethod().WithOrigins("http://localhost:4200").AllowCredentials());
     });
 }
Beispiel #23
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
     services.AddDbContext <QKContext>(options => options.UseSqlServer(Configuration.GetConnectionString("Connection")));
     services.AddCors(Options =>
                      Options.AddPolicy("EnableCORS", builder =>
     {
         builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod().AllowCredentials().Build();
     }));
 }
Beispiel #24
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddCors(Options => {
         Options.AddPolicy("AnotherPolicy", Builder => {
             Builder.AllowAnyOrigin();
             Builder.AllowAnyHeader();
             Builder.AllowAnyMethod();
         });
     });
     services.AddControllers();
 }
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
     services.AddDbContext <DbContextSistema>(options =>
                                              options.UseSqlServer(Configuration.GetConnectionString("Conexion")));
     services.AddCors(Options => {
         Options.AddPolicy(
             "Todos",
             builder => builder.WithOrigins("*").WithHeaders("*").WithMethods("*"));
     });
 }
Beispiel #26
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddDbContext <TestContext>(opt =>
                                         opt.UseInMemoryDatabase("TodoList"));
     services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
     //跨域访问组件
     services.AddCors(Options =>
                      Options.AddPolicy("CorsSample", p =>
                                        p.WithOrigins("http://localhost:5000")
                                        .AllowAnyMethod().AllowAnyHeader()));
 }
Beispiel #27
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
     services.AddTransient <IDataProvider, DataProvider>();
     services.AddCors(Options =>
     {
         Options.AddPolicy("AllowAll", p =>
         {
             p.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod();
         });
     });
 }
Beispiel #28
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddDbContext <BookstoreContext>(options => options.UseNpgsql(Configuration.GetConnectionString("BookstoreConnection")));
     services.AddMvc();
     services.AddCors(Options =>
     {
         Options.AddPolicy("CorsPolicy",
                           builder => builder.AllowAnyOrigin()
                           .AllowAnyMethod()
                           .AllowAnyHeader());
     });
 }
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddControllers();
     services.AddDbContext <BooksDBContext>(options =>
     {
         options.UseSqlServer(Configuration.GetConnectionString("BooksDB"));
     });
     services.AddCors(Options => Options.AddPolicy("CorsPolicy", builder =>
     {
         builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader();
     }));
 }
Beispiel #30
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services) //Ioc Container
 {
     services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
     services.AddCors(Options => Options.AddPolicy("CorsPolicy", builder =>
     {
         builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader();
     }));
     services.AddDbContext <BooksDBContext>(options =>
     {
         options.UseSqlServer(Configuration.GetConnectionString("BooksDB"));
     });
 }