public JwtController(IOptions <JwtIssuerOptions> jwtOptions, ListaCompraConext _context) { _jwtOptions = jwtOptions.Value; ThrowIfInvalidOptions(_jwtOptions); _serializerSettings = new JsonSerializerSettings { Formatting = Formatting.Indented }; Context = _context; }
public TiendaController(ListaCompraConext _context) { context = _context; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, ListaCompraConext context) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); app.UseCors(builder => builder.WithOrigins("*").AllowAnyHeader().AllowAnyMethod()); app.UseAuthentication(); app.UseMvc(); DbInitializer.Initialize(context); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, ListaCompraConext context) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); app.UseCors(builder => builder.WithOrigins("*").AllowAnyHeader().AllowAnyMethod()); var jwtAppSettingOptions = Configuration.GetSection(nameof(JwtIssuerOptions)); var tokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidIssuer = jwtAppSettingOptions[nameof(JwtIssuerOptions.Issuer)], ValidateAudience = true, ValidAudience = jwtAppSettingOptions[nameof(JwtIssuerOptions.Audience)], ValidateIssuerSigningKey = true, IssuerSigningKey = _signingKey, RequireExpirationTime = true, ValidateLifetime = true, ClockSkew = TimeSpan.Zero }; app.UseJwtBearerAuthentication(new JwtBearerOptions { AutomaticAuthenticate = true, AutomaticChallenge = true, TokenValidationParameters = tokenValidationParameters }); app.UseMvc(); DbInitializer.Initialize(context); }