Exemplo n.º 1
0
 public static void ConfigureDbMySql(this IServiceCollection services, AppSettingsModel config)
 {
     services.AddDbContext <ApiContext>(options => options
                                        ///.UseLazyLoadingProxies()
                                        .UseMySql(config.DbConnectionString));
     services.AddScoped <IUnitOfWork, UnitOfWork>();
 }
Exemplo n.º 2
0
 public static void ConfigureCors(this IServiceCollection services, AppSettingsModel config)
 {
     services.AddCors(options =>
     {
         options.AddPolicy("CorsPolicy",
                           builder => builder
                                             //.WithOrigins(config.CrossUrls)
                           .AllowAnyOrigin() // TODO: change this before deployment!
                           .AllowAnyMethod()
                           .AllowAnyHeader()
                           .AllowCredentials());
     });
 }
Exemplo n.º 3
0
        public static void ConfigureAuthentication(this IServiceCollection services, AppSettingsModel config)
        {
            services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultSignInScheme       = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultScheme             = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(opt =>
            {
                opt.TokenValidationParameters = new TokenValidationParameters
                {
                    RequireSignedTokens      = true,
                    ValidateIssuer           = false,
                    ValidateAudience         = false,
                    ValidateLifetime         = true,
                    ValidateIssuerSigningKey = true,

                    ValidIssuer      = config.Token.Issuer,
                    ValidAudience    = config.Token.Audience,
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(config.Token.SecretKey))
                };
            });
        }