// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var tokenProvider = new RsaJwtTokenProvider("issuer", "audience", "mykeyname"); services.AddSingleton <ITokenProvider>(tokenProvider); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.RequireHttpsMetadata = false; options.TokenValidationParameters = tokenProvider.GetValidationParameters(); }); // This is for the [Authorize] attributes. services.AddAuthorization(auth => { auth.DefaultPolicy = new AuthorizationPolicyBuilder() .AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme) .RequireAuthenticatedUser() .Build(); }); services.AddMvc(); services.AddTransient <IContactRepository, ContactRepository>(); services.AddTransient <IUserRepository, UserRepository>(); services.AddTransient <IDeviceRepository, DeviceRepository>(); services.AddTransient <ILockerRepository, LockerRepository>(); }
public void ConfigureServices(IServiceCollection services) { services.AddCors(options => { options.AddPolicy("AllowAllOrigins", builder => { builder .AllowAnyOrigin() .AllowAnyHeader() .AllowAnyMethod(); }); }); //Invoke DI GoIdentity.DIContainer.ServiceLocator.Instance.LoadContainer(services); // Add framework services. services.AddMvc().AddJsonOptions(options => { options.SerializerSettings.ContractResolver = new DefaultContractResolver(); }); var tokenProvider = new RsaJwtTokenProvider("GoIdentityIssuer", "GoIdentityAudience", "GoIdentity7star&steps"); services.AddSingleton <ITokenProvider>(tokenProvider); #if DEBUG Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Active.DisableTelemetry = true; #endif services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.RequireHttpsMetadata = false; options.TokenValidationParameters = tokenProvider.GetValidationParameters(); }); // This is for the [Authorize] attributes. services.AddAuthorization(auth => { auth.DefaultPolicy = new AuthorizationPolicyBuilder() .AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme) .RequireAuthenticatedUser() .Build(); }); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "API", Version = "v1" }); c.OperationFilter <HeaderOperationFilter>(); }); services.AddSingleton(new HandlerContainer()); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllersWithViews(); services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options => { options.LoginPath = "/login"; options.AccessDeniedPath = "/login"; options.Validate(); }); var tokenProvider = new RsaJwtTokenProvider("issuer", "audience", "keyName"); services.AddSingleton <ITokenProvider>(tokenProvider); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options => { options.RequireHttpsMetadata = false; options.TokenValidationParameters = tokenProvider.GetValidationParameters(); }); services.AddAuthorization(auth => { auth.AddPolicy("Cookies", new AuthorizationPolicyBuilder() .AddAuthenticationSchemes(CookieAuthenticationDefaults.AuthenticationScheme) .RequireAuthenticatedUser() .Build()); auth.AddPolicy("Bearer", new AuthorizationPolicyBuilder() .AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme) .RequireAuthenticatedUser() .Build()); auth.AddPolicy("ApplicationPolicy", policy => policy.Requirements.Add(new ApplicationAuthorRequirement())); auth.DefaultPolicy = auth.GetPolicy("Cookies"); }); services.AddSingleton <IAuthorizationHandler, ApplicationAuthorizationHandler>(); services.AddSingleton(ConfigureMapper()); services.AddTransient <ISqlDataAccess, SqlDataAccess>(); services.AddTransient <IUserTable, UserTable>(); services.AddTransient <IRoleTable, RoleTable>(); services.AddTransient <IApplicationTable, ApplicationTable>(); services.AddTransient <IUserRoleTable, UserRoleTable>(); services.AddTransient <IConnectionTable, ConnectionTable>(); services.AddTransient <IUserProcessor, UserProcessor>(); services.AddTransient <IRoleProcessor, RoleProcessor>(); services.AddTransient <IApplicationProcessor, ApplicationProcessor>(); services.AddTransient <IConnectionProcessor, ConnectionProcessor>(); }
public void ConfigureServices(IServiceCollection services) { services.AddCors(); //Invoke DI services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); ServiceLocator.Instance.LoadContainer(services); // Add framework services. services.AddMvc(options => { options.EnableEndpointRouting = false; }).AddNewtonsoftJson(options => { options.SerializerSettings.ContractResolver = new DefaultContractResolver(); }); var tokenProvider = new RsaJwtTokenProvider(); services.AddSingleton <ITokenProvider>(tokenProvider); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(cfg => { cfg.RequireHttpsMetadata = false; cfg.SaveToken = true; cfg.TokenValidationParameters = new TokenValidationParameters { ValidIssuer = ConfigSettings.Instance.JwtKeysSettings.ValidIssuer, ValidAudience = ConfigSettings.Instance.JwtKeysSettings.ValidAudience, IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(ConfigSettings.Instance.JwtKeysSettings.IssuerSigningKey)) //Secret }; }); // This is for the [Authorize] attributes. services.AddAuthorization(auth => { auth.DefaultPolicy = new AuthorizationPolicyBuilder() .AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme) .RequireAuthenticatedUser() .Build(); }); services.AddApplicationInsightsTelemetry(); services.AddControllers(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "IQSoft.eCommerce API", Version = "v1" }); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddSingleton <IUnitOfWork>(option => new NorthwindUnitOfWork(Configuration.GetConnectionString("Northwind"))); var tokenProvider = new RsaJwtTokenProvider("Cibertec", "AppCustomers", "token_cibertect_2017");// Nombre de la empresa o desarrollador de la web, nombre de la aplicacion, token no debería estar en duro. services.AddSingleton <ITokenProvider>(tokenProvider); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options => { options.RequireHttpsMetadata = false; options.TokenValidationParameters = tokenProvider.GetValidationParameters(); }); services.AddAuthorization(auth => { auth.DefaultPolicy = new AuthorizationPolicyBuilder().AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme).RequireAuthenticatedUser().Build(); }); services.AddCors(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddSingleton <IUnitOfWork> ( option => new NorthwindUniOftWork ( Configuration.GetConnectionString("Northwind") ) ); services.AddMvc().AddFluentValidation(); services.AddTransient <IValidator <Customer>, CustomerValidator>(); services.AddResponseCompression(); services.Configure <GzipCompressionProviderOptions>(options => options.Level = CompressionLevel.Optimal); //authentication var tokenProvider = new RsaJwtTokenProvider("issuer", "audience", "token_cibertec_2017"); services.AddSingleton <ITokenProvider>(tokenProvider); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.RequireHttpsMetadata = false; options.TokenValidationParameters = tokenProvider.GetValidationParameters(); }); services.AddAuthorization(auth => { auth.DefaultPolicy = new AuthorizationPolicyBuilder() .AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme) .RequireAuthenticatedUser() .Build(); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var tokenProvider = new RsaJwtTokenProvider("issuer", "audience", "mykeyname"); services.AddSingleton <ITokenProvider>(tokenProvider); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.RequireHttpsMetadata = false; options.TokenValidationParameters = tokenProvider.GetValidationParameters(); }); // This is for the [Authorize] attributes. services.AddAuthorization(auth => { auth.DefaultPolicy = new AuthorizationPolicyBuilder() .AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme) .RequireAuthenticatedUser() .Build(); }); services.AddCors(options => { options.AddPolicy("AllowAllOrigins", builder => { builder .AllowAnyOrigin() .AllowAnyHeader() .AllowAnyMethod(); }); }); // Add framework services. services.AddSingleton <IThingsRepository, ThingsRepository>(); services.AddMvc(); }