Esempio n. 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            IdentityBuilder builder = services.AddIdentityCore <User>(opt =>
            {
                opt.Password.RequireDigit           = false;
                opt.Password.RequireLowercase       = false;
                opt.Password.RequireNonAlphanumeric = false;
                opt.Password.RequireUppercase       = false;
                opt.Password.RequiredLength         = 4;

                opt.User.RequireUniqueEmail = true;
            });

            builder = new IdentityBuilder(builder.UserType, typeof(IdentityRole), builder.Services);
            builder.AddEntityFrameworkStores <ApplicationDbContext>();
            builder.AddSignInManager <SignInManager <User> >();
            builder.AddRoleManager <RoleManager <IdentityRole> >();
            builder.AddDefaultTokenProviders();

            services.AddAuthorization(options =>
                                      options.AddPolicy("EmployerPolicy",
                                                        policy => policy.RequireRole("Employer")));

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(Encoding.ASCII
                                                                        .GetBytes(Configuration.GetSection("AppSettings:Key").Value)),
                    ValidateIssuer   = false,
                    ValidateAudience = false
                };
            });


            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlite(Configuration.GetConnectionString("Default")));

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
            services.AddSingleton <IEmail, MailJet>();
            services.AddSingleton <IStorageConnectionFactory, StorageConnectionFactory>(sp =>
            {
                CloudStorageOptionsDTO cloudStorageOptionsDTO = new CloudStorageOptionsDTO();
                cloudStorageOptionsDTO.ConnectionString       = Configuration["AzureBlobStorage:ConnectionString"];
                cloudStorageOptionsDTO.ProfilePicsContainer   = Configuration["AzureBlobStorage:BlobContainer"];
                return(new StorageConnectionFactory(cloudStorageOptionsDTO));
            });
            services.AddSingleton <ICloudStorage, AzureStorage>();
            services.Configure <EmailOptionsDTO>(Configuration.GetSection("MailJet"));

            services.AddAutoMapper(typeof(MapperProfiles));
        }
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddSwaggerGen(
         x => {
         x.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo()
         {
             Title = "IdentityService", Version = "v1"
         });
         x.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
         {
             Description = "JWT Authorization header using the bearer scheme",
             Name        = "Authorization",
             In          = ParameterLocation.Header,
             Type        = SecuritySchemeType.ApiKey
         });
         x.AddSecurityRequirement(new OpenApiSecurityRequirement
         {
             { new OpenApiSecurityScheme {
                   Reference = new OpenApiReference
                   {
                       Id   = "Bearer",
                       Type = ReferenceType.SecurityScheme
                   }
               }, new List <string>() }
         });
     });
     services.AddSingleton <IStorageConnectionFactory, StorageConnectionFactory>(sp =>
     {
         CloudStorageOptionsDTO cloudStorageOptionsDTO = new CloudStorageOptionsDTO();
         cloudStorageOptionsDTO.ConnectionString       = Configuration["AzureBlobStorage:ConnectionString"];
         cloudStorageOptionsDTO.DocumentsContainer     = Configuration["AzureBlobStorage:BlobContainer"];
         return(new StorageConnectionFactory(cloudStorageOptionsDTO));
     });
     services.AddControllers();
     services.AddCors(c =>
     {
         c.AddPolicy("AllowOrigin", options => options.WithOrigins("http://localhost:4200").AllowAnyHeader());
     });
     services.AddScoped <DocumentAPI.Services.IDocumentUpload, CloudUploadService>();
 }
Esempio n. 3
0
 public StorageConnectionFactory(CloudStorageOptionsDTO storageOptions)
 {
     _storageOptions = storageOptions;
 }