예제 #1
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 http://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            // Add Entity Framework services to the services container.
            services.AddEntityFramework()
            .AddSqlServer()
            .AddDbContext <PhotoGalleryContext>(options =>
                                                options.UseSqlServer(Configuration["Data:PhotoGalleryConnection:ConnectionString"]));

            // Repositories
            services.AddScoped <IPhotoRepository, PhotoRepository>();
            services.AddScoped <IAlbumRepository, AlbumRepository>();
            services.AddScoped <IUserRepository, UserRepository>();
            services.AddScoped <IUserRoleRepository, UserRoleRepository>();
            services.AddScoped <IRoleRepository, RoleRepository>();
            services.AddScoped <ILoggingRepository, LoggingRepository>();

            // Services
            services.AddScoped <IMembershipService, MembershipService>();
            services.AddScoped <IEncryptionService, EncryptionService>();

            services.AddAuthentication();

            // Polices
            services.AddAuthorization(options =>
            {
                // inline policies
                options.AddPolicy("AdminOnly", policy =>
                {
                    policy.RequireClaim(ClaimTypes.Role, "Admin");
                });
            });

            // Add MVC services to the services container.
            services.AddMvc();
        }
예제 #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection services)
        {
            services.AddAuthentication("Bearer")
            .DSAddJwtBearer(options =>
            {
                options.AudienceAuthorityResolver = new CognitoUserPoolResolver(new DataContext());
            });

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

            services.AddScoped <IIAASService, AWSCognitoService>();
            services.AddScoped <DataContext>();
        }
예제 #3
0
        // This method gets called by the runtime. Use this method to add services to the container
        public void ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection services)
        {
            services.AddAuthentication();

            services.AddSignalR();
            // Add framework services.
            //services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));
            // Add MVC services to the services container.
            services.AddMvc()
            .AddJsonOptions(opts =>
            {
                opts.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            });
        }
예제 #4
0
 private void ConfigureServicesJWT(Microsoft.Extensions.DependencyInjection.IServiceCollection services)
 {
     services.AddAuthentication(options =>
     {
         options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
         options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
     })
     .AddJwtBearer(options =>
     {
         options.TokenValidationParameters = new TokenValidationParameters
         {
             ValidateIssuer           = true,
             ValidateAudience         = true,
             ValidateLifetime         = true,
             ValidateIssuerSigningKey = true,
             ValidIssuer      = Configuration["Jwt:Issuer"],
             ValidAudience    = Configuration["Jwt:Audience"],
             IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:Key"])),
         };
     });
 }
예제 #5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection services)
        {
            services.Configure <FormOptions>(o => {
                o.ValueLengthLimit         = int.MaxValue;
                o.MultipartBodyLengthLimit = int.MaxValue;
                o.MemoryBufferThreshold    = int.MaxValue;
            });


            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(
                                                             Configuration.GetConnectionString("MSSQL")));

            services.AddIdentity <ApplicationUser, IdentityRole>(cfg =>
            {
                cfg.User.RequireUniqueEmail = true;
            })
            .AddEntityFrameworkStores <ApplicationDbContext>();



            services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddCookie()
            .AddJwtBearer(cfg =>
            {
                cfg.TokenValidationParameters = new TokenValidationParameters()
                {
                    ValidIssuer      = this.Configuration["Tokens:Issuer"],
                    ValidAudience    = this.Configuration["Tokens:Audience"],
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(this.Configuration["Tokens:Key"]))
                };
            });


            services.Configure <IdentityOptions>(options =>
            {
                options.Password.RequiredLength         = 3;
                options.Password.RequireDigit           = false;
                options.Password.RequireLowercase       = false;
                options.Password.RequireUppercase       = false;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequiredUniqueChars    = 0;
            });

            services.AddCors(options =>
            {
                options.AddPolicy("CorsPolicy", builder => builder.WithOrigins("http://www.taximiapi.com.aspbg.net/", "http://localhost:8100/")
                                  .AllowAnyHeader()
                                  .AllowAnyMethod()
                                  .AllowCredentials()
                                  .SetIsOriginAllowed((host) => true));
            });

            services.AddMvc();

            services.AddSignalR();

            services.AddControllers()
            .AddNewtonsoftJson(options =>
                               options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);

            services.RegisterRepositoryServices();

            services.RegisterCloudinary(Configuration);

            services.Configure <MailSettings>(Configuration.GetSection("MailSettings"));

            services.RegisterCustomServices();
        }
예제 #6
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection services)
        {
            var cadena = Configuration.GetConnectionString("DefaultConnection");

            services.AddDbContext <GeneralContext>(opt => opt.UseSqlServer(cadena, b => b.MigrationsAssembly("Verduras")));

            services.AddControllersWithViews();

            #region configure strongly typed settings objects
            var appSettingsSection = Configuration.GetSection("AppSetting");
            services.Configure <AppSetting>(appSettingsSection);
            #endregion

            #region Configure jwt authentication inteprete el token
            var appSettings = appSettingsSection.Get <AppSetting>();
            var key         = Encoding.ASCII.GetBytes(appSettings.Secret);
            services.AddAuthentication(x =>
            {
                x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(x =>
            {
                x.RequireHttpsMetadata      = false;
                x.SaveToken                 = true;
                x.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(key),
                    ValidateIssuer           = false,
                    ValidateAudience         = false
                };
            }
                          );
            #endregion

            //Agregar OpenApi Swagger
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo
                {
                    Version        = "v1",
                    Title          = "School API",
                    Description    = "School API - ASP.NET Core Web API",
                    TermsOfService = new Uri("https://cla.dotnetfoundation.org/"),
                    Contact        = new OpenApiContact
                    {
                        Name  = "Unicesar",
                        Email = string.Empty,
                        Url   = new Uri("https://github.com/borisgr04/CrudNgDotNetCore3"),
                    },
                    License = new OpenApiLicense
                    {
                        Name = "Licencia dotnet foundation",
                        Url  = new Uri("https://www.byasystems.co/license"),
                    }
                });
            });

            // In production, the Angular files will be served from this directory
            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/dist";
            });
        }